OIMbackground.swift (3843B)
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 import taler_swift 10 11 public let OIMBACKDARK = "tara-meinczinger-G_yCplAsnB4-unsplash" 12 public let OIMBACKLIGHT = "andrey-haimin-VFUTPASjhB8-unsplash" 13 14 // MARK: - 15 struct OIMamountV: View { 16 let amount: Amount? 17 let currencyName: String 18 let factor: Int // workaround because TEST has no large denominations, so we multiply with 100 19 let mayChangeSpeed: Bool 20 21 @State private var color = Color.accentColor 22 23 init(amount: Amount?, currencyName: String, factor: Int, mayChangeSpeed: Bool = true) { 24 self.amount = amount 25 self.currencyName = currencyName 26 self.factor = factor 27 self.mayChangeSpeed = mayChangeSpeed 28 } 29 30 func updateColor() { 31 #if DEBUG 32 color = debugAnimations ? .orange 33 : fastAnimations ? .accentColor 34 : .red 35 #else 36 color = fastAnimations ? .accentColor 37 : WalletColors().confirm 38 #endif 39 } 40 41 var body: some View { 42 if let amount { 43 if let amount2 = try? amount * UInt32(factor) { // workaround for CFA, HUF, JPY 44 // print(amount2.readableDescription) 45 AmountV(currencyName, amount: amount2, isNegative: nil) 46 .ignoresSafeArea(edges: .top) 47 .foregroundColor(color) 48 .task { 49 updateColor() 50 } 51 #if DEBUG 52 .onTapGesture(count: 2) { 53 if mayChangeSpeed { 54 if debugAnimations { 55 debugAnimations = false 56 fastAnimations = true 57 } else { 58 debugAnimations = true 59 } 60 updateColor() 61 } 62 } 63 #endif 64 .onTapGesture(count: 1) { 65 if mayChangeSpeed { 66 #if DEBUG 67 if debugAnimations { 68 debugAnimations = false 69 fastAnimations = false 70 } else { 71 fastAnimations.toggle() 72 } 73 #else 74 fastAnimations.toggle() 75 #endif 76 updateColor() 77 } 78 } 79 } 80 } 81 } 82 } 83 // MARK: - 84 // shows a ZStack with backImage, and content on top 85 struct OIMbackground<Content: View>: View { 86 var content: () -> Content 87 88 @Environment(\.colorScheme) private var colorScheme 89 90 var body: some View { 91 let background = colorScheme == .dark ? OIMBACKDARK 92 : OIMBACKLIGHT 93 let backImage = Image(background) 94 .resizable() 95 let zStack = ZStack(alignment: .top) { 96 backImage 97 .ignoresSafeArea(edges: .all) 98 .frame(maxWidth: .infinity, maxHeight: .infinity) 99 content() 100 } 101 if #available(iOS 16.4, *) { 102 zStack 103 .toolbar(.hidden, for: .navigationBar, .tabBar) 104 .scrollBounceBehavior(.basedOnSize, axes: .horizontal) 105 } else { // Fallback on earlier versions 106 zStack 107 // .navigationBarTitle("") // must set the title... 108 .navigationBarHidden(true) // before you can hide the navigation bar 109 // .tabBarHidden(true) // unfortunately this call doesn't exist 110 } 111 } 112 } 113 // MARK: - 114 //#Preview { 115 // OIMbackground() 116 //}