diff options
Diffstat (limited to 'Hutch/App/ThemeManager.swift')
| -rw-r--r-- | Hutch/App/ThemeManager.swift | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/Hutch/App/ThemeManager.swift b/Hutch/App/ThemeManager.swift index ee74921..af54094 100644 --- a/Hutch/App/ThemeManager.swift +++ b/Hutch/App/ThemeManager.swift @@ -6,6 +6,7 @@ enum AppTheme: String, CaseIterable, Identifiable { case system case light case dark + case amoled var id: String { rawValue } @@ -14,6 +15,7 @@ enum AppTheme: String, CaseIterable, Identifiable { case .system: "System" case .light: "Light" case .dark: "Dark" + case .amoled: "AMOLED" } } @@ -22,6 +24,7 @@ enum AppTheme: String, CaseIterable, Identifiable { case .system: nil case .light: .light case .dark: .dark + case .amoled: .dark } } } @@ -46,25 +49,51 @@ private struct DisplayDensityKey: EnvironmentKey { static let defaultValue: DisplayDensity = .standard } +private struct IsAMOLEDThemeKey: EnvironmentKey { + static let defaultValue: Bool = false +} + extension EnvironmentValues { var displayDensity: DisplayDensity { get { self[DisplayDensityKey.self] } set { self[DisplayDensityKey.self] = newValue } } + + var isAMOLEDTheme: Bool { + get { self[IsAMOLEDThemeKey.self] } + set { self[IsAMOLEDThemeKey.self] = newValue } + } } // MARK: - Themed List Modifier -/// Combined modifier for List/Form that applies compact section spacing. +/// Combined modifier for List/Form that applies compact section spacing and AMOLED black backgrounds. /// Apply once per List or Form. struct ThemedListStyle: ViewModifier { @Environment(\.displayDensity) private var density + @Environment(\.isAMOLEDTheme) private var isAMOLED func body(content: Content) -> some View { content .listSectionSpacing(density == .compact ? .compact : .default) .contentMargins(.vertical, density == .compact ? 2 : 8, for: .scrollContent) .controlSize(density == .compact ? .small : .regular) + .modifier(AMOLEDListBackground(isAMOLED: isAMOLED)) + } +} + +/// Hides the default grouped list background and replaces it with true black for OLED screens. +private struct AMOLEDListBackground: ViewModifier { + let isAMOLED: Bool + + func body(content: Content) -> some View { + if isAMOLED { + content + .scrollContentBackground(.hidden) + .background(Color.black) + } else { + content + } } } @@ -74,3 +103,21 @@ extension View { modifier(ThemedListStyle()) } } + +// MARK: - Themed Row Modifier + +struct ThemedRowStyle: ViewModifier { + @Environment(\.isAMOLEDTheme) private var isAMOLED + + func body(content: Content) -> some View { + content + .listRowBackground(isAMOLED ? Color.black : nil) + } +} + +extension View { + /// Apply to each row view inside a List or Form section to get a true-black background in AMOLED mode. + func themedRow() -> some View { + modifier(ThemedRowStyle()) + } +} |
