Skip to content

Commit

Permalink
Consider platform support
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Jan 19, 2025
1 parent 1c4be3f commit ca942f3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Sources/SpeziViews/Views/Controls/OptionSetPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ public enum OptionSetPickerStyle {
/// The picker is rendered inline (e.g., in a List view).
case inline
/// The picker is rendered as a menu.
@available(watchOS, unavailable)
case menu

/// The default style for the platform.
public static var automatic: OptionSetPickerStyle {
#if os(watchOS)
.inline
#else
.menu
#endif
}
}


Expand Down Expand Up @@ -98,6 +108,7 @@ public struct OptionSetPicker<Label: View, Value: OptionSet & PickerValue>: View
} else {
view
}
#if !os(watchOS)
case .menu:
Menu {
ForEach(Value.allCases, id: \.self) { value in
Expand Down Expand Up @@ -136,7 +147,10 @@ public struct OptionSetPicker<Label: View, Value: OptionSet & PickerValue>: View
}
}
}
#if !os(macOS)
.menuActionDismissBehavior(.disabled) // disable for multi selection
#endif
#endif
}
}

Expand All @@ -147,7 +161,7 @@ public struct OptionSetPicker<Label: View, Value: OptionSet & PickerValue>: View
/// - style: The style how the picker is displayed.
/// - allowEmptySelection: Flag indicating if an empty selection is allowed.
/// - label: The label view.
public init(selection: Binding<Value>, style: OptionSetPickerStyle = .menu, allowEmptySelection: Bool = false, @ViewBuilder label: () -> Label) {
public init(selection: Binding<Value>, style: OptionSetPickerStyle = .automatic, allowEmptySelection: Bool = false, @ViewBuilder label: () -> Label) {

Check failure on line 164 in Sources/SpeziViews/Views/Controls/OptionSetPicker.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Line Length Violation: Line should be 150 characters or less; currently it has 154 characters (line_length)
self.style = style
self.allowEmptySelection = allowEmptySelection
self.label = label()
Expand All @@ -163,7 +177,7 @@ public struct OptionSetPicker<Label: View, Value: OptionSet & PickerValue>: View
public init(
_ titleKey: LocalizedStringResource,
selection: Binding<Value>,
style: OptionSetPickerStyle = .menu,
style: OptionSetPickerStyle = .automatic,
allowEmptySelection: Bool = false
) where Label == Text {
self.init(selection: selection, style: style, allowEmptySelection: allowEmptySelection) {
Expand Down

0 comments on commit ca942f3

Please sign in to comment.