Skip to content

Commit

Permalink
Fix Linux build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Apr 1, 2024
1 parent ee5fdc5 commit e69299e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Sources/OpenSwiftUI/Core/View/ViewGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ final class ViewGraph: GraphHost {
// FIXME: TO BE CONFIRMED
set { setPreferenceBridge(to: newValue, isInvalidating: newValue == nil) }
}
#if canImport(Darwin) // FIXME: See #39
var bridgedPreferences: [(AnyPreferenceKey.Type, OGAttribute)] = []
#endif
// TODO

init<Body: View>(rootViewType: Body.Type, requestedOutputs: Outputs) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/OpenSwiftUI/Data/Preference/PreferenceBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ final class PreferenceBridge {
init() {
viewGraph = GraphHost.currentHost as! ViewGraph
}


#if canImport(Darwin) // FIXME: See #39
func addValue(_ value: OGAttribute, for keyType: AnyPreferenceKey.Type) {
struct AddValue: PreferenceKeyVisitor {
var combiner: OGAttribute
Expand Down Expand Up @@ -191,6 +192,7 @@ final class PreferenceBridge {
}
}
}
#endif
}

private struct MergePreferenceKeys: Rule, AsyncAttribute {
Expand Down
2 changes: 2 additions & 0 deletions Sources/OpenSwiftUI/Data/Preference/PreferencesCombiner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct HostPreferencesCombiner: Rule, AsyncAttribute {
@WeakAttribute var values: PreferenceList?
}

#if canImport(Darwin) // FIXME: See #39
mutating func addChild(keys: Attribute<PreferenceKeys>, values: Attribute<PreferenceList>) {
let weakKeys = OGWeakAttribute(keys.identifier)
let weakValues = OGWeakAttribute(values.identifier)
Expand All @@ -52,6 +53,7 @@ struct HostPreferencesCombiner: Rule, AsyncAttribute {
children.append(child)
}
}
#endif

private struct CombineValues: PreferenceKeyVisitor {
var children: [Child]
Expand Down
21 changes: 15 additions & 6 deletions Sources/OpenSwiftUI/Data/Preference/PreferencesOutputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ internal import OpenGraphShims
struct PreferencesOutputs {
private var preferences: [KeyValue] = []
private var debugProperties: _ViewDebug.Properties = []
func contains<Key: PreferenceKey>(_ key: Key.Type) -> Bool {

func contains<Key: PreferenceKey>(_: Key.Type) -> Bool {
contains(_AnyPreferenceKey<Key>.self)
}

func contains(_ key: AnyPreferenceKey.Type) -> Bool {
preferences.contains { $0.key == key }
}

subscript<Key: PreferenceKey>(_ keyType: Key.Type) -> Attribute<Key.Value>? {

#if canImport(Darwin) // FIXME: See #39
subscript<Key: PreferenceKey>(_: Key.Type) -> Attribute<Key.Value>? {
get {
let value = self[anyKey: _AnyPreferenceKey<Key>.self]
return value.map { Attribute(identifier: $0) }
Expand All @@ -29,7 +30,7 @@ struct PreferencesOutputs {
self[anyKey: _AnyPreferenceKey<Key>.self] = newValue?.identifier
}
}

subscript(anyKey keyType: AnyPreferenceKey.Type) -> OGAttribute? {
get { preferences.first { $0.key == keyType }?.value }
set {
Expand All @@ -51,11 +52,19 @@ struct PreferencesOutputs {
}
}
}
#else
subscript<Key: PreferenceKey>(_: Key.Type) -> Attribute<Key.Value>? {
get { fatalError("See #39") }
set { fatalError("See #39") }
}
#endif
}

extension PreferencesOutputs {
private struct KeyValue {
var key: AnyPreferenceKey.Type
#if canImport(Darwin) // FIXME: See #39
var value: OGAttribute
#endif
}
}

0 comments on commit e69299e

Please sign in to comment.