Switches.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. extension BackendFeatures {
  2. /// Backend methods for toggle switches.
  3. ///
  4. /// These are used by ``Toggle`` when ``EnvironmentValues/toggleStyle`` is
  5. /// ``ToggleStyle/switch``.
  6. @MainActor
  7. public protocol Switches: Core {
  8. /// If `true`, a toggle in the ``ToggleStyle/switch`` style grows to fill
  9. /// its parent container.
  10. var requiresToggleSwitchSpacer: Bool { get }
  11. /// Creates a switch that is either on or off.
  12. ///
  13. /// - Returns: A switch.
  14. func createSwitch() -> Widget
  15. /// Sets the change handler of a switch.
  16. ///
  17. /// - Parameters:
  18. /// - switchWidget: The switch to update.
  19. /// - environment: The current environment.
  20. /// - onChange: The action to perform when the switch is toggled on or
  21. /// off. This replaces any existing change handlers.
  22. func updateSwitch(
  23. _ switchWidget: Widget,
  24. environment: EnvironmentValues,
  25. onChange: @escaping (Bool) -> Void
  26. )
  27. /// Sets the state of a switch.
  28. ///
  29. /// - Parameters:
  30. /// - switchWidget: The switch to set the state of.
  31. /// - state: The new state.
  32. func setState(ofSwitch switchWidget: Widget, to state: Bool)
  33. }
  34. }