taler-ios

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

commit 5f681aae5e3b2530e66db03f16bef029a4891c9e
parent 65b61e9736412deebe0d6712a7b387087da07c37
Author: Marc Stibane <marc@taler.net>
Date:   Mon, 13 Nov 2023 21:03:53 +0100

Shortcuts (50,25,10,5)

Diffstat:
MTalerWallet1/Views/Exchange/ManualWithdraw.swift | 3++-
MTalerWallet1/Views/HelperViews/CurrencyField.swift | 18+++++++++++++++++-
MTalerWallet1/Views/HelperViews/CurrencyInputView.swift | 54+++++++++++++++++++++++++++++++++++++-----------------
MTalerWallet1/Views/Peer2peer/RequestPayment.swift | 3++-
MTalerWallet1/Views/Peer2peer/SendAmount.swift | 3++-
5 files changed, 60 insertions(+), 21 deletions(-)

diff --git a/TalerWallet1/Views/Exchange/ManualWithdraw.swift b/TalerWallet1/Views/Exchange/ManualWithdraw.swift @@ -34,7 +34,8 @@ struct ManualWithdraw: View { VStack { CurrencyInputView(amount: $amountToTransfer, title: iconOnly ? String(localized: "How much:") - : String(localized: "Amount to withdraw:")) + : String(localized: "Amount to withdraw:"), + shortcutLabel: String(localized: "Withdraw", comment: "VoiceOver: Withdraw $50,$25,$10,$5 shortcut buttons")) let someCoins = SomeCoins(details: withdrawalAmountDetails) QuiteSomeCoins(someCoins: someCoins, shouldShowFee: true, currency: currency, amountEffective: withdrawalAmountDetails?.amountEffective) diff --git a/TalerWallet1/Views/HelperViews/CurrencyField.swift b/TalerWallet1/Views/HelperViews/CurrencyField.swift @@ -40,6 +40,10 @@ struct CurrencyField: View { currencyInputField.resignFirstResponder() } + func updateText(amount: Amount) { + currencyInputField.updateText(amount: amount) + } + public init(amount: Binding<Amount>, currencyInfo: CurrencyInfo) { self._amount = amount self.currencyInfo = currencyInfo @@ -60,6 +64,7 @@ struct CurrencyField: View { // Input text field to handle UI currencyInputField + .accessibilityHidden(true) // .textFieldStyle(.roundedBorder) } } @@ -84,6 +89,7 @@ class NoCaretTextField: UITextField { struct CurrencyInputField: UIViewRepresentable { @Binding var amount: Amount let currencyInfo: CurrencyInfo + private let textField = NoCaretTextField(frame: .zero) func makeCoordinator() -> Coordinator { @@ -98,6 +104,14 @@ struct CurrencyInputField: UIViewRepresentable { textField.resignFirstResponder() } + func updateText(amount: Amount) { + let plain = amount.plainString(currencyInfo) + print("Setting textfield to: \(plain)") + textField.text = plain + let endPosition = textField.endOfDocument + textField.selectedTextRange = textField.textRange(from: endPosition, to: endPosition) + } + func makeUIView(context: Context) -> NoCaretTextField { // Assign delegate textField.delegate = context.coordinator @@ -147,8 +161,10 @@ struct CurrencyInputField: UIViewRepresentable { func updateText(_ amount: Amount, textField: UITextField) { // Update field text and last valid input text lastValidInput = amount.plainString(input.currencyInfo) -// print(lastValidInput) +// print("lastValidInput: `\(lastValidInput)´") textField.text = lastValidInput + let endPosition = textField.endOfDocument + textField.selectedTextRange = textField.textRange(from: endPosition, to: endPosition) } func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { diff --git a/TalerWallet1/Views/HelperViews/CurrencyInputView.swift b/TalerWallet1/Views/HelperViews/CurrencyInputView.swift @@ -8,24 +8,43 @@ import taler_swift struct CurrencyInputView: View { @Binding var amount: Amount // the `value´ let title: String + let shortcutLabel: String @EnvironmentObject private var controller: Controller @State var hasBeenShown = false var body: some View { - let currencyInfo = controller.info(for: amount.currencyStr, controller.currencyTicker) + let shortcuts = [50,25,10,5] + let currency = amount.currencyStr + let currencyInfo = controller.info(for: currency, controller.currencyTicker) let currencyField = CurrencyField(amount: $amount, currencyInfo: currencyInfo) - VStack (alignment: .leading) { - Text(title) -// .padding(.top) - .accessibilityFont(.title3) + VStack (alignment: .center) { + HStack { + Text(title) +// .padding(.top) + .accessibilityFont(.title3) + .accessibilityAddTraits(.isHeader) + .accessibilityRemoveTraits(.isStaticText) + Spacer() + } currencyField .frame(maxWidth: .infinity, alignment: .trailing) .foregroundColor(WalletColors().fieldForeground) // text color .background(WalletColors().fieldBackground) .accessibilityFont(.title2) .textFieldStyle(.roundedBorder) + HStack { + ForEach(shortcuts, id: \.self) { shortcut in + let shortie = Amount(currency: currency, integer: UInt64(shortcut), fraction: 0) + let title = shortie.string(currencyInfo) + Button(title) { + currencyField.updateText(amount: shortie) + amount = shortie + }.buttonStyle(.bordered) + .accessibilityLabel("\(shortcutLabel) \(title)") + } + } }.onAppear { // make CurrencyField show the keyboard after 0.4 seconds if hasBeenShown { // print("❗️Yikes: CurrencyInputView hasBeenShown") @@ -43,20 +62,21 @@ struct CurrencyInputView: View { } // MARK: - #if DEBUG -struct CurrencyInputView_Previews: PreviewProvider { - struct StateContainer : View { - @State var amountToTransfer = Amount(currency: LONGCURRENCY, cent: 0) - - var body: some View { - CurrencyInputView(amount: $amountToTransfer, - title: "Amount to withdraw:") +fileprivate struct Previews: PreviewProvider { + @MainActor + struct StateContainer: View { + @StateObject private var controller = Controller.shared + @State var amountToTransfer = Amount(currency: LONGCURRENCY, cent: 0) + var body: some View { +// Preview_Content() + CurrencyInputView(amount: $amountToTransfer, + title: "Amount to withdraw:", + shortcutLabel: "Withdraw") + .environmentObject(controller) + } } - } - static var previews: some View { - List { - StateContainer() - } + StateContainer() } } #endif diff --git a/TalerWallet1/Views/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Peer2peer/RequestPayment.swift @@ -31,7 +31,8 @@ struct RequestPayment: View { ScrollView { VStack { CurrencyInputView(amount: $amountToTransfer, title: iconOnly ? String(localized: "How much:") - : String(localized: "Amount to request:")) + : String(localized: "Amount to request:"), + shortcutLabel: String(localized: "Request", comment: "VoiceOver: Request $50,$25,$10,$5 shortcut buttons")) let someCoins = SomeCoins(details: peerPullCheck) QuiteSomeCoins(someCoins: someCoins, shouldShowFee: true, diff --git a/TalerWallet1/Views/Peer2peer/SendAmount.swift b/TalerWallet1/Views/Peer2peer/SendAmount.swift @@ -49,7 +49,8 @@ struct SendAmount: View { .padding(.bottom, 2) CurrencyInputView(amount: $amountToTransfer, title: iconOnly ? String(localized: "How much:") - : String(localized: "Amount to send:")) + : String(localized: "Amount to send:"), + shortcutLabel: String(localized: "Send", comment: "VoiceOver: Send $50,$25,$10,$5 shortcut buttons")) Text("+ \(fee) payment fee") .accessibilityFont(.body) .foregroundColor(.red)