taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

LaunchAnimationView.swift (2476B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-25 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                rotationEnabled: $rotationEnabled)
     19                 .accessibilityLabel(Text("Progress indicator", comment: "a11y"))
     20         }
     21     }
     22 }
     23 // MARK: -
     24 struct RotatingTaler: View {
     25     let size: CGFloat
     26     let progress: Bool
     27     let once: Bool
     28 
     29     @Binding var rotationEnabled: Bool
     30     @State private var rotationDirection = false
     31 
     32     private let animationTimer = Timer
     33         .publish(every: 1.5, on: .current, in: .common)
     34         .autoconnect()
     35 
     36     var body: some View {
     37         let image = Image(TALER_LOGO)
     38             .resizable()
     39             .scaledToFit()
     40             .frame(width: size, height: size)
     41             .padding(10)
     42             .accessibilityLabel(progress ? Text("In progress", comment: "a11y")
     43                                          : Text("Taler Logo", comment: "a11y"))       // decorative logo - with button function
     44             .rotationEffect(rotationDirection ? Angle(degrees: 0) : Angle(degrees: once ? 900 : 720))
     45             .onReceive(animationTimer) { timerValue in
     46 //                print("Timer: \(timerValue), rotationDirection: \(rotationDirection)")
     47                 if rotationEnabled {
     48                     if !once {
     49                         withAnimation(.easeInOut(duration: 1.5)) {
     50                             rotationDirection.toggle()
     51                         }
     52                     }
     53                 }
     54             }
     55             .task {
     56                 if once {
     57                     withAnimation(.easeInOut(duration: 2.0)) {
     58                         rotationDirection.toggle()
     59                     }
     60                 }
     61             }
     62         if #available(iOS 26.0, *) {
     63             image
     64                 .glassEffect(.clear)
     65         } else {
     66             image
     67                 .background {
     68                     Capsule()
     69                         .fill(Color(.systemGray6).opacity(0.7))
     70                 }
     71         }
     72     }
     73 }
     74 // MARK: -
     75 struct LaunchAnimationView_Previews: PreviewProvider {
     76     static var previews: some View {
     77         LaunchAnimationView()
     78     }
     79 }