1
0

Picker.swift 939 B

123456789101112131415161718192021222324252627282930
  1. /// A control for selecting from a set of values.
  2. public struct Picker<Value: Equatable>: View {
  3. /// The options to be offered by the picker.
  4. private var options: [Value]
  5. /// A binding to the picker's selected option.
  6. private var value: Binding<Value?>
  7. @Environment(\.self) var environment
  8. /// Creates a new picker with the given options and a binding for the
  9. /// selected value.
  10. ///
  11. /// - Parameters:
  12. /// - options: The options to be offered by the picker.
  13. /// - value: A binding to the picker's selected option.
  14. public init(of options: [Value], selection value: Binding<Value?>) {
  15. self.options = options
  16. self.value = value
  17. }
  18. public var body: some View {
  19. AnyView(
  20. environment.pickerStyle.makeView(
  21. options: options,
  22. selection: value,
  23. environment: environment
  24. )
  25. )
  26. }
  27. }