App/Sources/Dimmed.swift
21 lines · 723 bytes
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}