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 {