ViewGraphNodeChildren.swift 1.0 KB

123456789101112131415161718192021
  1. /// The children of a view graph node. This is implemented by a few different
  2. /// types for various purposes. E.g. variable length with same-typed elements
  3. /// (``ForEach``), and fixed length with distinctly-typed elements (``TupleView1``,
  4. /// ``TupleView2``, etc).
  5. @MainActor
  6. public protocol ViewGraphNodeChildren {
  7. /// The widget of the children. Type-erased to avoid the type of the currently
  8. /// selected backend leaking into the ``View`` protocol, requiring users to
  9. /// engage with annoying complexity and reducing ease of backend switching.
  10. var widgets: [AnyWidget] { get }
  11. /// Erased representations of all contained child nodes.
  12. var erasedNodes: [ErasedViewGraphNode] { get }
  13. }
  14. extension ViewGraphNodeChildren {
  15. /// Gets the node's type-erased widgets for a specific backend (crashing if the
  16. /// widgets were created by a different backend).
  17. public func widgets<Backend: BaseAppBackend>(for backend: Backend) -> [Backend.Widget] {
  18. return widgets.map { $0.into() }
  19. }
  20. }