1
1
//
2
2
// ViewRendererHost.swift
3
- // OpenSwiftUI
3
+ // OpenSwiftUICore
4
4
//
5
- // Audited for RELEASE_2021
5
+ // Audited for RELEASE_2024
6
6
// Status: WIP
7
+ // ID: 76C8A4B3FC8EE0F99045B3425CD62255
7
8
9
+ import Foundation
8
10
internal import OpenGraphShims
9
11
10
12
// MARK: - ViewRendererHostProperties
@@ -39,6 +41,8 @@ package enum ViewRenderingPhase {
39
41
@available ( * , unavailable)
40
42
extension ViewRenderingPhase : Sendable { }
41
43
44
+ // MARK: - ViewRendererHost
45
+
42
46
package protocol ViewRendererHost : ViewGraphDelegate {
43
47
var viewGraph : ViewGraph { get }
44
48
var currentTimestamp : Time { get set }
@@ -64,49 +68,85 @@ package protocol ViewRendererHost: ViewGraphDelegate {
64
68
65
69
extension ViewRendererHost {
66
70
package var isRendering : Bool {
71
+ renderingPhase != . none
72
+ }
73
+
74
+ package func initializeViewGraph( ) {
75
+ // viewGraph.delegate = self
76
+ // TODO: Signpost related
77
+ }
78
+
79
+ package func invalidate( ) {
80
+ // viewGraph.delegate = nil
81
+ // TODO: Signpost.viewHost
67
82
fatalError ( " TODO " )
68
83
}
69
- }
70
-
71
- // TODO: FIXME
72
-
73
- extension ViewRendererHost {
74
- package func updateViewGraph< Value> ( body: ( ViewGraph ) -> Value ) -> Value {
84
+
85
+ // package static func makeRootView<V>(_ view: V) -> ModifiedContent<V, HitTestBindingModifier> where V: View
86
+ package static func makeRootView< V: View > ( _ view: V ) -> some View {
87
+ view/*.modifier(HitTestBindingModifier())*/
88
+ }
89
+
90
+ @_spi ( ForOpenSwiftUIOnly)
91
+ public func updateViewGraph< T> ( body: ( ViewGraph ) -> T ) -> T {
92
+ // FIXME
75
93
Update . dispatchImmediately {
76
94
OGGraph . withoutUpdate {
77
95
updateGraph ( )
78
96
return body ( viewGraph)
79
97
}
80
98
}
81
99
}
82
- }
83
-
84
- extension ViewRendererHost {
85
- package func initializeViewGraph( ) {
86
- viewGraph. delegate = self
87
- // TODO: Signpost related
100
+
101
+ @_spi ( ForOpenSwiftUIOnly)
102
+ public func graphDidChange( ) {
103
+ fatalError ( " TODO " )
88
104
}
89
105
90
- package func invalidateProperties( _ properties: ViewRendererHostProperties , mayDeferUpdate: Bool ) {
91
- Update . locked {
92
- guard !propertiesNeedingUpdate. contains ( properties) else {
93
- return
94
- }
95
- propertiesNeedingUpdate. insert ( properties)
96
- viewGraph. setNeedsUpdate ( mayDeferUpdate: mayDeferUpdate)
97
- requestUpdate ( after: . zero)
98
- }
106
+ package func didRender( ) {
107
+ fatalError ( " TODO " )
99
108
}
100
109
101
- package func startProfiling( ) {
102
- OGGraph . startProfiling ( viewGraph. graph)
110
+ @_spi ( ForOpenSwiftUIOnly)
111
+ public func preferencesDidChange( ) {
112
+ fatalError ( " TODO " )
103
113
}
104
114
105
- package func stopProfiling( ) {
106
- OGGraph . stopProfiling ( viewGraph. graph)
115
+ package func invalidateProperties( _ props: ViewRendererHostProperties , mayDeferUpdate: Bool = true ) {
116
+ // FIXME
117
+ // Update.locked {
118
+ // guard !propertiesNeedingUpdate.contains(properties) else {
119
+ // return
120
+ // }
121
+ // propertiesNeedingUpdate.insert(properties)
122
+ // viewGraph.setNeedsUpdate(mayDeferUpdate: mayDeferUpdate)
123
+ // requestUpdate(after: .zero)
124
+ // }
107
125
}
108
126
109
- package func render( interval: Double , updateDisplayList: Bool = true ) {
127
+ package func updateGraph( ) {
128
+ // FIXME
129
+ let properties = propertiesNeedingUpdate
130
+ // addImplicitPropertiesNeedingUpdate(to: &properties)
131
+ guard !properties. isEmpty else { return }
132
+ Update . syncMain {
133
+ func update( _ property: ViewRendererHostProperties , body: ( ) -> Void ) {
134
+ if properties. contains ( property) {
135
+ propertiesNeedingUpdate. remove ( property)
136
+ }
137
+ body ( )
138
+ }
139
+ update ( . rootView) { updateRootView ( ) }
140
+ // TODO:
141
+ }
142
+ }
143
+
144
+ package func updateTransform( ) {
145
+ fatalError ( " TODO " )
146
+ }
147
+
148
+ package func render( interval: Double = 0 , updateDisplayList: Bool = true , targetTimestamp: Time ? = nil ) {
149
+ // FIXME
110
150
Update . dispatchImmediately {
111
151
guard !isRendering else {
112
152
return
@@ -128,29 +168,126 @@ extension ViewRendererHost {
128
168
}
129
169
}
130
170
131
- package static func makeRootView < V : View > ( _ view : V ) -> some View {
132
- view/*.modifier(HitTestBindingModifier())*/
171
+ package func renderAsync ( interval : Double = 0 , targetTimestamp : Time ? ) -> Time ? {
172
+ fatalError ( " TODO " )
133
173
}
134
174
135
- package func updateGraph( ) {
136
- var properties = propertiesNeedingUpdate
137
- addImplicitPropertiesNeedingUpdate ( to: & properties)
138
- guard !properties. isEmpty else { return }
139
- Update . syncMain {
140
- func update( _ property: ViewRendererHostProperties , body: ( ) -> Void ) {
141
- if properties. contains ( property) {
142
- propertiesNeedingUpdate. remove ( property)
143
- }
144
- body ( )
145
- }
146
- update ( . rootView) { updateRootView ( ) }
147
- // TODO:
175
+ package func advanceTimeForTest( interval: Double ) {
176
+ fatalError ( " TODO " )
177
+ }
178
+
179
+ @_spi ( Private)
180
+ public func preferenceValue< K> ( _ key: K . Type ) -> K . Value where K: HostPreferenceKey {
181
+ fatalError ( " TODO " )
182
+ }
183
+
184
+ package func idealSize( ) -> CGSize { fatalError ( " TODO " ) }
185
+
186
+ package func sizeThatFits( _ proposal: _ProposedSize ) -> CGSize {
187
+ fatalError ( " TODO " )
188
+ }
189
+ package func explicitAlignment( of guide: HorizontalAlignment , at size: CGSize ) -> CGFloat ? {
190
+ fatalError ( " TODO " )
191
+ }
192
+ package func explicitAlignment( of guide: VerticalAlignment , at size: CGSize ) -> CGFloat ? {
193
+ fatalError ( " TODO " )
194
+ }
195
+ package func alignment( of guide: HorizontalAlignment , at size: CGSize ) -> CGFloat {
196
+ fatalError ( " TODO " )
197
+ }
198
+ package func alignment( of guide: VerticalAlignment , at size: CGSize ) -> CGFloat {
199
+ fatalError ( " TODO " )
200
+ }
201
+ package var centersRootView : Bool {
202
+ get { fatalError ( " TODO " ) }
203
+ set { fatalError ( " TODO " ) }
204
+ }
205
+
206
+ // package var responderNode: ResponderNode? {
207
+ // fatalError("TODO")
208
+ // }
209
+
210
+ package var isRootHost : Bool {
211
+ fatalError ( " TODO " )
212
+ }
213
+ private var enclosingHosts : [ ViewRendererHost ] { fatalError ( " TODO " ) }
214
+ package func performExternalUpdate( _ update: ( ) -> Void ) { fatalError ( " TODO " ) }
215
+ package func updateFocusedItem( ) { fatalError ( " TODO " ) }
216
+ package func updateFocusedValues( ) { fatalError ( " TODO " ) }
217
+ package func updateFocusStore( ) { fatalError ( " TODO " ) }
218
+ package func updateAccessibilityFocus( ) { fatalError ( " TODO " ) }
219
+ package func updateAccessibilityFocusStore( ) { fatalError ( " TODO " ) }
220
+ package func updateAccessibilityEnvironment( ) { fatalError ( " TODO " ) }
221
+ }
222
+
223
+ // MARK: - ViewRendererHost + Gesture [TODO]
224
+
225
+ //package let hostingViewCoordinateSpace: CoordinateSpace.ID
226
+
227
+ //extension ViewRendererHost {
228
+ // package var nextGestureUpdateTime: Time {
229
+ // get
230
+ // }
231
+ // package func sendEvents(_ events: [EventID : any EventType], rootNode: ResponderNode, at time: Time) -> GesturePhase<Void>
232
+ // package func resetEvents()
233
+ // package func gestureCategory() -> GestureCategory?
234
+ // package func setInheritedPhase(_ phase: _GestureInputs.InheritedPhase)
235
+ //}
236
+
237
+ //extension ViewRendererHost {
238
+ // package func sendTestEvents(_ events: [EventID : any EventType])
239
+ // package func resetTestEvents()
240
+ //}
241
+
242
+ // MARK: - ViewGraph + viewRendererHost
243
+
244
+ extension ViewGraph {
245
+ package static var viewRendererHost : ( any ViewRendererHost ) ? {
246
+ ViewGraph . current. delegate as? ViewRendererHost
247
+ }
248
+ }
249
+
250
+ // MARK: - EnvironmentValues + PreferenceBridge
251
+
252
+ extension EnvironmentValues {
253
+ private struct PreferenceBridgeKey : EnvironmentKey {
254
+ struct Value {
255
+ weak var value : PreferenceBridge ?
148
256
}
257
+ static let defaultValue : Value = Value ( )
149
258
}
150
259
151
- package func invalidate( ) {
152
- viewGraph. delegate = nil
153
- // TODO: Signpost.viewHost
260
+ package var preferenceBridge : PreferenceBridge ? {
261
+ get { self [ PreferenceBridgeKey . self] . value }
262
+ set { self [ PreferenceBridgeKey . self] . value = newValue }
263
+ }
264
+ }
265
+
266
+ // MARK: - ViewRendererHost + rootContentPath [TODO]
267
+
268
+ extension ViewRendererHost {
269
+ package func rootContentPath( kind: ContentShapeKinds ) -> Path {
270
+ fatalError ( " TODO " )
271
+ }
272
+ }
273
+
274
+ // MARK: - ViewRendererHost + Graph [TODO]
275
+
276
+ extension ViewRendererHost {
277
+ package func startProfiling( ) {
278
+ Graph . startProfiling ( viewGraph. graph)
279
+ }
280
+
281
+ package func stopProfiling( ) {
282
+ Graph . stopProfiling ( viewGraph. graph)
283
+ }
284
+
285
+ package func resetProfile( ) {
286
+ // Graph.resetProfile(viewGraph.graph)
287
+ }
288
+
289
+ package func archiveJSON( name: String ? = nil ) {
290
+ // viewGraph.graph.archiveJSON(name: name)
154
291
}
155
292
}
156
293
0 commit comments