|
1 | 1 | // |
2 | 2 | // ViewModifier.swift |
3 | | -// OpenSwiftUI |
| 3 | +// OpenSwiftUICore |
4 | 4 | // |
5 | 5 | // Audited for iOS 15.5 |
6 | 6 | // Status: Complete |
|
48 | 48 | /// Downtown Bus. A view extension, using custom a modifier, renders the |
49 | 49 | /// caption in blue text surrounded by a rounded |
50 | 50 | /// rectangle.](OpenSwiftUI-View-ViewModifier.png) |
| 51 | +@MainActor |
| 52 | +@preconcurrency |
51 | 53 | public protocol ViewModifier { |
52 | | - /// The type of view representing the body. |
53 | | - associatedtype Body: View |
54 | | - |
55 | 54 | /// Makes a new view using the view modifier and inputs that you provide. |
56 | | - static func _makeView( |
| 55 | + nonisolated static func _makeView( |
57 | 56 | modifier: _GraphValue<Self>, |
58 | 57 | inputs: _ViewInputs, |
59 | 58 | body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs |
60 | 59 | ) -> _ViewOutputs |
61 | 60 |
|
62 | | - static func _makeViewList( |
| 61 | + nonisolated static func _makeViewList( |
63 | 62 | modifier: _GraphValue<Self>, |
64 | 63 | inputs: _ViewListInputs, |
65 | 64 | body: @escaping (_Graph, _ViewListInputs) -> _ViewListOutputs |
66 | 65 | ) -> _ViewListOutputs |
67 | 66 |
|
68 | 67 | /// The number of views that `_makeViewList()` would produce, or |
69 | 68 | /// nil if unknown. |
70 | | - static func _viewListCount( |
| 69 | + nonisolated static func _viewListCount( |
71 | 70 | inputs: _ViewListCountInputs, |
72 | 71 | body: (_ViewListCountInputs) -> Int? |
73 | 72 | ) -> Int? |
74 | 73 |
|
75 | | - /// The content view type passed to `body()`. |
76 | | - typealias Content = _ViewModifier_Content<Self> |
| 74 | + /// The type of view representing the body. |
| 75 | + associatedtype Body: View |
77 | 76 |
|
78 | 77 | /// Gets the current body of the caller. |
79 | 78 | /// |
80 | 79 | /// `content` is a proxy for the view that will have the modifier |
81 | 80 | /// represented by `Self` applied to it. |
82 | 81 | @ViewBuilder |
83 | | - @MainActor |
84 | | - @preconcurrency |
85 | 82 | func body(content: Content) -> Body |
86 | | -} |
87 | | - |
88 | | -extension ViewModifier { |
89 | | - public static func _makeView( |
90 | | - modifier: _GraphValue<Self>, |
91 | | - inputs: _ViewInputs, |
92 | | - body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs |
93 | | - ) -> _ViewOutputs { |
94 | | - makeView(modifier: modifier, inputs: inputs, body: body) |
95 | | - } |
96 | 83 |
|
97 | | - public static func _makeViewList( |
98 | | - modifier: _GraphValue<Self>, |
99 | | - inputs: _ViewListInputs, |
100 | | - body: @escaping (_Graph, _ViewListInputs) -> _ViewListOutputs |
101 | | - ) -> _ViewListOutputs { |
102 | | - makeViewList(modifier: modifier, inputs: inputs, body: body) |
103 | | - } |
104 | | - |
105 | | - public static func _viewListCount( |
106 | | - inputs: _ViewListCountInputs, |
107 | | - body: (_ViewListCountInputs) -> Int? |
108 | | - ) -> Int? { |
109 | | - viewListCount(inputs: inputs, body: body) |
110 | | - } |
| 84 | + /// The content view type passed to `body()`. |
| 85 | + typealias Content = _ViewModifier_Content<Self> |
111 | 86 | } |
112 | 87 |
|
| 88 | +package protocol PrimitiveViewModifier: ViewModifier where Body == Never {} |
| 89 | + |
113 | 90 | extension ViewModifier where Body == Never { |
114 | 91 | public func body(content _: Content) -> Never { |
115 | 92 | bodyError() |
@@ -163,3 +140,28 @@ extension ViewModifier { |
163 | 140 | preconditionFailure("body() should not be called on \(Self.self)") |
164 | 141 | } |
165 | 142 | } |
| 143 | + |
| 144 | +extension ViewModifier { |
| 145 | + public static func _makeView( |
| 146 | + modifier: _GraphValue<Self>, |
| 147 | + inputs: _ViewInputs, |
| 148 | + body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs |
| 149 | + ) -> _ViewOutputs { |
| 150 | + makeView(modifier: modifier, inputs: inputs, body: body) |
| 151 | + } |
| 152 | + |
| 153 | + public static func _makeViewList( |
| 154 | + modifier: _GraphValue<Self>, |
| 155 | + inputs: _ViewListInputs, |
| 156 | + body: @escaping (_Graph, _ViewListInputs) -> _ViewListOutputs |
| 157 | + ) -> _ViewListOutputs { |
| 158 | + makeViewList(modifier: modifier, inputs: inputs, body: body) |
| 159 | + } |
| 160 | + |
| 161 | + public static func _viewListCount( |
| 162 | + inputs: _ViewListCountInputs, |
| 163 | + body: (_ViewListCountInputs) -> Int? |
| 164 | + ) -> Int? { |
| 165 | + viewListCount(inputs: inputs, body: body) |
| 166 | + } |
| 167 | +} |
0 commit comments