Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/SwiftCrossUI/Environment/EnvironmentValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public struct EnvironmentValues {
/// Whether the text should be selectable. Set by ``View/textSelectionEnabled(_:)``.
public var isTextSelectionEnabled: Bool

/// The menu ordering to use.
public var menuOrder: MenuOrder

/// Backing storage for extensible subscript
private var extraValues: [ObjectIdentifier: Any]

Expand Down Expand Up @@ -226,6 +229,7 @@ public struct EnvironmentValues {
isEnabled = true
scrollDismissesKeyboardMode = .automatic
isTextSelectionEnabled = false
menuOrder = .automatic
allowLayoutCaching = false
}

Expand Down
8 changes: 8 additions & 0 deletions Sources/SwiftCrossUI/Values/MenuOrder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public enum MenuOrder: Hashable, Sendable {
/// The automatic behavior.
case automatic
/// Sorts items so the first item is closest to where the user opened the menu from.
case priority
/// Sorts items in the order given.
case fixed
}
6 changes: 6 additions & 0 deletions Sources/SwiftCrossUI/Views/Modifiers/MenuModifiers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extension View {
/// Sets the menu sort order, for backends that support it.
public func menuOrder(_ order: MenuOrder) -> some View {
environment(\.menuOrder, order)
}
}
7 changes: 7 additions & 0 deletions Sources/UIKitBackend/UIKitBackend+Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
setButtonTitle(buttonWidget, label, environment: environment)
buttonWidget.child.menu = menu.uiMenu
buttonWidget.child.showsMenuAsPrimaryAction = true
if #available(iOS 16, tvOS 17, macCatalyst 16, *) {

Check warning on line 61 in Sources/UIKitBackend/UIKitBackend+Menu.swift

View workflow job for this annotation

GitHub Actions / uikit (TV)

unnecessary check for 'tvOS'; enclosing scope ensures guard will always be true
buttonWidget.child.preferredMenuElementOrder = switch environment.menuOrder {
case .automatic: .automatic
case .priority: .priority
case .fixed: .fixed
}
}
} else {
preconditionFailure("Current OS is too old to support menu buttons.")
}
Expand Down
Loading