Skip to content

Commit 1002ddc

Browse files
committed
Update VariadicView_Children
1 parent 65459f2 commit 1002ddc

File tree

4 files changed

+220
-38
lines changed

4 files changed

+220
-38
lines changed

Sources/OpenSwiftUICore/View/DynamicViewContent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ package struct DynamicViewContentOffsetTraitKey: _ViewTraitKey {
3333
package struct DynamicContentOffsetVisitor: ViewListVisitor {
3434
package var offset: Int?
3535

36-
package mutating func visit(view: _ViewList_View, traits: ViewTraitCollection) -> Bool {
36+
package mutating func visit(view: ViewList.View, traits: ViewTraitCollection) -> Bool {
3737
offset = traits.value(for: DynamicViewContentOffsetTraitKey.self)
3838
return false
3939
}

Sources/OpenSwiftUICore/View/Input/ViewList.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ extension ViewList.Elements {
747747
}
748748
}
749749

750-
// MARK: - View.List.ID
750+
// MARK: - ViewList.ID
751751

752752
@_spi(ForOpenSwiftUIOnly)
753753
public struct _ViewList_ID: Hashable {

Sources/OpenSwiftUICore/View/VariadicView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public enum _VariadicView {
3737
/// Spacer()
3838
/// Text(timestamp, format: .dateTime).layoutPriority(1)
3939
/// }
40-
///
40+
///
4141
public typealias Root = _VariadicView_Root
4242

4343
/// A type of root that creates a View when its result builder is invoked with View.

Sources/OpenSwiftUICore/View/VariadicView_Children.swift

Lines changed: 217 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,44 @@
77
// ID: 52A2FFECFBCF37BFFEED558E33EBD1E3 (?)
88
// ID: 9B09D1820E97ECBB666F7560EA2A2D2C (?)
99

10+
package import OpenGraphShims
1011

11-
// FIXME: Confirm the ID
12+
// MARK: - _VariadicView.Children + View [WIP]
1213

13-
import OpenGraphShims
14+
extension _VariadicView.Children: View, MultiView, PrimitiveView {
15+
nonisolated public static func _makeViewList(
16+
view: _GraphValue<Self>,
17+
inputs: _ViewListInputs
18+
) -> _ViewListOutputs {
19+
let child = _GraphValue(Child(children: view.value))
20+
return ForEach._makeViewList(view: child, inputs: inputs)
21+
}
22+
23+
nonisolated public static func _viewListCount(
24+
inputs: _ViewListCountInputs
25+
) -> Int? {
26+
nil
27+
}
28+
29+
private struct Child: Rule, AsyncAttribute {
30+
typealias Value = ForEach<_VariadicView.Children, AnyHashable, _VariadicView.Children.Element>
31+
32+
@Attribute var children: _VariadicView.Children
1433

15-
extension _VariadicView_Children: RandomAccessCollection {
34+
var value: Value {
35+
preconditionFailure("TODO")
36+
}
37+
}
38+
}
39+
40+
// MARK: - _VariadicView.Children + RandomAccessCollection [WIP]
41+
42+
extension _VariadicView.Children: RandomAccessCollection {
1643
public struct Element: PrimitiveView, UnaryView, Identifiable {
17-
18-
// var view: _ViewList_View
44+
var view: ViewList.View
1945
var traits: ViewTraitCollection
2046

2147
public var id: AnyHashable {
22-
// view.viewID
2348
preconditionFailure("TODO")
2449

2550
}
@@ -34,67 +59,224 @@ extension _VariadicView_Children: RandomAccessCollection {
3459
set { traits[key] = newValue }
3560
}
3661

37-
public static func _makeView(view: _GraphValue<_VariadicView_Children.Element>, inputs: _ViewInputs) -> _ViewOutputs {
62+
public static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
3863
preconditionFailure("TODO")
3964
}
4065
}
4166

4267
public var startIndex: Int {
4368
preconditionFailure("TODO")
44-
45-
// get
4669
}
70+
4771
public var endIndex: Int {
4872
preconditionFailure("TODO")
49-
50-
// get
5173
}
52-
public subscript(index: Int) -> _VariadicView_Children.Element {
53-
preconditionFailure("TODO")
5474

55-
// get
75+
public subscript(index: Int) -> Element {
76+
preconditionFailure("TODO")
5677
}
5778
}
5879

59-
extension _VariadicView_Children {
60-
private struct Child: Rule, AsyncAttribute {
61-
typealias Value = ForEach<_VariadicView_Children, AnyHashable, _VariadicView_Children.Element>
62-
63-
@Attribute var children: _VariadicView_Children
64-
65-
var value: Value {
66-
preconditionFailure("TODO")
67-
}
68-
}
80+
// MARK: - ViewListVisitor
81+
82+
package protocol ViewListVisitor {
83+
mutating func visit(view: ViewList.View, traits: ViewTraitCollection) -> Bool
6984
}
7085

86+
// MARK: - ViewList.Backing [WIP]
87+
7188
extension ViewList {
7289
package typealias Backing = _ViewList_Backing
7390
}
7491

7592
package struct _ViewList_Backing {
7693
package var children: _VariadicView.Children
77-
// package var viewCount: Swift.Int {
78-
// get
79-
// }
94+
95+
package var viewCount: Swift.Int {
96+
children.list.count
97+
}
98+
8099
package init(_ children: _VariadicView.Children) {
81100
self.children = children
82101
}
83-
// package func visitViews<V>(applying v: inout V, from start: inout Swift.Int) -> Swift.Bool where V : SwiftUICore.ViewListVisitor
102+
103+
package func visitViews<V>(applying v: inout V, from start: inout Int) -> Bool where V: ViewListVisitor {
104+
Update.ensure {
105+
children.list.applySublists(from: &start, list: nil) { sublist in
106+
preconditionFailure("TODO")
107+
}
108+
}
109+
}
110+
}
111+
112+
extension ViewList.Backing {
113+
package func visitAll<V>(applying v: inout V) where V: ViewListVisitor {
114+
preconditionFailure("TODO")
115+
}
116+
117+
package func visitViews<V>(applying v: inout V, from start: Int) where V: ViewListVisitor {
118+
preconditionFailure("TODO")
119+
}
84120
}
85121

86-
// MARK: - _ViewList_View
122+
extension ViewList.Backing {
123+
package var ids: [AnyHashable] {
124+
preconditionFailure("TODO")
125+
}
126+
}
87127

88-
package struct _ViewList_View {
128+
// MARK: - _ViewList.View
129+
130+
extension ViewList {
131+
package typealias View = _ViewList_View
132+
}
133+
134+
package struct _ViewList_View: PrimitiveView, View, UnaryView {
89135
var elements: any ViewList.Elements
90-
var id: _ViewList_ID
136+
var releaseElements: ViewList.Elements.Release?
137+
package var id: ViewList.ID
91138
var index: Int
92139
var count: Int
93-
var contentSubgraph: Subgraph
140+
var contentSubgraph: Subgraph?
141+
142+
package init(
143+
elements: any ViewList.Elements,
144+
id: ViewList.ID,
145+
index: Int,
146+
count: Int,
147+
contentSubgraph: Subgraph
148+
) {
149+
self.elements = elements
150+
self.id = id
151+
self.index = index
152+
self.count = count
153+
self.contentSubgraph = contentSubgraph
154+
}
155+
156+
package var elementID: ViewList.ID {
157+
id.elementID(at: index)
158+
}
159+
160+
package var reuseIdentifier: Int {
161+
elementID.reuseIdentifier
162+
}
163+
164+
package var viewID: AnyHashable {
165+
let canonicalID = elementID.canonicalID
166+
if count == 1, !canonicalID.requiresImplicitID {
167+
return canonicalID.explicitID!.anyHashable
168+
} else {
169+
return AnyHashable(canonicalID)
170+
}
171+
}
172+
173+
nonisolated package static func _makeView(
174+
view: _GraphValue<Self>,
175+
inputs: _ViewInputs
176+
) -> _ViewOutputs {
177+
let outputs = inputs.makeIndirectOutputs()
178+
let placeholderInfo = PlaceholderInfo(
179+
placeholder: view.value,
180+
inputs: inputs,
181+
outputs: outputs,
182+
parentSubgraph: .current!
183+
)
184+
let attribute = Attribute(placeholderInfo)
185+
outputs.setIndirectDependency(attribute.identifier)
186+
return outputs
187+
}
94188
}
95189

96-
// MARK: - ViewListVisitor
190+
// MARK: - PlaceholderInfo [WIP]
191+
192+
private struct PlaceholderInfo: StatefulRule, ObservedAttribute, AsyncAttribute {
193+
@Attribute var placeholder: ViewList.View
194+
let inputs: _ViewInputs
195+
let outputs: _ViewOutputs
196+
let parentSubgraph: Subgraph
197+
var lastSubgraph: Subgraph?
198+
var lastRelease: ViewList.Elements.Release?
199+
var secondaryRelease: ViewList.Elements.Release?
200+
var lastElements: (any ViewList.Elements)?
201+
var lastMap: IndirectAttributeMap?
202+
var contentObserver: (Subgraph, Int)?
203+
var lastPhase: Attribute<_GraphInputs.Phase>?
204+
205+
struct Value {
206+
var id: ViewList.ID
207+
var seed: UInt32
208+
var index: Int
209+
}
210+
211+
func makeItem(placeholder: ViewList.View, seed: UInt32) -> Value {
212+
preconditionFailure("TODO")
213+
}
97214

98-
protocol ViewListVisitor {
99-
mutating func visit(view: _ViewList_View, traits: ViewTraitCollection) -> Bool
215+
mutating func reuseItem(info: inout Value, placeholder: ViewList.View) -> Bool {
216+
guard let lastElements,
217+
lastElements.tryToReuseElement(
218+
at: info.index,
219+
by: placeholder.elements,
220+
at: placeholder.index,
221+
indirectMap: lastMap!,
222+
testOnly: false
223+
)
224+
else {
225+
ReuseTrace.traceReuseInvalidSubgraphFailure(ViewList.View.self)
226+
return false
227+
}
228+
lastPhase!.mutateBody(
229+
as: PlaceholderViewPhase.self,
230+
invalidating: true
231+
) { phase in
232+
phase.resetDelta &+= 1
233+
}
234+
secondaryRelease = placeholder.elements.retain()
235+
info.id = placeholder.id
236+
info.index = placeholder.index
237+
return true
238+
}
239+
240+
mutating func eraseItem() {
241+
outputs.detachIndirectOutputs()
242+
if let lastSubgraph {
243+
lastSubgraph.willInvalidate(isInserted: true)
244+
lastSubgraph.invalidate()
245+
self.lastSubgraph = nil
246+
}
247+
if let contentObserver {
248+
// TODO: OSubgraphRemoveObserver
249+
// contentObserver.0.removeObserver(contentObserver.1)
250+
self.contentObserver = nil
251+
}
252+
lastRelease = nil
253+
secondaryRelease = nil
254+
lastElements = nil
255+
lastMap = nil
256+
lastPhase = nil
257+
}
258+
259+
mutating func updateValue() {
260+
preconditionFailure("TODO")
261+
}
262+
263+
func destroy() {
264+
if let contentObserver {
265+
// TODO: OSubgraphRemoveObserver
266+
// contentObserver.0.removeObserver(contentObserver.1)
267+
}
268+
}
269+
}
270+
271+
private struct PlaceholderViewPhase: Rule, AsyncAttribute {
272+
@Attribute var phase1: _GraphInputs.Phase
273+
@Attribute var phase2: _GraphInputs.Phase
274+
var resetDelta: UInt32
275+
276+
var value: _GraphInputs.Phase {
277+
var result = phase1
278+
result.merge(phase2)
279+
result.resetSeed &+= resetDelta
280+
return result
281+
}
100282
}

0 commit comments

Comments
 (0)