-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathVariadicView.swift
49 lines (45 loc) · 1.52 KB
/
VariadicView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/// A type of structured content that is passed as an argument to a
/// `Root`'s result builder, creating a `Tree` that conditionally conforms
/// to protocols like `View`.
///
/// For example, `View`s can be passed to a `Layout` result builder
/// creating a `View`:
///
/// HStack {
/// Image(name: "envelope")
/// Text("Your time away request has been approved")
/// Spacer()
/// Text(timestamp, format: .dateTime).layoutPriority(1)
/// }
///
public enum _VariadicView {
public typealias Root = _VariadicView_Root
public typealias ViewRoot = _VariadicView_ViewRoot
public typealias Children = _VariadicView_Children
// public typealias UnaryViewRoot = _VariadicView_UnaryViewRoot
// public typealias MultiViewRoot = _VariadicView_MultiViewRoot
@frozen
public struct Tree<Root: _VariadicView_Root, Content> {
public var root: Root
public var content: Content
@inlinable
init(root: Root, content: Content) {
self.root = root
self.content = content
}
@inlinable public init(_ root: Root, @ViewBuilder content: () -> Content) {
self.root = root
self.content = content()
}
}
}
extension _VariadicView_ViewRoot {
func bodyError() -> Never {
preconditionFailure("body() should not be called on \(Self.self)")
}
}
extension _VariadicView_ViewRoot where Body == Never {
public func body(children: _VariadicView.Children) -> Never {
bodyError()
}
}