taler-ios

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

LaunchAnimationView.swift (1722B)


      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(.systemGray6).ignoresSafeArea()
     15             RotatingTaler(size: (350 < UIScreen.screenWidth) ? 200 : 250,
     16                       progress: true,
     17                rotationEnabled: $rotationEnabled)
     18                 .accessibilityLabel(Text("Progress indicator", comment: "a11y"))
     19         }
     20     }
     21 }
     22 // MARK: -
     23 struct RotatingTaler: View {
     24     let size: CGFloat
     25     let progress: Bool
     26 
     27     @Binding var rotationEnabled: Bool
     28     @State private var rotationDirection = false
     29 
     30     private let animationTimer = Timer
     31         .publish(every: 1.6, on: .current, in: .common)
     32         .autoconnect()
     33 
     34     var body: some View {
     35         Image(TALER_LOGO)
     36             .resizable()
     37             .scaledToFit()
     38             .frame(width: size, height: size)
     39             .rotationEffect(rotationDirection ? Angle(degrees: 0) : Angle(degrees: 900))
     40             .accessibilityLabel(progress ? Text("In progress", comment: "a11y")
     41                                          : Text("Taler Logo", comment: "a11y"))       // decorative logo - with button function
     42             .onReceive(animationTimer) { timerValue in
     43                 if rotationEnabled {
     44                     withAnimation(.easeInOut(duration: 1.9)) {
     45                         rotationDirection.toggle()
     46                     }
     47                 }
     48             }
     49     }
     50 }
     51 // MARK: -
     52 struct LaunchAnimationView_Previews: PreviewProvider {
     53     static var previews: some View {
     54         LaunchAnimationView()
     55     }
     56 }