diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-05-08 20:53:10 -0700 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-05-08 20:53:10 -0700 |
| commit | 75b40db9adac93dde9df3ff76bb172c76e3d3a55 (patch) | |
| tree | 1e9088849d7a32ac0f42c933e2b6ab50350ed196 /Hotline/macOS/ServerAgreementView.swift | |
| parent | 01d32910bc1e75533c2f473011296fee6febbadb (diff) | |
Fix about box layout on open. Remove about box from window menu, add expand button to server agreement, add email address highlighting, style server messages, unread badge on admins are red now, play server message sound, some code cleanup.
Diffstat (limited to 'Hotline/macOS/ServerAgreementView.swift')
| -rw-r--r-- | Hotline/macOS/ServerAgreementView.swift | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/Hotline/macOS/ServerAgreementView.swift b/Hotline/macOS/ServerAgreementView.swift new file mode 100644 index 0000000..a1f96d9 --- /dev/null +++ b/Hotline/macOS/ServerAgreementView.swift @@ -0,0 +1,81 @@ +import SwiftUI + +fileprivate let MAX_AGREEMENT_HEIGHT: CGFloat = 280 + +struct ServerAgreementView: View { + let text: String + + @State private var expandable: Bool = false + @State private var expanded: Bool = false + + var body: some View { + ScrollView(.vertical) { + HStack(alignment: .top) { + Spacer() + Text(text.convertToAttributedStringWithLinks()) + .font(.system(size: 12)) + .fontDesign(.monospaced) + .textSelection(.enabled) + .tint(Color("Link Color")) + .frame(maxWidth: 400) + .padding(16) + .background( + GeometryReader { geometry in + Color.clear.onAppear { + if geometry.size.height > MAX_AGREEMENT_HEIGHT { + expandable = true + } + else { + expandable = false + } + } + } + ) + Spacer() + } + } + .scrollIndicators(.never) + .frame(maxWidth: .infinity, maxHeight: (expandable && expanded) ? nil : MAX_AGREEMENT_HEIGHT) + .scrollBounceBehavior(.basedOnSize) +#if os(iOS) + .background(Color("Agreement Background")) +#elseif os(macOS) + .background(VisualEffectView(material: .titlebar, blendingMode: .withinWindow)) +#endif + .overlay( + ZStack(alignment: .bottomTrailing) { + Group { + if !expandable || expanded { + EmptyView() + } + else { + Button(action: { + withAnimation(.easeOut(duration: 0.15)) { + expanded = true + } + }, label: { + Color.black + .opacity(0.00001) + .frame(width: 32, height: 32) + .overlay( + Image(systemName: "arrow.up.left.and.arrow.down.right") + .resizable() + .scaledToFit() + .fontWeight(.semibold) + .frame(width: 12, height: 12) + .foregroundColor(.primary.opacity(0.8)) + , alignment: .center) + }) + .buttonStyle(.plain) + .help("Expand Server Agreement") + } + } + } + , alignment: .bottomTrailing) + .clipShape(RoundedRectangle(cornerRadius: 8)) + } +} + +#Preview { + ServerAgreementView(text: "Hello there and welcome to this server.") +} |