taler-ios

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

Animations.swift (4566B)


      1 //  MIT License
      2 //  Copyright © SwiftUI-Lab
      3 //  https://swiftui-lab.com/matchedGeometryEffect-part2
      4 //
      5 //  Permission is hereby granted, free of charge, to any person obtaining a copy of this software
      6 //  and associated documentation files (the "Software"), to deal in the Software without restriction,
      7 //  including without limitation the rights to use, copy, modify, merge, publish, distribute,
      8 //  sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
      9 //  furnished to do so, subject to the following conditions:
     10 //
     11 //  The above copyright notice and this permission notice shall be included in all copies or
     12 //  substantial portions of the Software.
     13 //
     14 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
     15 //  BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     16 //  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
     17 //  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     18 //  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     19 //
     20 /**
     21  * @author Marc Stibane
     22  */
     23 import SwiftUI
     24 
     25 var fastAnimations = true
     26 #if DEBUG
     27 var debugAnimations = false
     28 #endif
     29 
     30 var flyDelay: Double {     // time
     31 #if DEBUG
     32     if debugAnimations { return 5.0 }
     33     //        return fastAnimations ? 5 : 1.0
     34 #endif
     35     return fastAnimations ? 0.4 : 0.8
     36 }
     37 
     38 var curveDelay: Double {
     39     flyDelay * 2 / 3
     40 }
     41 
     42 fileprivate
     43 let FAST: TimeInterval = 0.25
     44 fileprivate
     45 let SLOW: TimeInterval = 0.5
     46 
     47 extension Animation {
     48 #if DEBUG
     49     static var debug: Animation { .easeInOut(duration: 2.0) }
     50 #endif
     51 
     52     static var talerDelay0: TimeInterval {
     53         return fastAnimations ? 0.1 : 0.25
     54     }
     55 
     56     static var talerDuration0: TimeInterval {
     57 #if DEBUG
     58         if debugAnimations { return 2.0 }
     59 #endif
     60         return fastAnimations ? FAST : SLOW
     61     }
     62 
     63     static var talerDuration2: TimeInterval {
     64         return 0.2 + talerDuration0
     65     }
     66 
     67     static var springFast: Animation {
     68         .interactiveSpring(response: 0.6, dampingFraction: 0.6, blendDuration: FAST)
     69     }
     70     static var springFast2: Animation {
     71         .interactiveSpring(response: 0.3, dampingFraction: 0.3, blendDuration: FAST)
     72     }
     73     static var springSlow: Animation {
     74         .interactiveSpring(response: 0.9, dampingFraction: 0.75, blendDuration: SLOW)
     75     }
     76 
     77     static var easeIn1: Animation {
     78 #if DEBUG
     79         if debugAnimations { return .debug }
     80 #endif
     81         return .easeIn(duration: (fastAnimations ? FAST : SLOW))
     82     }
     83 
     84     static var easeOut1: Animation {
     85 #if DEBUG
     86         if debugAnimations { return .debug }
     87 #endif
     88         return .easeOut(duration: (fastAnimations ? FAST : SLOW))
     89     }
     90 
     91     static var easeInOut1: Animation {
     92 #if DEBUG
     93         if debugAnimations { return .debug }
     94 #endif
     95         return .easeInOut(duration: (fastAnimations ? FAST : SLOW))
     96     }
     97 
     98     static var move1: Animation {
     99 #if DEBUG
    100         if debugAnimations { return .debug }
    101 #endif
    102         return fastAnimations ? .springFast
    103                               : .springSlow
    104     }
    105 
    106     static var springDelay1: Animation {
    107 #if DEBUG
    108         if debugAnimations { return .debug }
    109 #endif
    110         return fastAnimations ? .springFast.delay(FAST)
    111                               : .springSlow.delay(SLOW)
    112     }
    113 
    114     static var easeOutDelay1: Animation {
    115         fastAnimations ? .easeOut1.delay(FAST)
    116                        : .easeOut1.delay(SLOW)
    117     }
    118 
    119     static var easeInOutDelay1: Animation {
    120         fastAnimations ? .easeInOut1.delay(FAST)
    121                        : .easeInOut1.delay(SLOW)
    122     }
    123     static var easeInOutDelay2: Animation {
    124         fastAnimations ? .easeInOut1.delay(FAST/2)
    125                        : .easeInOut1.delay(SLOW/2)
    126     }
    127 
    128     static var basic1: Animation {
    129 #if DEBUG
    130         if debugAnimations { return .debug }
    131 #endif
    132         /// The `default` animation is ``spring(response:dampingFraction:blendDuration:)``
    133         /// with:
    134         /// - `response` equal to `0.55`
    135         /// - `dampingFraction` equal to `1.0`
    136         /// - `blendDuration` equal to `0.0`
    137         ///
    138         /// Prior to iOS 17, macOS 14, tvOS 17, and watchOS 10, the `default` animation is ``easeInOut``.
    139         return fastAnimations ? .default
    140                               : .springSlow
    141     }
    142 
    143     static var basicFast: Animation {
    144 #if DEBUG
    145         if debugAnimations { return .debug }
    146 #endif
    147         return fastAnimations ? .springFast2
    148                               : .springFast
    149     }
    150 }