taler-ios

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

commit df98951ecd4f993c10cd0938b37f829dae2a0cde
parent a37bc6fec76c72a658c56328881fbd4f9ab42f75
Author: Marc Stibane <marc@taler.net>
Date:   Mon, 28 Apr 2025 09:36:40 +0200

tagStyle

Diffstat:
MTalerWallet1/Views/OIM/OIMView.swift | 101++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
MTalerWallet1/Views/OIM/OIMactionButtons.swift | 41++++++++++++++++++++++++++++++++++++-----
2 files changed, 103 insertions(+), 39 deletions(-)

diff --git a/TalerWallet1/Views/OIM/OIMView.swift b/TalerWallet1/Views/OIM/OIMView.swift @@ -22,11 +22,16 @@ fileprivate func intValue(_ amount: Amount?) -> UInt64 { struct OIMnavBack<Content: View>: View { let stack: CallStack let currencyName: String + let isFinal: Bool + let isGoal: Bool + let isSierra: Bool + let isSending: Bool @Binding var amount: Amount - @Binding var fwdButtonTapped: Bool + let action: () -> Void var content: () -> Content @Environment(\.dismiss) var dismiss // pop back once + @EnvironmentObject private var wrapper: NamespaceWrapper var body: some View { OIMbackground() { @@ -34,28 +39,25 @@ struct OIMnavBack<Content: View>: View { content() VStack { HStack { - OIMbalanceButton(isOpen: true, tint: false) { + OIMbalanceButton(isOpen: true, isSierra: isSierra, isFinal: false) { var transaction = Transaction() transaction.disablesAnimations = true withTransaction(transaction) { dismiss() } } - .frame(width: 66, height: 66) + .frame(width: 66, height: 66) Spacer() - OIMsendButton(isGoal: true, enabled: !amount.isZero) { - var transaction = Transaction() - transaction.disablesAnimations = true - withTransaction(transaction) { - fwdButtonTapped = true - } - } - .frame(width: 66, height: 66) + OIMsendButton(isGoal: isGoal, + isFinal: isFinal, + enabled: !amount.isZero, + action: action) + .frame(width: 66, height: 66) + .matchedGeometryEffect(id: isSending ? "OIMaction" : "OIMaction2", + in: wrapper.namespace, isSource: false) } } -#if DEBUG - .border(.blue) -#endif +// .border(.blue) } } } @@ -101,6 +103,9 @@ struct OIMView: View { var debugTick = 0 // let _ = Self._printChanges() + let enabled = if let available { + !available.isZero + } else { false } let actions = HStack(alignment: .top) { QRButton(hideTitle: true) { // var transaction = Transaction() @@ -113,30 +118,16 @@ struct OIMView: View { .frame(width: 66, height: 66) .matchedGeometryEffect(id: "OIMback", in: wrapper.namespace,isSource: true) Spacer() - let enabled = if let available { - !available.isZero - } else { false } - OIMsendButton(isGoal: false, enabled: enabled, action: sendAction) + OIMsendButton(isGoal: false, isFinal: false, enabled: enabled, action: sendAction) .frame(width: 66, height: 66) } - let numberView = HStack { - OIMbalanceButton(isOpen: true, tint: false) {} - .frame(width: 66, height: 66) - .disabled(true) - .opacity(0.01) - .matchedGeometryEffect(id: "OIMnumber", in: wrapper.namespace,isSource: true) - - OIMamountV(amount: available, currencyName: cash.currency.noteBase) - } - let maxAvailable = cash.max(available: intValue(available)) let _ = print("maxAvailable", maxAvailable) OIMbackground() { ZStack(alignment: .top) { actions - numberView VStack { Spacer() HStack(spacing: 30) { @@ -148,7 +139,7 @@ struct OIMView: View { let itsMe = isOpen == index let isClosed = isOpen == nil let size = isClosed ? 120.0 : 66.0 - OIMbalanceButton(isOpen: itsMe, tint: index > 0) { + OIMbalanceButton(isOpen: itsMe, isSierra: index > 0, isFinal: false) { withAnimation(.basic1) { if itsMe { isOpen = nil @@ -241,6 +232,7 @@ struct OIMEditView: View { @EnvironmentObject private var wrapper: NamespaceWrapper @State private var amountVal: UInt64 = 0 + @State private var sending = false // user tapped on Send @State private var availableVal: UInt64 = 0 @State private var tappedVal: UInt64 = 0 @@ -275,14 +267,38 @@ struct OIMEditView: View { return 999_999_999 } + func sendAction() { + // TODO: hide scroller +// DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) { +// withAnimation(.basic1.delay(delay + 0.5)) { + withAnimation(.basic1) { + sending = true // + } +// DispatchQueue.main.asyncAfter(deadline: .now() + delay + 1) { // cash.delay + DispatchQueue.main.asyncAfter(deadline: .now() + 1.2) { + var transaction = Transaction() + transaction.disablesAnimations = true + withTransaction(transaction) { + fwdButtonTapped = true // ==> go to purpose/goal + } + } +// } + } + var body: some View { // let _ = Self._printChanges() let _ = print(">>> OIMEditView", available, amount, stack.peek()?.file) + let noteBase = cash.currency.noteBase + let isSierra = noteBase == "SLE" OIMnavBack(stack: stack.push(), - currencyName: cash.currency.noteBase, + currencyName: noteBase, + isFinal: false, + isGoal: true, + isSierra: isSierra, + isSending: sending, amount: $amount, - fwdButtonTapped: $fwdButtonTapped + action: sendAction ) { ZStack { // without this, money would fly below the scroller VStack { // even though this is the only item in the ZStack @@ -340,15 +356,32 @@ struct OIMSubjectView: View { // let decimal: Int // 0 for ¥,HUF; 2 for $,€,£; 3 for ﷼,₯ (arabic) @Binding var fwdButtonTapped: Bool + @State private var sending = false // user tapped on Send + func sendAction() { + withAnimation(.basic1) { + sending = true // + } + var transaction = Transaction() + transaction.disablesAnimations = true + withTransaction(transaction) { + fwdButtonTapped = true // ==> Send the money + } + } var body: some View { // let _ = Self._printChanges() let currency = cash.currency + let noteBase = currency.noteBase + let isSierra = noteBase == "SLE" OIMnavBack(stack: stack.push(), - currencyName: currency.noteBase, + currencyName: noteBase, + isFinal: true, + isGoal: false, + isSierra: isSierra, + isSending: sending, amount: $amount, - fwdButtonTapped: $fwdButtonTapped + action: sendAction ) { VStack { Spacer() diff --git a/TalerWallet1/Views/OIM/OIMactionButtons.swift b/TalerWallet1/Views/OIM/OIMactionButtons.swift @@ -9,6 +9,7 @@ import SwiftUI struct OIMsendButton: View { let isGoal: Bool + let isFinal: Bool let enabled: Bool let action: () -> Void @@ -22,24 +23,54 @@ struct OIMsendButton: View { // .tint(WalletColors().talerColor) .foregroundStyle(WalletColors().talerColor) } - .opacity(enabled ? 1.0 : 0.3) + .tagStyle(isFinal ? .prominent : .borderless) + .opacity(enabled ? 1.0 : 0.01) .disabled(!enabled) } } struct OIMbalanceButton: View { let isOpen: Bool - let tint: Bool + let isSierra: Bool + let isFinal: Bool let action: () -> Void var body: some View { - let imageName = isOpen ? "ChestOpen" : "ChestClosed" + let imageName = isSierra ? (isOpen ? "ChestSLopen" : "ChestSLclosed") +// : (isOpen ? "ChestDEopen" : "ChestDEclosed") +// : (isOpen ? "ChestEUopen" : "ChestEUclosed") + : (isOpen ? "ChestEUopen1" : "ChestEUclosed1") Button(action: action) { Image(imageName) .resizable() .scaledToFit() - .foregroundStyle(tint ? .brown - : WalletColors().talerColor) + } + .tagStyle(isFinal ? .prominent : .borderless) + } +} + +enum TagButtonStyle { + case prominent + case bordered + case `default` + case borderless + // .. extend with any custom here +} + +extension Button { + + @ViewBuilder + func tagStyle(_ style: TagButtonStyle) -> some View { + switch style { + case .prominent: + self.buttonStyle(BorderedProminentButtonStyle()) + case .bordered: + self.buttonStyle(BorderedButtonStyle()) + case .borderless: + self.buttonStyle(BorderlessButtonStyle()) + case .default: + self.buttonStyle(DefaultButtonStyle()) + // .. extend with any custom here } } }