DynamicProperty.swift 822 B

123456789101112131415161718192021
  1. /// A property wrapper updated by the view graph before each access to
  2. /// ``View/body``.
  3. ///
  4. /// Conforming types should use internal mutability to implement this protocol's
  5. /// non-`mutating` methods if required. This protocol avoids mutation to allow
  6. /// state properties and such to be captured even though views are structs.
  7. public protocol DynamicProperty {
  8. /// Updates the property.
  9. ///
  10. /// This is called by SwiftCrossUI before every access it makes to an
  11. /// `App.body` or `View.body`.
  12. ///
  13. /// - Parameters:
  14. /// - environment: The current environment.
  15. /// - previousValue: The previous value of the property. `nil` if this is
  16. /// the first time an update has been made.
  17. func update(
  18. with environment: EnvironmentValues,
  19. previousValue: Self?
  20. )
  21. }