PickerStyle.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /// A type that specifies the appearance and interaction of all pickers within a view hierarchy.
  2. @MainActor
  3. public protocol PickerStyle: Sendable {
  4. associatedtype Body: View
  5. /// The method used to render ``Picker``.
  6. /// - Parameters:
  7. /// - options: The options that the picker should display.
  8. /// - selection: A binding to the picker's currently selected value. May
  9. /// hold nil if no value has been chosen.
  10. /// - environment: The environment the picker is being rendered in.
  11. func makeView<Value: Equatable>(
  12. options: [Value],
  13. selection: Binding<Value?>,
  14. environment: EnvironmentValues
  15. ) -> Body
  16. /// A method that can be used to check whether a picker style is currently
  17. /// supported by a specific backend.
  18. ///
  19. /// To determine whether a picker style is supported, use the environment
  20. /// action ``EnvironmentValues/isPickerStyleSupported`` instead. This method
  21. /// is used to implement that check.
  22. ///
  23. /// The default implementation always returns `true`.
  24. /// - Parameter backend: The backend being queried for support.
  25. func isSupported<Backend: BaseAppBackend>(backend: Backend) -> Bool
  26. }
  27. extension PickerStyle {
  28. public func isSupported<Backend: BaseAppBackend>(backend: Backend) -> Bool {
  29. // Custom picker styles are supported on all platforms by default.
  30. true
  31. }
  32. }