Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Sources/OpenSwiftUI/App/App/AppGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,32 @@ package final class AppGraph: GraphHost {

// MARK: - Override Methods

override package func instantiateOutputs() {
data.updateSeed &+= 1
let outputs = rootSubgraph.apply {
var inputs = _SceneInputs(
base: graphInputs,
preferences: .init(hostKeys: data.$hostPreferenceKeys)
)
inputs.base.environment = Attribute(
RootEnvironment(
environment: graphInputs.environment,
phase: $rootScenePhase,
sceneKeyboardShorts: $sceneKeyboardShortcuts
)
)
inputs.preferences.add(HostPreferencesKey.self)
inputs.preferences.add(SceneList.Key.self)
inputs.preferences.add(CommandsList.Key.self)
inputs.base.focusedValues = $focusedValues
inputs.base.focusStore = $focusStore
return makeRootScene(inputs)
}
$rootSceneList = outputs.preferences.sceneList
$rootCommandsList = outputs.preferences.commandsList
hostPreferenceValues = WeakAttribute(outputs.preferences.hostPreferenceValues)
}

// MARK: - Profile related

func startProfilingIfNecessary() {
Expand Down Expand Up @@ -167,3 +193,15 @@ private struct AppBodyAccessor<Application>: BodyAccessor where Application: App
}
}
}

// MARK: - RootEnvironment

private struct RootEnvironment: Rule {
@Attribute var environment: EnvironmentValues
@Attribute var phase: ScenePhase
@Attribute var sceneKeyboardShorts: [SceneID: KeyboardShortcut]

var value: EnvironmentValues {
environment
}
}
1 change: 0 additions & 1 deletion Sources/OpenSwiftUI/App/Window/WindowGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ struct WindowSceneList<Attributes>: PrimitiveScene where Attributes: WindowScene
scene: _GraphValue<Self>,
inputs: _SceneInputs
) -> _SceneOutputs {
_openSwiftUIBaseClassAbstractMethod()
let configuration = scene[offset: { .of(&$0.configuration) }].value
var outputs = _SceneOutputs()
outputs.preferences
Expand Down
21 changes: 21 additions & 0 deletions Sources/OpenSwiftUI/Event/Focus/FocusStore.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import OpenAttributeGraphShims
@_spi(ForOpenSwiftUIOnly)
import OpenSwiftUICore

Expand Down Expand Up @@ -27,3 +28,23 @@ extension FocusStore {

}
}

struct FocusStoreInputKey: ViewInput {
static var defaultValue: OptionalAttribute<FocusStore> {
.init()
}
}

extension _ViewInputs {
var focusStore: Attribute<FocusStore>? {
get { base.focusStore }
set { base.focusStore = newValue }
}
}

extension _GraphInputs {
var focusStore: Attribute<FocusStore>? {
get { self[FocusStoreInputKey.self].attribute }
set { self[FocusStoreInputKey.self] = .init(newValue) }
}
}
14 changes: 14 additions & 0 deletions Sources/OpenSwiftUI/Event/Focus/FocusedValueKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,17 @@ struct FocusedValuesInputKey: ViewInput {
.init()
}
}

extension _ViewInputs {
var focusedValues: Attribute<FocusedValues>? {
get { base.focusedValues }
set { base.focusedValues = newValue }
}
}

extension _GraphInputs {
var focusedValues: Attribute<FocusedValues>? {
get { self[FocusedValuesInputKey.self].attribute }
set { self[FocusedValuesInputKey.self] = .init(newValue) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ package final class PreferenceBridge {
let combiner = Attribute(
HostPreferencesCombiner(
keys: inputs.preferences.hostKeys,
values: outputs[HostPreferencesKey.self]
values: outputs.hostPreferenceValues
)
)
outputs[HostPreferencesKey.self] = combiner
outputs.hostPreferenceValues = combiner
_hostPreferenceKeys = WeakAttribute(inputs.preferences.hostKeys)
_hostPreferencesCombiner = WeakAttribute(combiner)
} else {
Expand Down
9 changes: 9 additions & 0 deletions Sources/OpenSwiftUICore/Data/Preference/PreferenceKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Status: Complete
// ID: 3D8838A231BB2CC7FC00E7880D8B2FC4 (SwiftUICore)

package import OpenAttributeGraphShims

// MARK: - PreferenceKey

/// A named value produced by a view.
Expand Down Expand Up @@ -160,6 +162,13 @@ package struct HostPreferencesKey: PreferenceKey {
}
}

extension PreferencesOutputs {
package var hostPreferenceValues: Attribute<PreferenceValues>? {
get { self[HostPreferencesKey.self] }
set { self[HostPreferencesKey.self] = newValue }
}
}

// MARK: - HostPreferenceKey

@_spi(Private)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ extension PreferencesOutputs {
}
if K._isReadableByHost,
inputs.contains(HostPreferencesKey.self) {
self[HostPreferencesKey.self] = Attribute(
hostPreferenceValues = Attribute(
HostPreferencesTransform<K>(
transform: attribute ?? transform(),
keys: inputs.hostKeys,
childValues: .init(self[HostPreferencesKey.self]),
childValues: .init(hostPreferenceValues),
keyRequested: false,
wasEmpty: false,
delta: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ extension PreferencesOutputs {
}
if K._isReadableByHost,
inputs.contains(HostPreferencesKey.self) {
self[HostPreferencesKey.self] = Attribute(
hostPreferenceValues = Attribute(
HostPreferencesWriter<K>(
keyValue: attribute ?? value(),
keys: inputs.hostKeys,
childValues: .init(self[HostPreferencesKey.self]),
childValues: .init(hostPreferenceValues),
keyRequested: false,
wasEmpty: false,
delta: 0,
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ package final class ViewGraph: GraphHost {
if requestedOutputs.contains(.layout) {
_rootLayoutComputer = WeakAttribute(outputs.layoutComputer)
}
hostPreferenceValues = WeakAttribute(outputs.preferences[HostPreferencesKey.self])
hostPreferenceValues = WeakAttribute(outputs.preferences.hostPreferenceValues)
makePreferenceOutlets(outputs: outputs)
}

Expand Down
Loading