Skip to content

Commit

Permalink
Update PreferenceBridge
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Oct 20, 2024
1 parent a709674 commit cc69107
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
28 changes: 18 additions & 10 deletions Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
//
// PreferenceBridge.swift
// OpenSwiftUI
// OpenSwiftUICore
//
// Audited for RELEASE_2021
// Status: Complete
// ID: A9FAE381E99529D5274BA37A9BC9B074
// Audited for RELEASE_2024
// Status: TO BE AUDITED
// ID: A9FAE381E99529D5274BA37A9BC9B074 (RELEASE_2021)
// ID: DF57A19C61B44C613EB77C1D47FC679A (RELEASE_2024)

internal import OpenGraphShims

package final class PreferenceBridge {
unowned let viewGraph: ViewGraph
weak var viewGraph: ViewGraph?
var isValid: Bool = true

Check warning on line 14 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L14

Added line #L14 was not covered by tests
private(set) var children: [Unmanaged<ViewGraph>] = []
var requestedPreferences = PreferenceKeys()
var bridgedViewInputs = PropertyList()
Expand All @@ -23,9 +25,15 @@ package final class PreferenceBridge {
}

init() {
viewGraph = GraphHost.currentHost as! ViewGraph
viewGraph = ViewGraph.current

Check warning on line 28 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L28

Added line #L28 was not covered by tests
}

deinit {
if isValid { invalidate() }

Check warning on line 32 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L31-L32

Added lines #L31 - L32 were not covered by tests
}

// FIXME: TO BE AUDITED

#if canImport(Darwin) // FIXME: See #39
func addValue(_ value: AnyAttribute, for keyType: AnyPreferenceKey.Type) {
struct AddValue: PreferenceKeyVisitor {
Expand All @@ -48,7 +56,7 @@ package final class PreferenceBridge {
}
var visitor = AddValue(combiner: combiner, value: value)
keyType.visitKey(&visitor)
viewGraph.graphInvalidation(from: value)
viewGraph?.graphInvalidation(from: value)

Check warning on line 59 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L59

Added line #L59 was not covered by tests
}

func removeValue(_ value: AnyAttribute, for keyType: AnyPreferenceKey.Type, isInvalidating: Bool) {
Expand Down Expand Up @@ -78,7 +86,7 @@ package final class PreferenceBridge {
var visitor = RemoveValue(combiner: combiner, value: value)
keyType.visitKey(&visitor)
if visitor.changed {
viewGraph.graphInvalidation(from: isInvalidating ? nil : value)
viewGraph?.graphInvalidation(from: isInvalidating ? nil : value)

Check warning on line 89 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L89

Added line #L89 was not covered by tests
}
}

Expand All @@ -92,7 +100,7 @@ package final class PreferenceBridge {
) { combiner in
combiner.addChild(keys: keys, values: values)
}
viewGraph.graphInvalidation(from: combiner.identifier)
viewGraph?.graphInvalidation(from: combiner.identifier)

Check warning on line 103 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L103

Added line #L103 was not covered by tests
}

func removeHostValue(for keys: Attribute<PreferenceKeys>, isInvalidating: Bool) {
Expand All @@ -112,7 +120,7 @@ package final class PreferenceBridge {
hasRemoved = true
}
if hasRemoved {
viewGraph.graphInvalidation(from: isInvalidating ? nil : keys.identifier)
viewGraph?.graphInvalidation(from: isInvalidating ? nil : keys.identifier)

Check warning on line 123 in Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift#L123

Added line #L123 was not covered by tests
}
}

Expand Down
20 changes: 9 additions & 11 deletions Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ extension ViewRendererHost {
fatalError("TODO")

Check warning on line 103 in Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift#L102-L103

Added lines #L102 - L103 were not covered by tests
}

package func didRender() {
fatalError("TODO")
}
package func didRender() {}

Check warning on line 106 in Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift#L106

Added line #L106 was not covered by tests

@_spi(ForOpenSwiftUIOnly)
public func preferencesDidChange() {
Expand Down Expand Up @@ -199,8 +197,8 @@ extension ViewRendererHost {
fatalError("TODO")

Check warning on line 197 in Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift#L196-L197

Added lines #L196 - L197 were not covered by tests
}
package var centersRootView: Bool {
get { fatalError("TODO") }
set { fatalError("TODO") }
get { viewGraph.centersRootView }
set { viewGraph.centersRootView = newValue }

Check warning on line 201 in Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift#L200-L201

Added lines #L200 - L201 were not covered by tests
}

// package var responderNode: ResponderNode? {
Expand All @@ -212,12 +210,12 @@ extension ViewRendererHost {
}
private var enclosingHosts: [ViewRendererHost] { fatalError("TODO") }
package func performExternalUpdate(_ update: () -> Void) { fatalError("TODO") }
package func updateFocusedItem() { fatalError("TODO") }
package func updateFocusedValues() { fatalError("TODO") }
package func updateFocusStore() { fatalError("TODO") }
package func updateAccessibilityFocus() { fatalError("TODO") }
package func updateAccessibilityFocusStore() { fatalError("TODO") }
package func updateAccessibilityEnvironment() { fatalError("TODO") }
package func updateFocusedItem() {}
package func updateFocusedValues() {}
package func updateFocusStore() {}
package func updateAccessibilityFocus() {}
package func updateAccessibilityFocusStore() {}
package func updateAccessibilityEnvironment() {}

Check warning on line 218 in Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift#L211-L218

Added lines #L211 - L218 were not covered by tests
}

// MARK: - ViewRendererHost + Gesture [TODO]
Expand Down

0 comments on commit cc69107

Please sign in to comment.