Files
OSGKeyboard/OSGKeyboardShared/DesignSystem/ThemedRoot.swift
T
Zhongshu e0b92ff35a [P0-①] Theme follows system + keyboard background transparent
- Split Palette.dark / Palette.light into a ThemePalette struct
- Add EnvironmentKey<ThemePalette> + ThemedRoot<Content>
- Wrap OSGKeyboardApp root in ThemedRoot so main App follows system
- Remove 6 .preferredColorScheme(.dark) overrides from main App views
- KeyboardRootView drops its Palette.background fill, uses .background(Color.clear)
- Drop the unused 'background' computed property from KeyboardRootView
- Legacy 'Palette.xxx' static accessors still resolve to dark values,
  so 2000 lines of existing call sites stay untouched

xcodebuild iOS Simulator: SUCCEEDED
2026-06-18 10:38:23 +08:00

51 lines
1.3 KiB
Swift

// ThemedRoot.swift
// OSGKeyboard · Design System
//
// `ThemedRoot` injects the right `ThemePalette` for the current system
// colour scheme. Wrap the main App's root in this view to opt into
// light/dark following; the keyboard extension deliberately stays dark
// (Apple's custom keyboards always render dark) and does NOT use this.
import SwiftUI
public struct ThemedRoot<Content: View>: View {
@Environment(\.colorScheme) private var colorScheme
let content: () -> Content
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
public var body: some View {
content()
.environment(\.themePalette, colorScheme == .dark ? Palette.dark : Palette.light)
}
}
#if DEBUG
#Preview("ThemedRoot · Dark") {
ThemedRoot {
ZStack {
Palette.dark.background.ignoresSafeArea()
Text("Dark")
.foregroundStyle(Palette.dark.textPrimary)
.font(.title)
}
}
.preferredColorScheme(.dark)
}
#Preview("ThemedRoot · Light") {
ThemedRoot {
ZStack {
Palette.light.background.ignoresSafeArea()
Text("Light")
.foregroundStyle(Palette.light.textPrimary)
.font(.title)
}
}
.preferredColorScheme(.light)
}
#endif