LaunchAnimationView.swift (2566B)
1 /* 2 * This file is part of GNU Taler, ©2022-26 Taler Systems S.A. 3 * See LICENSE.md 4 */ 5 /** 6 * @author Marc Stibane 7 */ 8 import SwiftUI 9 10 struct LaunchAnimationView: View { 11 @State private var rotationEnabled = true 12 var body: some View { 13 ZStack { 14 Color(.systemGray3).ignoresSafeArea() 15 RotatingTaler(size: (350 < UIScreen.screenWidth) ? 200 : 250, 16 progress: true, 17 once: true, 18 background: nil, 19 rotationEnabled: $rotationEnabled) 20 .accessibilityLabel(Text("Progress indicator", comment: "a11y")) 21 } 22 } 23 } 24 // MARK: - 25 struct RotatingTaler: View { 26 let size: CGFloat 27 let progress: Bool 28 let once: Bool 29 let background: Color? 30 31 @Binding var rotationEnabled: Bool 32 @State private var rotationDirection = false 33 34 private let animationTimer = Timer 35 .publish(every: 1.5, on: .current, in: .common) 36 .autoconnect() 37 38 var body: some View { 39 let image = Image(TALER_LOGO) 40 .resizable() 41 .scaledToFit() 42 .frame(width: size, height: size) 43 .padding(10) 44 .accessibilityLabel(progress ? Text("In progress", comment: "a11y") 45 : Text("Taler Logo", comment: "a11y")) // decorative logo - with button function 46 .rotationEffect(rotationDirection ? Angle(degrees: 0) : Angle(degrees: once ? 900 : 720)) 47 .onReceive(animationTimer) { timerValue in 48 // print("Timer: \(timerValue), rotationDirection: \(rotationDirection)") 49 if rotationEnabled { 50 if !once { 51 withAnimation(.easeInOut(duration: 1.5)) { 52 rotationDirection.toggle() 53 } 54 } 55 } 56 } 57 .task { 58 if once { 59 withAnimation(.easeInOut(duration: 2.0)) { 60 rotationDirection.toggle() 61 } 62 } 63 } 64 // if #available(iOS 26.0, *) { 65 // image 66 // .glassEffect(.clear) 67 // } else { 68 image 69 .background { 70 Capsule() 71 .fill((background ?? Color(.systemGray6)).opacity(0.3)) 72 } 73 // } 74 } 75 } 76 // MARK: - 77 struct LaunchAnimationView_Previews: PreviewProvider { 78 static var previews: some View { 79 LaunchAnimationView() 80 } 81 }