Files

83 lines
3.1 KiB
Swift

// SplashView.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import SwiftUI
/// Animated launch splash shown over the app on cold start.
///
/// The native launch screen (`UILaunchScreen` → `LaunchBackground`) paints an instant dark
/// backdrop with no visible jump; this view then fades and scales the ShoeGaze pedal logo in,
/// holds briefly, and fades the whole overlay away to reveal ``ShoeGazeBuilderView``. Colors match
/// the app background so the hand-off is seamless. Respects Reduce Motion by skipping the scale.
struct SplashView: View {
/// Background matching the builder's app background (`0.08, 0.07, 0.06`).
private static let backgroundColor: Color = Color(red: 0.08, green: 0.07, blue: 0.06)
private static let logoSize: CGFloat = 200
private static let logoCornerRadius: CGFloat = 44
private static let logoStartScale: CGFloat = 0.86
private static let wordmarkKerning: CGFloat = 4
private static let logoFadeInDuration: Double = 0.55
private static let wordmarkFadeInDelay: Double = 0.30
private static let wordmarkFadeInDuration: Double = 0.45
private static let holdDuration: Double = 0.85
private static let fadeOutDuration: Double = 0.45
@Environment(\.accessibilityReduceMotion) private var reduceMotion
/// Set false to fade the overlay out; parent removes it when the fade completes.
@Binding var isActive: Bool
@State private var logoOpacity: Double = 0
@State private var logoScale: CGFloat = SplashView.logoStartScale
@State private var wordmarkOpacity: Double = 0
var body: some View {
ZStack {
SplashView.backgroundColor
.ignoresSafeArea()
VStack(spacing: 22) {
Image("SplashLogo")
.resizable()
.scaledToFit()
.frame(width: SplashView.logoSize, height: SplashView.logoSize)
.clipShape(RoundedRectangle(cornerRadius: SplashView.logoCornerRadius,
style: .continuous))
.opacity(logoOpacity)
.scaleEffect(logoScale)
Text("ShoeGaze")
.font(.system(size: 34, weight: .semibold, design: .rounded))
.kerning(SplashView.wordmarkKerning)
.foregroundStyle(.white)
.opacity(wordmarkOpacity)
}
}
.onAppear { runSequence() }
}
private func runSequence() {
withAnimation(.easeOut(duration: SplashView.logoFadeInDuration)) {
logoOpacity = 1
if !reduceMotion { logoScale = 1 }
}
withAnimation(.easeOut(duration: SplashView.wordmarkFadeInDuration)
.delay(SplashView.wordmarkFadeInDelay)) {
wordmarkOpacity = 1
}
let holdUntil: Double = SplashView.logoFadeInDuration + SplashView.holdDuration
DispatchQueue.main.asyncAfter(deadline: .now() + holdUntil) {
withAnimation(.easeIn(duration: SplashView.fadeOutDuration)) {
isActive = false
}
}
}
}