From f56d854acca12431ca6d4d8f62586046820316cf Mon Sep 17 00:00:00 2001 From: Trey T Date: Sat, 18 Apr 2026 19:11:15 -0500 Subject: [PATCH] P0.3: add iOS @Environment(\.dataManager) key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduces DataManagerEnvironmentKey + EnvironmentValues.dataManager so SwiftUI views can resolve DataManagerObservable via @Environment, mirroring Compose's LocalDataManager ambient on the Kotlin side. No view migrations yet — views continue to read DataManagerObservable.shared directly. The actual screen-level substitution (fake DataManager for parity-gallery / tests / previews) lands in P1 when ViewModels gain an optional init param that accepts the environment-resolved observable. For this commit we only need the key so P1 can wire against it. Note: the iosSimulator Kotlin compile is broken at baseline (bb4cbd5) with pre-existing "Unresolved reference 'testTagsAsResourceId'" errors across 20+ screen files — Android-only semantics API imported in commonMain. Swift-parse of the new file succeeds. Verified by checking out bb4cbd5 and rerunning ./gradlew :composeApp:compileKotlinIosSimulatorArm64. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Environment/DataManagerEnvironment.swift | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 iosApp/iosApp/Environment/DataManagerEnvironment.swift diff --git a/iosApp/iosApp/Environment/DataManagerEnvironment.swift b/iosApp/iosApp/Environment/DataManagerEnvironment.swift new file mode 100644 index 0000000..2590309 --- /dev/null +++ b/iosApp/iosApp/Environment/DataManagerEnvironment.swift @@ -0,0 +1,31 @@ +import SwiftUI +import ComposeApp + +/// SwiftUI `@Environment` mirror of Compose's `LocalDataManager` ambient. +/// +/// Production views resolve `@Environment(\.dataManager)` to +/// `DataManagerObservable.shared` — the existing Swift-side mirror of the +/// shared Kotlin `DataManager` singleton. Tests, previews, and the +/// parity-gallery override via: +/// +/// ```swift +/// MyView() +/// .environment(\.dataManager, FakeDataManagerObservable()) +/// ``` +/// +/// This key is intentionally introduced without migrating any SwiftUI +/// screens yet. Views continue to access `DataManagerObservable.shared` +/// directly; the actual view-level migration lands when parity-gallery +/// fixtures arrive (P1), at which point ViewModels will gain an optional +/// init param that accepts a `DataManagerObservable` resolved from this +/// environment key. +struct DataManagerEnvironmentKey: EnvironmentKey { + static let defaultValue: DataManagerObservable = DataManagerObservable.shared +} + +extension EnvironmentValues { + var dataManager: DataManagerObservable { + get { self[DataManagerEnvironmentKey.self] } + set { self[DataManagerEnvironmentKey.self] = newValue } + } +}