From e8ef9345e95c1b2c432a16894f76998a4c954711 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 5 Dec 2023 22:00:48 -0500 Subject: [PATCH] Fix visibility/local-only buttons not appearing on Catalyst You need to pass the configuration to the initializer to get it to show up in the Mac idiom Fixes #452 --- .../Controllers/ToolbarController.swift | 8 ++++- .../Sources/TuskerComponents/MenuPicker.swift | 29 ++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift index 7ebe6622..c829b060 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift @@ -54,14 +54,20 @@ class ToolbarController: ViewController { 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 + #if !targetEnvironment(macCatalyst) + // 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 targetEnvironment(macCatalyst) + .padding(.leading, 4) + #else .padding(.horizontal, -8) + #endif .disabled(draft.editedStatusID != nil) } diff --git a/Packages/TuskerComponents/Sources/TuskerComponents/MenuPicker.swift b/Packages/TuskerComponents/Sources/TuskerComponents/MenuPicker.swift index 21c0c8e9..08f67c1e 100644 --- a/Packages/TuskerComponents/Sources/TuskerComponents/MenuPicker.swift +++ b/Packages/TuskerComponents/Sources/TuskerComponents/MenuPicker.swift @@ -26,13 +26,26 @@ public struct MenuPicker: UIViewRepresentable { } public func makeUIView(context: Context) -> UIButton { - let button = UIButton() + let button = UIButton(configuration: makeConfiguration()) button.showsMenuAsPrimaryAction = true button.setContentHuggingPriority(.required, for: .horizontal) return button } public func updateUIView(_ button: UIButton, context: Context) { + button.configuration = makeConfiguration() + button.menu = UIMenu(children: options.map { opt in + let action = UIAction(title: opt.title, subtitle: opt.subtitle, image: opt.image, state: opt.value == selection ? .on : .off) { _ in + selection = opt.value + } + action.accessibilityLabel = opt.accessibilityLabel + return action + }) + button.accessibilityLabel = selectedOption.accessibilityLabel ?? selectedOption.title + button.isPointerInteractionEnabled = buttonStyle == .iconOnly + } + + private func makeConfiguration() -> UIButton.Configuration { var config = UIButton.Configuration.borderless() if #available(iOS 16.0, *) { config.indicator = .popup @@ -43,16 +56,10 @@ public struct MenuPicker: UIViewRepresentable { if buttonStyle.hasLabel { config.title = selectedOption.title } - button.configuration = config - button.menu = UIMenu(children: options.map { opt in - let action = UIAction(title: opt.title, subtitle: opt.subtitle, image: opt.image, state: opt.value == selection ? .on : .off) { _ in - selection = opt.value - } - action.accessibilityLabel = opt.accessibilityLabel - return action - }) - button.accessibilityLabel = selectedOption.accessibilityLabel ?? selectedOption.title - button.isPointerInteractionEnabled = buttonStyle == .iconOnly + #if targetEnvironment(macCatalyst) + config.macIdiomStyle = .bordered + #endif + return config } public struct Option {