taler-ios

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

commit d25c0afde8d1afb3529da5de70254a394b6870d0
parent f4f05a6c6b05276bbf1b60b3280dbc6c707fc1dd
Author: Marc Stibane <marc@taler.net>
Date:   Sun, 13 Apr 2025 16:10:09 +0200

use tappedVal

Diffstat:
MTalerWallet1/Views/OIM/OIMView.swift | 28++++++++++++----------------
MTalerWallet1/Views/OIM/OIMcurrencyScroller.swift | 37++-----------------------------------
MTalerWallet1/Views/OIM/OIMlineViews.swift | 89++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
3 files changed, 73 insertions(+), 81 deletions(-)

diff --git a/TalerWallet1/Views/OIM/OIMView.swift b/TalerWallet1/Views/OIM/OIMView.swift @@ -65,7 +65,6 @@ struct OIMView: View { @State private var amountVal: UInt64 = 0 @State private var tappedVal: UInt64 = 0 - @State private var flying: UInt64 = 0 var body: some View { // let _ = Self._printChanges() @@ -87,10 +86,9 @@ struct OIMView: View { VStack { Spacer() OIMlineViews(stack: stack.push(), - amountVal: $amountVal, + amountVal: $amountVal, tappedVal: $tappedVal, - flying: $flying, - canEdit: false) + canEdit: false) Spacer() actions }//.border(.red) @@ -113,7 +111,6 @@ struct OIMPayView: View { @State private var amountVal: UInt64 = 0 @State private var tappedVal: UInt64 = 0 - @State private var flying: UInt64 = 0 var body: some View { // let _ = Self._printChanges() @@ -123,10 +120,9 @@ struct OIMPayView: View { VStack { Spacer() OIMlineViews(stack: stack.push(), - amountVal: $amountVal, + amountVal: $amountVal, tappedVal: $tappedVal, - flying: $flying, - canEdit: true) + canEdit: true) Spacer() }.border(.red) } @@ -154,7 +150,6 @@ struct OIMEditView: View { @State private var availableVal: UInt64 = 0 @State private var tappedVal: UInt64 = 0 - @State private var flying: UInt64 = 0 var isAvailable: UInt64 { if useAvailable { @@ -182,10 +177,9 @@ struct OIMEditView: View { VStack { // even though this is the only item in the ZStack Spacer() OIMlineViews(stack: stack.push(), - amountVal: $amountVal, + amountVal: $amountVal, tappedVal: $tappedVal, - flying: $flying, - canEdit: true) + canEdit: true) .zIndex(1) // make notes fly from topZ .onChange(of: amountVal) { newVal in let currencyStr = amount.currencyStr @@ -194,10 +188,12 @@ struct OIMEditView: View { } Spacer() OIMcurrencyScroller(stack: stack.push(), - availableVal: $availableVal, - amountVal: $amountVal, - tappedVal: $tappedVal, - flying: $flying) + availableVal: $availableVal, + tappedVal: $tappedVal) + .zIndex(2) // make notes fly from topZ + .clipped(antialiased: true) + .padding(.horizontal, 5) + .ignoresSafeArea(edges: .horizontal) .onChange(of: available) { newVal in availableVal = intValue(newVal) - intValue(amount) } diff --git a/TalerWallet1/Views/OIM/OIMcurrencyScroller.swift b/TalerWallet1/Views/OIM/OIMcurrencyScroller.swift @@ -12,44 +12,11 @@ import taler_swift struct OIMcurrencyScroller: View { let stack: CallStack @Binding var availableVal: UInt64 - @Binding var amountVal: UInt64 @Binding var tappedVal: UInt64 - @Binding var flying: UInt64 -// @Binding var shake: Bool @EnvironmentObject private var cash: OIMcash @EnvironmentObject private var wrapper: NamespaceWrapper - func tap(value: UInt64, _ delay: Int = 250) { - withAnimation(.shake1) { - flying = 0 - tappedVal = value - } -#if DEBUG - let ms = debugAnimations ? 1500 : delay -#else - let ms = delay -#endif -// print("tapped \(value)") - DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(ms)) { -// print("shake start") - withAnimation(.shake1) { - cash.shake = value - } - DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(ms)) { -// print("shake end") - withAnimation(.shake1) { - cash.shake = 0 - } - DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(ms)) { - withAnimation(.basic1) { - amountVal += value - tappedVal = 0 - } - } - } - } - } var body: some View { let currency = cash.currency ScrollView(.horizontal) { @@ -62,7 +29,7 @@ struct OIMcurrencyScroller: View { canEdit: true, // isFlipped: false, pct: 0.0, - action: { tap(value: value) } + action: { tappedVal = value } ) // .matchedGeometryEffect(id: value, in: wrapper.namespace, isSource: true) .matchedGeometryEffect(id: String(value), in: wrapper.namespace, isSource: true) @@ -75,7 +42,7 @@ struct OIMcurrencyScroller: View { canEdit: true, // isFlipped: false, pct: 0.0, - action: { tap(value: value) } + action: { tappedVal = value } ) // .matchedGeometryEffect(id: value, in: wrapper.namespace, isSource: true) .matchedGeometryEffect(id: String(value), in: wrapper.namespace, isSource: true) diff --git a/TalerWallet1/Views/OIM/OIMlineViews.swift b/TalerWallet1/Views/OIM/OIMlineViews.swift @@ -53,13 +53,15 @@ struct OIMlineViews: View { let stack: CallStack @Binding var amountVal: UInt64 @Binding var tappedVal: UInt64 - @Binding var flying: UInt64 let canEdit: Bool @EnvironmentObject private var cash: OIMcash @EnvironmentObject private var wrapper: NamespaceWrapper @AppStorage("oimTwoRows") var oimTwoRows: Bool = false + @State private var flying: UInt64 = 0 + @State private var myTappedVal: UInt64 = 0 + var body: some View { // let _ = Self._printChanges() #if DEBUG @@ -76,7 +78,7 @@ struct OIMlineViews: View { spread: result.0, currency: currency, amountVal: $amountVal, - tappedVal: tappedVal, + tappedVal: myTappedVal, flying: $flying, shake: (cash.shake != 0), canEdit: canEdit @@ -89,7 +91,7 @@ struct OIMlineViews: View { spread: result.1, currency: currency, amountVal: $amountVal, - tappedVal: tappedVal, + tappedVal: myTappedVal, flying: $flying, shake: (cash.shake != 0), canEdit: canEdit @@ -123,43 +125,70 @@ struct OIMlineViews: View { #endif } } - if #available(iOS 16.4, *) { - Group { - if false { - scrollView + + Group { + if #available(iOS 16.4, *) { + LayoutThatFits([HStackLayout(alignment: .center), VStackLayout()]) { + notes #if DEBUG - .padding(1) - .border(orange) + .padding(1) + .border(green) #endif - .clipped() - .scrollIndicators(.visible) - .viewExtractor { view in - if let scrollView = view as? UIScrollView { - if #available(iOS 17.4, *) { - scrollView.bouncesVertically = false - } else { // Fallback on earlier versions - scrollView.bounces = false - } - } - } - } else { - LayoutThatFits([HStackLayout(alignment: .center), VStackLayout()]) { - notes + coins + } #if DEBUG - .padding(1) - .border(green) + .padding(1) + .border(orange) #endif - coins - } + } else { + scrollView #if DEBUG .padding(1) .border(orange) #endif + .clipped() + } + } + .onChange(of: tappedVal) { newVal in + print(">>tapped ", newVal) + if newVal > 0 { + tappedVal = 0 + let ms = debugAnimations ? 1250 : 250 + + // next cycle + DispatchQueue.main.async { + print("\n>>start flying", newVal, flying) + let addedValue = (newVal == 200) ? 1000 : newVal + withAnimation(.shake1) { + print("addCash", addedValue) + cash.addCash(addedValue) + myTappedVal = newVal + } + print("\n>>reset flying", newVal, flying) + flying = 0 // remove immediately after it flew in, but outside of the animation block + + + DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(ms)) { + print("\n>>shake start", newVal, flying) + withAnimation(.shake1) { + cash.shake = newVal + } + DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(ms)) { + print("\n>>shake end", newVal, flying) + withAnimation(.shake1) { + cash.shake = 0 + } + DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(ms)) { + print("\n>>dissolve", newVal, flying) + withAnimation(.basic1) { + amountVal += newVal + myTappedVal = 0 + } + } + } + } } } - } else { - // Fallback on earlier versions - scrollView } } }