7
7
// ID: 52A2FFECFBCF37BFFEED558E33EBD1E3 (?)
8
8
// ID: 9B09D1820E97ECBB666F7560EA2A2D2C (?)
9
9
10
+ package import OpenGraphShims
10
11
11
- // FIXME: Confirm the ID
12
+ // MARK: - _VariadicView.Children + View [WIP]
12
13
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
14
33
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 {
16
43
public struct Element : PrimitiveView , UnaryView , Identifiable {
17
-
18
- // var view: _ViewList_View
44
+ var view : ViewList . View
19
45
var traits : ViewTraitCollection
20
46
21
47
public var id : AnyHashable {
22
- // view.viewID
23
48
preconditionFailure ( " TODO " )
24
49
25
50
}
@@ -34,67 +59,224 @@ extension _VariadicView_Children: RandomAccessCollection {
34
59
set { traits [ key] = newValue }
35
60
}
36
61
37
- public static func _makeView( view: _GraphValue < _VariadicView_Children . Element > , inputs: _ViewInputs ) -> _ViewOutputs {
62
+ public static func _makeView( view: _GraphValue < Self > , inputs: _ViewInputs ) -> _ViewOutputs {
38
63
preconditionFailure ( " TODO " )
39
64
}
40
65
}
41
66
42
67
public var startIndex : Int {
43
68
preconditionFailure ( " TODO " )
44
-
45
- // get
46
69
}
70
+
47
71
public var endIndex : Int {
48
72
preconditionFailure ( " TODO " )
49
-
50
- // get
51
73
}
52
- public subscript( index: Int ) -> _VariadicView_Children . Element {
53
- preconditionFailure ( " TODO " )
54
74
55
- // get
75
+ public subscript( index: Int ) -> Element {
76
+ preconditionFailure ( " TODO " )
56
77
}
57
78
}
58
79
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
69
84
}
70
85
86
+ // MARK: - ViewList.Backing [WIP]
87
+
71
88
extension ViewList {
72
89
package typealias Backing = _ViewList_Backing
73
90
}
74
91
75
92
package struct _ViewList_Backing {
76
93
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
+
80
99
package init ( _ children: _VariadicView . Children ) {
81
100
self . children = children
82
101
}
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
+ }
84
120
}
85
121
86
- // MARK: - _ViewList_View
122
+ extension ViewList . Backing {
123
+ package var ids : [ AnyHashable ] {
124
+ preconditionFailure ( " TODO " )
125
+ }
126
+ }
87
127
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 {
89
135
var elements : any ViewList . Elements
90
- var id : _ViewList_ID
136
+ var releaseElements : ViewList . Elements . Release ?
137
+ package var id : ViewList . ID
91
138
var index : Int
92
139
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
+ }
94
188
}
95
189
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
+ }
97
214
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
+ }
100
282
}
0 commit comments