Repository Public License
1// ORIX Alarm2// File: App/Features/Nightstand/SunriseSkyView.swift3// Description: Sunrise simulation backdrop: near-black night, then deep blue, violet, ember and warm gold with a glow rising from the bottom.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SwiftUI89/// Full-screen sky for a sunrise progress of 0 (night) ... 1 (full warm light).10///11/// At 0 the screen is almost pure black: on an OLED panel that means nearly no light in the bedroom and no static12/// bright pixels. Colours come from `Theme.sky`; towards the end a warm wash covers the remaining blue so the final13/// light is gold and peach rather than daylight blue.14struct SunriseSkyView: View {15 var progress: Double16 /// Seconds over which a change of `progress` is animated (the caller's update interval).17 var updateInterval: TimeInterval = 118 @Environment(\.accessibilityReduceMotion) private var reduceMotion1920 static func smooth(_ x: Double) -> Double { let t = min(max(x, 0), 1); return t * t * (3 - 2 * t) }2122 var body: some View {23 let p = min(max(progress, 0), 1)24 GeometryReader { geo in25 let size = geo.size26 ZStack {27 Color.black28 LinearGradient(colors: Theme.sky(p), startPoint: .top, endPoint: .bottom)29 .opacity(0.10 + 0.90 * Self.smooth(p / 0.22))30 // Horizon glow: a wide, soft dome of light that climbs and widens.31 RadialGradient(colors: [glowCore(p).opacity(0.95 * Self.smooth(p / 0.3)), glowCore(p).opacity(0.35 * Self.smooth(p / 0.4)), .clear],32 center: UnitPoint(x: 0.5, y: 1.18 - 0.42 * p), startRadius: 0, endRadius: size.height * (0.28 + 0.62 * p))33 // The sun itself: a blurred disc that clears the bottom edge during the gentle wake.34 Circle()35 .fill(RadialGradient(colors: [Theme.peach, Theme.gold, Theme.sunrise.opacity(0)], center: .center, startRadius: 0, endRadius: sunRadius(size)))36 .frame(width: sunRadius(size) * 2, height: sunRadius(size) * 2)37 .blur(radius: 14)38 .position(x: size.width / 2, y: size.height * (1.16 - 0.44 * p))39 .opacity(Self.smooth((p - 0.12) / 0.35))40 // Low-blue finish: a warm wash over the upper sky.41 LinearGradient(colors: [Theme.gold.opacity(0.62), Theme.peach.opacity(0.30)], startPoint: .top, endPoint: .bottom)42 .opacity(Self.smooth((p - 0.62) / 0.38))43 }44 .animation(reduceMotion ? nil : .linear(duration: updateInterval), value: p)45 }46 .ignoresSafeArea()47 .accessibilityHidden(true)48 }4950 private func sunRadius(_ size: CGSize) -> CGFloat { size.width * 0.34 }5152 private func glowCore(_ p: Double) -> Color {53 p < 0.5 ? Theme.ember.mix(with: Theme.sunrise, by: p * 2) : Theme.sunrise.mix(with: Theme.gold, by: (p - 0.5) * 2)54 }55}56