ed11a11329
6 review-driven small fixes to the P0 commit series (e0b92ff/e93bab5/2e2d8e3/013c498). No behavior changes, no new features, no push yet. Code: - RED-1: Remove empty init() from OSGKeyboardApp; @StateObject is initialized inline and the only thing init() did was print a DEBUG log. - RED-4: Re-add .preferredColorScheme(.dark) to the 3 keyboard extension #Preview blocks. Custom keyboards always render dark; the preview should match. - RED-6: ThemedRoot #Preview blocks now use the new EnvironmentKey (\.themePalette) via a private ThemedPreviewContent, instead of hard-coding Palette.dark / Palette.light. - BUG-5: ThemedRoot body now also fills the background with the active palette's background color (repeats the colorScheme ternary — accepted because body must be a single expression). Docs: - DOC-1: CHANGELOG [Unreleased] top note: this is a v0.1.0 → v0.1.1 polish, nothing removed, iOS 26 SpeechAnalyzer still 0.2.0. - DOC-2: README + README.zh.md Limitations: explicit note for iOS 26+ users in v0.1.1. Verified: xcodebuild Debug-iphonesimulator BUILD SUCCEEDED, 8/8 unit tests pass on iPhone 17 sim (iOS 26.3.1).
57 lines
1.4 KiB
Swift
57 lines
1.4 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)
|
|
.background(colorScheme == .dark ? Palette.dark.background : Palette.light.background)
|
|
}
|
|
}
|
|
|
|
#if DEBUG
|
|
#Preview("ThemedRoot · Dark") {
|
|
ThemedRoot {
|
|
ThemedPreviewContent(title: "Dark")
|
|
}
|
|
.preferredColorScheme(.dark)
|
|
}
|
|
|
|
#Preview("ThemedRoot · Light") {
|
|
ThemedRoot {
|
|
ThemedPreviewContent(title: "Light")
|
|
}
|
|
.preferredColorScheme(.light)
|
|
}
|
|
|
|
private struct ThemedPreviewContent: View {
|
|
@Environment(\.themePalette) private var palette
|
|
let title: String
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
palette.background.ignoresSafeArea()
|
|
Text(title)
|
|
.foregroundStyle(palette.textPrimary)
|
|
.font(.title)
|
|
}
|
|
}
|
|
}
|
|
#endif
|