krz/moonrise

Night-sky companion for iPhone, Apple Watch and Vision Pro: what's up tonight, the Moon, planets, launches and missions, and a Library of the solar system. SwiftUI app with a Cloudflare Workers backend. astronomy cloudflare-workers ios night-sky space swiftui visionos watchos

App/Sources/Dimmed.swift

04b2b1d914788057bcd20945b876847386eb8f65
moonrise/App/Sources/Dimmed.swift history · blame · raw

21 lines · 723 bytes

3 symbols in this file
 1import SwiftUI
 2
 3extension EnvironmentValues {
 4    /// True while the Sky tab draws in night mode; dimmed text stays above 90% so red text keeps AA contrast.
 5    @Entry var nightMode = false
 6}
 7
 8/// Secondary text: dimmed by `opacity`, but never below 90% in night mode and not at all with Increase Contrast.
 9struct Dimmed: ViewModifier {
10    var opacity: Double
11    @Environment(\.colorSchemeContrast) private var contrast
12    @Environment(\.nightMode) private var night
13
14    func body(content: Content) -> some View {
15        content.opacity(contrast == .increased ? 1 : night ? max(opacity, 0.9) : opacity)
16    }
17}
18
19extension View {
20    func dimmed(_ opacity: Double) -> some View { modifier(Dimmed(opacity: opacity)) }
21}