From c0301ce7e71b098e5243530fe5baabaa693f8a81 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 8 Nov 2023 16:52:46 -0500 Subject: [PATCH] visionOS: Further Compose screen tweaks --- .../Controllers/AttachmentRowController.swift | 12 ++++++++++-- .../ComposeUI/Controllers/ComposeController.swift | 10 +++++----- .../ComposeUI/Controllers/ToolbarController.swift | 1 - .../Views/AttachmentDescriptionTextView.swift | 14 +++++++++++++- .../Sources/ComposeUI/Views/EmojiTextField.swift | 2 ++ .../Sources/ComposeUI/Views/MainTextView.swift | 12 ++++++++++-- 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentRowController.swift b/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentRowController.swift index 16273c85..ff11ef04 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentRowController.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentRowController.swift @@ -136,7 +136,7 @@ class AttachmentRowController: ViewController { .overlay { thumbnailFocusedOverlay } - .frame(width: 80, height: 80) + .frame(width: thumbnailSize, height: thumbnailSize) .onTapGesture { textEditorFocused = false // if we just focus the attachment immediately, the text editor doesn't actually unfocus @@ -162,7 +162,7 @@ class AttachmentRowController: ViewController { switch controller.descriptionMode { case .allowEntry: - InlineAttachmentDescriptionView(attachment: attachment, minHeight: 80) + InlineAttachmentDescriptionView(attachment: attachment, minHeight: thumbnailSize) .matchedGeometrySource(id: AttachmentDescriptionTextViewID(attachment), presentationID: attachment.id) .focused($textEditorFocused) @@ -192,6 +192,14 @@ class AttachmentRowController: ViewController { #endif } + private var thumbnailSize: CGFloat { + #if os(visionOS) + 120 + #else + 80 + #endif + } + @ViewBuilder private var thumbnailFocusedOverlay: some View { Image(systemName: "arrow.up.backward.and.arrow.down.forward") diff --git a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift index fdf4104d..bb31f3c9 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift @@ -334,6 +334,11 @@ public final class ComposeController: ViewController { .toolbar { ToolbarItem(placement: .cancellationAction) { cancelButton } ToolbarItem(placement: .confirmationAction) { postButton } + #if os(visionOS) + ToolbarItem(placement: .bottomOrnament) { + ControllerView(controller: { controller.toolbarController }) + } + #endif } .background(GeometryReader { proxy in Color.clear @@ -342,11 +347,6 @@ public final class ComposeController: ViewController { globalFrameOutsideList = newValue } }) - #if os(visionOS) - .ornament(attachmentAnchor: .scene(.bottom)) { - ControllerView(controller: { controller.toolbarController }) - } - #endif .sheet(isPresented: $controller.isShowingDraftsList) { ControllerView(controller: { DraftsController(parent: controller, isPresented: $controller.isShowingDraftsList) }) } diff --git a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift index 5861c987..a81227eb 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift @@ -53,7 +53,6 @@ class ToolbarController: ViewController { var body: some View { #if os(visionOS) buttons - .glassBackgroundEffect(in: .rect(cornerRadius: 50)) #else ScrollView(.horizontal, showsIndicators: false) { buttons diff --git a/Packages/ComposeUI/Sources/ComposeUI/Views/AttachmentDescriptionTextView.swift b/Packages/ComposeUI/Sources/ComposeUI/Views/AttachmentDescriptionTextView.swift index 5f1bbf09..44313e19 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Views/AttachmentDescriptionTextView.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Views/AttachmentDescriptionTextView.swift @@ -22,13 +22,21 @@ struct InlineAttachmentDescriptionView: View { self.minHeight = minHeight } + private var placeholderOffset: CGSize { + #if os(visionOS) + CGSize(width: 8, height: 8) + #else + CGSize(width: 4, height: 8) + #endif + } + var body: some View { ZStack(alignment: .topLeading) { if attachment.attachmentDescription.isEmpty { placeholder .font(.body) .foregroundColor(.secondary) - .offset(x: 4, y: 8) + .offset(placeholderOffset) } WrappedTextView( @@ -84,6 +92,10 @@ private struct WrappedTextView: UIViewRepresentable { view.font = .preferredFont(forTextStyle: .body) view.adjustsFontForContentSizeCategory = true view.textContainer.lineBreakMode = .byWordWrapping + #if os(visionOS) + view.borderStyle = .roundedRect + view.textContainerInset = UIEdgeInsets(top: 8, left: 4, bottom: 8, right: 4) + #endif return view } diff --git a/Packages/ComposeUI/Sources/ComposeUI/Views/EmojiTextField.swift b/Packages/ComposeUI/Sources/ComposeUI/Views/EmojiTextField.swift index dd02ef8c..cbb9906c 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Views/EmojiTextField.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Views/EmojiTextField.swift @@ -57,7 +57,9 @@ struct EmojiTextField: UIViewRepresentable { context.coordinator.maxLength = maxLength context.coordinator.focusNextView = focusNextView + #if !os(visionOS) uiView.backgroundColor = colorScheme == .dark ? UIColor(controller.config.fillColor) : .secondarySystemBackground + #endif if becomeFirstResponder?.wrappedValue == true { DispatchQueue.main.async { diff --git a/Packages/ComposeUI/Sources/ComposeUI/Views/MainTextView.swift b/Packages/ComposeUI/Sources/ComposeUI/Views/MainTextView.swift index 2070e2df..23fe44e3 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Views/MainTextView.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Views/MainTextView.swift @@ -31,11 +31,19 @@ struct MainTextView: View { #endif } + private var textViewBackgroundColor: UIColor? { + #if os(visionOS) + nil + #else + colorScheme == .dark ? UIColor(config.fillColor) : .secondarySystemBackground + #endif + } + var body: some View { ZStack(alignment: .topLeading) { MainWrappedTextViewRepresentable( text: $draft.text, - backgroundColor: colorScheme == .dark ? UIColor(config.fillColor) : .secondarySystemBackground, + backgroundColor: textViewBackgroundColor, becomeFirstResponder: $controller.mainComposeTextViewBecomeFirstResponder, updateSelection: $updateSelection, textDidChange: textDidChange @@ -76,7 +84,7 @@ fileprivate struct MainWrappedTextViewRepresentable: UIViewRepresentable { typealias UIViewType = UITextView @Binding var text: String - let backgroundColor: UIColor + let backgroundColor: UIColor? @Binding var becomeFirstResponder: Bool @Binding var updateSelection: ((UITextView) -> Void)? let textDidChange: (UITextView) -> Void