Files
honeyDueKMP/iosApp/iosApp/Environment/DataManagerEnvironment.swift
Trey T f56d854acc P0.3: add iOS @Environment(\.dataManager) key
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) <noreply@anthropic.com>
2026-04-18 19:11:15 -05:00

32 lines
1.2 KiB
Swift

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 }
}
}