fix(settings): 修复主题切换后窗口与表单深浅混用

This commit is contained in:
2026-11-03 13:20:05 +08:00
parent 92e8187038
commit d81825ba8c
4 changed files with 17 additions and 8 deletions
@@ -46,7 +46,7 @@ struct AppearanceSettingsView: View {
}
.onChange(of: selection) { _, _ in colorPicker.close() }
.frame(minWidth: 720, idealWidth: 780, minHeight: 460, idealHeight: 540)
.modifier(AppearanceStyle(preferences: preferences))
.modifier(AppearanceStyle(preferences: preferences, refreshContentOnChange: true))
}
private var selectedPage: SettingsPage { selection ?? .appearance }
@@ -164,13 +164,8 @@ private struct LiquidAppearancePicker: View {
HStack(spacing: 4) {
ForEach(AppAppearance.allCases) { appearance in
Button {
if reduceMotion {
selection = appearance
} else {
withAnimation(.smooth(duration: 0.24)) {
selection = appearance
}
}
// Theme changes must not animate the native split view / Form hierarchy.
selection = appearance
} label: {
Label(appearance.title, systemImage: appearance.symbol)
.labelStyle(.titleAndIcon)
@@ -196,6 +191,7 @@ private struct LiquidAppearancePicker: View {
.padding(4)
.glassEffect(.regular, in: .capsule)
}
.animation(reduceMotion ? nil : .smooth(duration: 0.24), value: selection)
.accessibilityElement(children: .contain)
.accessibilityLabel(Text("appearance.title"))
}
+4
View File
@@ -33,11 +33,15 @@ extension AppearancePreferences {
struct AppearanceStyle: ViewModifier {
let preferences: AppearancePreferences
var refreshContentOnChange = false
@State private var system = SystemAppearanceObserver()
private var resolved: AppAppearance { preferences.appearance.resolved(systemIsDark: system.isDark) }
private var scheme: ColorScheme { resolved == .dark ? .dark : .light }
func body(content: Content) -> some View {
content
// Settings split-view hosts can retain their previous native appearance.
// Keep state in the owning view, but replace the hosted subtree on a resolved theme change.
.id(refreshContentOnChange ? resolved : nil)
.background(WindowAppearanceBridge(choice: resolved))
.preferredColorScheme(scheme)
.environment(\.colorScheme, scheme)