Skip to content

Commit cc69107

Browse files
committed
Update PreferenceBridge
1 parent a709674 commit cc69107

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
//
22
// PreferenceBridge.swift
3-
// OpenSwiftUI
3+
// OpenSwiftUICore
44
//
5-
// Audited for RELEASE_2021
6-
// Status: Complete
7-
// ID: A9FAE381E99529D5274BA37A9BC9B074
5+
// Audited for RELEASE_2024
6+
// Status: TO BE AUDITED
7+
// ID: A9FAE381E99529D5274BA37A9BC9B074 (RELEASE_2021)
8+
// ID: DF57A19C61B44C613EB77C1D47FC679A (RELEASE_2024)
89

910
internal import OpenGraphShims
1011

1112
package final class PreferenceBridge {
12-
unowned let viewGraph: ViewGraph
13+
weak var viewGraph: ViewGraph?
14+
var isValid: Bool = true
1315
private(set) var children: [Unmanaged<ViewGraph>] = []
1416
var requestedPreferences = PreferenceKeys()
1517
var bridgedViewInputs = PropertyList()
@@ -23,9 +25,15 @@ package final class PreferenceBridge {
2325
}
2426

2527
init() {
26-
viewGraph = GraphHost.currentHost as! ViewGraph
28+
viewGraph = ViewGraph.current
2729
}
2830

31+
deinit {
32+
if isValid { invalidate() }
33+
}
34+
35+
// FIXME: TO BE AUDITED
36+
2937
#if canImport(Darwin) // FIXME: See #39
3038
func addValue(_ value: AnyAttribute, for keyType: AnyPreferenceKey.Type) {
3139
struct AddValue: PreferenceKeyVisitor {
@@ -48,7 +56,7 @@ package final class PreferenceBridge {
4856
}
4957
var visitor = AddValue(combiner: combiner, value: value)
5058
keyType.visitKey(&visitor)
51-
viewGraph.graphInvalidation(from: value)
59+
viewGraph?.graphInvalidation(from: value)
5260
}
5361

5462
func removeValue(_ value: AnyAttribute, for keyType: AnyPreferenceKey.Type, isInvalidating: Bool) {
@@ -78,7 +86,7 @@ package final class PreferenceBridge {
7886
var visitor = RemoveValue(combiner: combiner, value: value)
7987
keyType.visitKey(&visitor)
8088
if visitor.changed {
81-
viewGraph.graphInvalidation(from: isInvalidating ? nil : value)
89+
viewGraph?.graphInvalidation(from: isInvalidating ? nil : value)
8290
}
8391
}
8492

@@ -92,7 +100,7 @@ package final class PreferenceBridge {
92100
) { combiner in
93101
combiner.addChild(keys: keys, values: values)
94102
}
95-
viewGraph.graphInvalidation(from: combiner.identifier)
103+
viewGraph?.graphInvalidation(from: combiner.identifier)
96104
}
97105

98106
func removeHostValue(for keys: Attribute<PreferenceKeys>, isInvalidating: Bool) {
@@ -112,7 +120,7 @@ package final class PreferenceBridge {
112120
hasRemoved = true
113121
}
114122
if hasRemoved {
115-
viewGraph.graphInvalidation(from: isInvalidating ? nil : keys.identifier)
123+
viewGraph?.graphInvalidation(from: isInvalidating ? nil : keys.identifier)
116124
}
117125
}
118126

Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ extension ViewRendererHost {
103103
fatalError("TODO")
104104
}
105105

106-
package func didRender() {
107-
fatalError("TODO")
108-
}
106+
package func didRender() {}
109107

110108
@_spi(ForOpenSwiftUIOnly)
111109
public func preferencesDidChange() {
@@ -199,8 +197,8 @@ extension ViewRendererHost {
199197
fatalError("TODO")
200198
}
201199
package var centersRootView: Bool {
202-
get { fatalError("TODO") }
203-
set { fatalError("TODO") }
200+
get { viewGraph.centersRootView }
201+
set { viewGraph.centersRootView = newValue }
204202
}
205203

206204
// package var responderNode: ResponderNode? {
@@ -212,12 +210,12 @@ extension ViewRendererHost {
212210
}
213211
private var enclosingHosts: [ViewRendererHost] { fatalError("TODO") }
214212
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") }
213+
package func updateFocusedItem() {}
214+
package func updateFocusedValues() {}
215+
package func updateFocusStore() {}
216+
package func updateAccessibilityFocus() {}
217+
package func updateAccessibilityFocusStore() {}
218+
package func updateAccessibilityEnvironment() {}
221219
}
222220

223221
// MARK: - ViewRendererHost + Gesture [TODO]

0 commit comments

Comments
 (0)