diff --git a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift index 369d89bd..dcdafe5e 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift @@ -315,7 +315,9 @@ public final class ComposeController: ViewController { .transition(.move(edge: .bottom)) .animation(.default, value: controller.currentInput?.autocompleteState) + #if !os(visionOS) ControllerView(controller: { controller.toolbarController }) + #endif } #if !os(visionOS) // on iPadOS15, the toolbar ends up below the keyboard's toolbar without this @@ -335,6 +337,11 @@ 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 7ebe6622..5861c987 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift @@ -45,55 +45,27 @@ class ToolbarController: ViewController { @EnvironmentObject private var composeController: ComposeController @ScaledMetric(relativeTo: .body) private var imageSize: CGFloat = 22 + #if !os(visionOS) @State private var minWidth: CGFloat? @State private var realWidth: CGFloat? + #endif var body: some View { + #if os(visionOS) + buttons + .glassBackgroundEffect(in: .rect(cornerRadius: 50)) + #else ScrollView(.horizontal, showsIndicators: false) { - HStack(spacing: 0) { - cwButton - - MenuPicker(selection: visibilityBinding, options: visibilityOptions, buttonStyle: .iconOnly) - // the button has a bunch of extra space by default, but combined with what we add it's too much - .padding(.horizontal, -8) - .disabled(draft.editedStatusID != nil) - .disabled(composeController.mastodonController.instanceFeatures.localOnlyPostsVisibility && draft.localOnly) - - if composeController.mastodonController.instanceFeatures.localOnlyPosts { - localOnlyPicker - .padding(.horizontal, -8) - .disabled(draft.editedStatusID != nil) - } - - if let currentInput = composeController.currentInput, - currentInput.toolbarElements.contains(.emojiPicker) { - customEmojiButton - } - - if let currentInput = composeController.currentInput, - currentInput.toolbarElements.contains(.formattingButtons), - composeController.config.contentType != .plain { - - Spacer() - formatButtons - } - - Spacer() - - if #available(iOS 16.0, *), - composeController.mastodonController.instanceFeatures.createStatusWithLanguage { - LanguagePicker(draftLanguage: $draft.language, hasChangedSelection: $composeController.hasChangedLanguageSelection) - } - } - .padding(.horizontal, 16) - .frame(minWidth: minWidth) - .background(GeometryReader { proxy in - Color.clear - .preference(key: ToolbarWidthPrefKey.self, value: proxy.size.width) - .onPreferenceChange(ToolbarWidthPrefKey.self) { width in - realWidth = width - } - }) + buttons + .padding(.horizontal, 16) + .frame(minWidth: minWidth) + .background(GeometryReader { proxy in + Color.clear + .preference(key: ToolbarWidthPrefKey.self, value: proxy.size.width) + .onPreferenceChange(ToolbarWidthPrefKey.self) { width in + realWidth = width + } + }) } .scrollDisabledIfAvailable(realWidth ?? 0 <= minWidth ?? 0) .frame(height: ToolbarController.height) @@ -110,6 +82,51 @@ class ToolbarController: ViewController { minWidth = width } }) + #endif + } + + @ViewBuilder + private var buttons: some View { + HStack(spacing: 0) { + cwButton + + MenuPicker(selection: visibilityBinding, options: visibilityOptions, buttonStyle: .iconOnly) + #if !os(visionOS) + // the button has a bunch of extra space by default, but combined with what we add it's too much + .padding(.horizontal, -8) + #endif + .disabled(draft.editedStatusID != nil) + .disabled(composeController.mastodonController.instanceFeatures.localOnlyPostsVisibility && draft.localOnly) + + if composeController.mastodonController.instanceFeatures.localOnlyPosts { + localOnlyPicker + #if !os(visionOS) + .padding(.horizontal, -8) + #endif + .disabled(draft.editedStatusID != nil) + } + + if let currentInput = composeController.currentInput, + currentInput.toolbarElements.contains(.emojiPicker) { + customEmojiButton + } + + if let currentInput = composeController.currentInput, + currentInput.toolbarElements.contains(.formattingButtons), + composeController.config.contentType != .plain { + + Spacer() + formatButtons + } + + Spacer() + + if #available(iOS 16.0, *), + composeController.mastodonController.instanceFeatures.createStatusWithLanguage { + LanguagePicker(draftLanguage: $draft.language, hasChangedSelection: $composeController.hasChangedLanguageSelection) + } + } + .buttonStyle(.borderless) } private var cwButton: some View {