Skip to content

Commit a709674

Browse files
committed
Update ViewRendererHost
1 parent 6956e53 commit a709674

File tree

4 files changed

+222
-65
lines changed

4 files changed

+222
-65
lines changed

Sources/OpenSwiftUI/Integration/UIKit/UIHostingView.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,44 @@ open class _UIHostingView<Content>: UIView where Content: View {
154154
}
155155

156156
extension _UIHostingView: ViewRendererHost {
157+
package var renderingPhase: OpenSwiftUICore.ViewRenderingPhase {
158+
get {
159+
fatalError("TODO")
160+
}
161+
set(newValue) {
162+
fatalError("TODO")
163+
}
164+
}
165+
166+
package var externalUpdateCount: Int {
167+
get {
168+
fatalError("TODO")
169+
}
170+
set(newValue) {
171+
fatalError("TODO")
172+
}
173+
}
174+
175+
package func updateEnvironment() {
176+
fatalError("TODO")
177+
}
178+
179+
package func updateSize() {
180+
fatalError("TODO")
181+
}
182+
183+
package func updateSafeArea() {
184+
fatalError("TODO")
185+
}
186+
187+
package func updateScrollableContainerSize() {
188+
fatalError("TODO")
189+
}
190+
191+
package func renderDisplayList(_ list: DisplayList, asynchronously: Bool, time: Time, nextTime: Time, targetTimestamp: Time?, version: DisplayList.Version, maxVersion: DisplayList.Version) -> Time {
192+
fatalError("TODO")
193+
}
194+
157195
package func addImplicitPropertiesNeedingUpdate(to _: inout ViewRendererHostProperties) {}
158196

159197
package func updateRootView() {

Sources/OpenSwiftUICore/Data/Preference/View_Preference.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,3 @@ extension View {
2222
modifier(_PreferenceTransformModifier<K>(transform: callback))
2323
}
2424
}
25-
26-
extension EnvironmentValues {
27-
private struct PreferenceBridgeKey: EnvironmentKey {
28-
struct Value {
29-
weak var value: PreferenceBridge?
30-
}
31-
static let defaultValue: Value = Value()
32-
}
33-
34-
var preferenceBridge: PreferenceBridge? {
35-
get { self[PreferenceBridgeKey.self].value }
36-
set { self[PreferenceBridgeKey.self] = PreferenceBridgeKey.Value(value: newValue) }
37-
}
38-
}

Sources/OpenSwiftUICore/EventHandling/InputEvent/HitTesting/ContentShapeKinds.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// ContentShapeKinds.swift
33
// OpenSwiftUI
44
//
5-
// Audited for RELEASE_2023
5+
// Audited for RELEASE_2024
66
// Status: Complete
77

88
import Foundation
@@ -55,7 +55,6 @@ public struct ContentShapeKinds: OptionSet, Sendable {
5555
/// When using this kind, only the preview shape will be affected. To
5656
/// control the shape used to hit-test and start the context menu
5757
/// presentation, use the `.interaction` kind.
58-
@available(tvOS 17.0, *)
5958
@available(macOS, unavailable)
6059
@available(watchOS, unavailable)
6160
public static let contextMenuPreview: ContentShapeKinds = ContentShapeKinds(rawValue: 1 << 2)
@@ -69,10 +68,8 @@ public struct ContentShapeKinds: OptionSet, Sendable {
6968
/// This kind does not affect the `onHover` modifier.
7069
@available(macOS, unavailable)
7170
@available(watchOS, unavailable)
72-
@available(tvOS, unavailable)
7371
public static let hoverEffect: ContentShapeKinds = ContentShapeKinds(rawValue: 1 << 3)
7472

75-
#if OPENSWIFTUI_SUPPORT_2023_API
7673
/// The kind for accessibility visuals and sorting.
7774
///
7875
/// Setting a content shape with this kind causes the accessibility frame
@@ -85,5 +82,4 @@ public struct ContentShapeKinds: OptionSet, Sendable {
8582
///
8683
/// To control the shape for accessibility and hit-testing, use the `interaction` kind.
8784
public static let accessibility: ContentShapeKinds = ContentShapeKinds(rawValue: 1 << 4)
88-
#endif
8985
}

Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift

Lines changed: 183 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//
22
// ViewRendererHost.swift
3-
// OpenSwiftUI
3+
// OpenSwiftUICore
44
//
5-
// Audited for RELEASE_2021
5+
// Audited for RELEASE_2024
66
// Status: WIP
7+
// ID: 76C8A4B3FC8EE0F99045B3425CD62255
78

9+
import Foundation
810
internal import OpenGraphShims
911

1012
// MARK: - ViewRendererHostProperties
@@ -39,6 +41,8 @@ package enum ViewRenderingPhase {
3941
@available(*, unavailable)
4042
extension ViewRenderingPhase: Sendable {}
4143

44+
// MARK: - ViewRendererHost
45+
4246
package protocol ViewRendererHost: ViewGraphDelegate {
4347
var viewGraph: ViewGraph { get }
4448
var currentTimestamp: Time { get set }
@@ -64,49 +68,85 @@ package protocol ViewRendererHost: ViewGraphDelegate {
6468

6569
extension ViewRendererHost {
6670
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
6782
fatalError("TODO")
6883
}
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
7593
Update.dispatchImmediately {
7694
OGGraph.withoutUpdate {
7795
updateGraph()
7896
return body(viewGraph)
7997
}
8098
}
8199
}
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")
88104
}
89105

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")
99108
}
100109

101-
package func startProfiling() {
102-
OGGraph.startProfiling(viewGraph.graph)
110+
@_spi(ForOpenSwiftUIOnly)
111+
public func preferencesDidChange() {
112+
fatalError("TODO")
103113
}
104114

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+
// }
107125
}
108126

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
110150
Update.dispatchImmediately {
111151
guard !isRendering else {
112152
return
@@ -128,29 +168,126 @@ extension ViewRendererHost {
128168
}
129169
}
130170

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")
133173
}
134174

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?
148256
}
257+
static let defaultValue: Value = Value()
149258
}
150259

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)
154291
}
155292
}
156293

0 commit comments

Comments
 (0)