|
| 1 | +// |
| 2 | +// LaunchScreenView.swift |
| 3 | +// EatHub |
| 4 | +// |
| 5 | +// Created by Даниил Дементьев on 29.03.2025. |
| 6 | +// |
| 7 | + |
| 8 | +import SwiftUI |
| 9 | + |
| 10 | +struct LaunchScreenView: View { |
| 11 | + @ObservedObject private var launchScreenStateManager: LaunchScreenStateManager |
| 12 | + |
| 13 | + @State private var firstAnimation = false |
| 14 | + @State private var secondAnimation = false |
| 15 | + @State private var startFadeoutAnimation = false |
| 16 | + |
| 17 | + init(dependencies: AppDependencies) { |
| 18 | + self._launchScreenStateManager = ObservedObject(wrappedValue: |
| 19 | + dependencies.launchScreenStateManager) |
| 20 | + } |
| 21 | + |
| 22 | + var body: some View { |
| 23 | + ZStack { |
| 24 | + backgroundColor |
| 25 | + image |
| 26 | + }.onReceive(animationTimer) { _ in |
| 27 | + updateAnimation() |
| 28 | + }.opacity(startFadeoutAnimation ? 0 : 1) |
| 29 | + } |
| 30 | + |
| 31 | + private var image: some View { |
| 32 | + Image(systemName: "fork.knife.circle.fill") |
| 33 | + .resizable() |
| 34 | + .scaledToFit() |
| 35 | + .frame(width: 120, height: 120) |
| 36 | + .foregroundStyle(.white) |
| 37 | + .rotationEffect(firstAnimation ? .degrees(0) : .degrees(360)) |
| 38 | + .scaleEffect(secondAnimation ? 0.1 : 1.0) |
| 39 | + .offset(y: secondAnimation ? 500 : 0) |
| 40 | + .shadow(color: .black.opacity(0.2), radius: 10, x: 0, y: 10) |
| 41 | + .animation(.easeInOut(duration: 1.3), value: firstAnimation) |
| 42 | + .animation(.easeIn(duration: 0.6), value: secondAnimation) |
| 43 | + } |
| 44 | + |
| 45 | + private var backgroundColor: some View { |
| 46 | + LinearGradient( |
| 47 | + colors: [Color.orange, Color.red], |
| 48 | + startPoint: .top, |
| 49 | + endPoint: .bottom |
| 50 | + ) |
| 51 | + .ignoresSafeArea() |
| 52 | + } |
| 53 | + |
| 54 | + private let animationTimer = Timer |
| 55 | + .publish(every: 1.5, on: .current, in: .common) |
| 56 | + .autoconnect() |
| 57 | + |
| 58 | + private func updateAnimation() { |
| 59 | + switch launchScreenStateManager.state { |
| 60 | + case .firstStep: |
| 61 | + withAnimation(.easeInOut(duration: 0.9)) { |
| 62 | + firstAnimation.toggle() |
| 63 | + } |
| 64 | + case .secondStep: |
| 65 | + if secondAnimation == false { |
| 66 | + withAnimation(.linear) { |
| 67 | + secondAnimation = true |
| 68 | + startFadeoutAnimation = true |
| 69 | + } |
| 70 | + } |
| 71 | + case .finished: |
| 72 | + break |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments