From 3f71ba5914aa115c9c1906a6dbb7df18351635b1 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 12 Oct 2025 12:57:03 +0800 Subject: [PATCH] Add ModifiedViewList implementation --- .../OpenSwiftUICore/View/Input/ViewList.swift | 117 +++++++++++++++++- 1 file changed, 114 insertions(+), 3 deletions(-) diff --git a/Sources/OpenSwiftUICore/View/Input/ViewList.swift b/Sources/OpenSwiftUICore/View/Input/ViewList.swift index 6aa64bf15..d3cc3923a 100644 --- a/Sources/OpenSwiftUICore/View/Input/ViewList.swift +++ b/Sources/OpenSwiftUICore/View/Input/ViewList.swift @@ -1383,9 +1383,24 @@ extension _ViewListOutputs { package mutating func multiModifier(_ modifier: _GraphValue, inputs: _ViewListInputs) where T: ViewModifier { switch views { case let .staticList(elements): - views = .staticList(ModifiedElements(base: elements, modifier: WeakAttribute(modifier.value), baseInputs: inputs.base)) - case .dynamicList(_, _): - _openSwiftUIUnimplementedFailure() + views = .staticList( + ModifiedElements( + base: elements, + modifier: WeakAttribute( + modifier.value + ), + baseInputs: inputs.base + ) + ) + case let .dynamicList(attribute, listModifier): + views = .dynamicList( + attribute, + ModifiedViewList.ListModifier( + pred: listModifier, + modifier: modifier, + inputs: inputs.base + ) + ) } } @@ -1565,6 +1580,102 @@ private struct ModifiedElements: ViewList.Elements where Modifier: Vie } } +// MARK: - ModifiedViewList [6.5.4] + +private struct ModifiedViewList: ViewList where Modifier: ViewModifier { + let base: ViewList + let modifier: WeakAttribute + let inputs: _GraphInputs + + func count(style: IteratorStyle) -> Int { + base.count(style: style) + } + + func estimatedCount(style: IteratorStyle) -> Int { + base.estimatedCount(style: style) + } + + var traitKeys: ViewTraitKeys? { + base.traitKeys + } + + var viewIDs: ID.Views? { + base.viewIDs + } + + var traits: ViewTraitCollection { + base.traits + } + + func applyNodes( + from start: inout Int, + style: IteratorStyle, + list: Attribute?, + transform: inout SublistTransform, + to body: ApplyBody + ) -> Bool { + let item = Transform(modifier: modifier, inputs: inputs) + transform.push(item) + defer { transform.pop() } + return base.applyNodes( + from: &start, + style: style, + list: list, + transform: &transform, + to: body + ) + } + + func edit( + forID id: ID, + since transaction: TransactionID + ) -> Edit? { + base.edit(forID: id, since: transaction) + } + + func firstOffset( + forID id: OtherID, + style: IteratorStyle + ) -> Int? where OtherID : Hashable { + base.firstOffset(forID: id, style: style) + } + + struct Transform: ViewList.SublistTransform.Item { + var modifier: WeakAttribute + var inputs: _GraphInputs + + func apply(sublist: inout _ViewList_Sublist) { + sublist.elements = ModifiedElements(base: sublist.elements, modifier: modifier, baseInputs: inputs) + } + + func bindID(_ id: inout _ViewList_ID) { + _openSwiftUIEmptyStub() + } + } + + class ListModifier: _ViewListOutputs.ListModifier { + let pred: _ViewListOutputs.ListModifier? + let modifier: WeakAttribute + let inputs: _GraphInputs + + init( + pred: _ViewListOutputs.ListModifier?, + modifier: _GraphValue, + inputs: _GraphInputs + ) { + self.pred = pred + self.modifier = WeakAttribute(modifier.value) + self.inputs = inputs + } + + override func apply(to list: inout any ViewList) { + pred?.apply(to: &list) + list = ModifiedViewList(base: list, modifier: modifier, inputs: inputs) + } + } + +} + // MARK: - BaseViewList [6.4.41] private struct BaseViewList: ViewList {