@@ -30,7 +30,7 @@ struct ViewTreeBuilder<R: RootRegistry> {
3030 }
3131
3232 @ViewBuilder
33- fileprivate func fromNode( _ node: Node , context: LiveContextStorage < R > ) -> some View {
33+ func fromNode( _ node: Node , context: LiveContextStorage < R > ) -> some View {
3434 switch node. data {
3535 case . root:
3636 fatalError ( " ViewTreeBuilder.fromNode may not be called with the root node " )
@@ -41,7 +41,7 @@ struct ViewTreeBuilder<R: RootRegistry> {
4141 }
4242 }
4343
44- fileprivate func fromElement( _ element: ElementNode , context: LiveContextStorage < R > ) -> some View {
44+ func fromElement( _ element: ElementNode , context: LiveContextStorage < R > ) -> some View {
4545 let view = createView ( element, context: context)
4646
4747 let modified = view. applyModifiers ( R . self)
@@ -210,10 +210,17 @@ private struct ModifierApplicator<Parent: View, R: RootRegistry>: View {
210210 let context : LiveContextStorage < R >
211211
212212 var body : some View {
213- let remaining = modifiers. dropFirst ( )
214- // force-unwrap is okay, this view is never constructed with an empty slice
215- parent. modifier ( modifiers. first!. modifier)
216- . applyModifiers ( remaining, element: element, context: context)
213+ if modifiers. isEmpty {
214+ parent
215+ } else {
216+ ModifierApplicator < _ , R > (
217+ // force-unwrap is okay, this view is never constructed with an empty slice
218+ parent: parent. modifier ( modifiers. first!. modifier) ,
219+ modifiers: modifiers. dropFirst ( ) ,
220+ element: element,
221+ context: context
222+ )
223+ }
217224 }
218225}
219226
@@ -245,11 +252,7 @@ extension View {
245252
246253 @ViewBuilder
247254 func applyModifiers< R: RootRegistry > ( _ modifiers: ArraySlice < ModifierContainer < R > > , element: ElementNode , context: LiveContextStorage < R > ) -> some View {
248- if modifiers. isEmpty {
249- self
250- } else {
251- ModifierApplicator ( parent: self , modifiers: modifiers, element: element, context: context)
252- }
255+ ModifierApplicator ( parent: self , modifiers: modifiers, element: element, context: context)
253256 }
254257
255258 @ViewBuilder
@@ -262,16 +265,6 @@ extension View {
262265 }
263266}
264267
265- // not fileprivate because it's used by LiveContext.
266- internal struct NodeView < R: RootRegistry > : View {
267- let node : Node
268- let context : LiveContextStorage < R >
269-
270- var body : some View {
271- context. coordinator. builder. fromNode ( node, context: context)
272- }
273- }
274-
275268private enum ForEachElement : Identifiable {
276269 case keyed( Node , id: String )
277270 case unkeyed( Node )
@@ -300,7 +293,7 @@ func forEach<R: CustomRegistry>(nodes: some Collection<Node>, context: LiveConte
300293 switch $0 {
301294 case let . keyed( node, _) ,
302295 let . unkeyed( node) :
303- NodeView ( node : node, context: context)
296+ context . coordinator . builder . fromNode ( node, context: context)
304297 }
305298 }
306299}
0 commit comments