taler-ios

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

commit ca1e592e3c6269963e0f5d034d1d6ba0d5fce64c
parent 055b524f0a44599d6e7cb28f9ebf60e3f76fb9f0
Author: Marc Stibane <marc@taler.net>
Date:   Fri,  8 Nov 2024 13:47:12 +0100

Use NavLink

Diffstat:
MTalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift | 11+++++------
MTalerWallet1/Views/Main/MainView.swift | 38+++++++++++++++++++++++---------------
MTalerWallet1/Views/Sheets/Payment/PayTemplateV.swift | 16+++++-----------
MTalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift | 13++++++-------
4 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift @@ -216,6 +216,10 @@ struct RequestPaymentContent: View { amountToTransfer: $amountShortcut, summary: $summary, expireDays: $expireDays) + let actions = Group { + NavLink($buttonSelected) { inputDestination } + NavLink($shortcutSelected) { shortcutDestination } + } let amountLabel = minimalistic ? String(localized: "Amount:") : String(localized: "Amount to request:") AmountInputV(stack: stack.push(), @@ -230,12 +234,7 @@ struct RequestPaymentContent: View { buttonAction: buttonAction, feeIsNegative: true, computeFee: computeFee) - .background(NavigationLink(destination: shortcutDestination, isActive: $shortcutSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden() - ) // shortcutDestination - .background(NavigationLink(destination: inputDestination, isActive: $buttonSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden() - ) // inputDestination + .background(actions) } } // Group .task(id: balanceIndex + (1000 * controller.currencyTicker)) { diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift @@ -278,6 +278,11 @@ extension MainView { } } } + private var isBalances: Bool { self.selectedTab == .balances} + private func triggerAction(_ action: Int) { + navModel.actionSelected = isBalances ? action // 1..4 + : action + 4 // 5..8 + } private static func className() -> String {"\(self)"} private static var name: String { Self.className() } @@ -330,6 +335,18 @@ extension MainView { amountLastUsed: $amountLastUsed, // currency needs to be updated! isSheet: false) + let balanceActions = Group { + NavLink(1, $navModel.actionSelected) { sendDest } + NavLink(2, $navModel.actionSelected) { requestDest } + NavLink(3, $navModel.actionSelected) { depositDest } + NavLink(4, $navModel.actionSelected) { manualWithdrawDest } + } + let settingsActions = Group { + NavLink(5, $navModel.actionSelected) { sendDest } + NavLink(6, $navModel.actionSelected) { requestDest } + NavLink(7, $navModel.actionSelected) { depositDest } + NavLink(8, $navModel.actionSelected) { manualWithdrawDest } + } ZStack(alignment: .bottom) { TabView(selection: tabSelection()) { NavigationView { @@ -338,20 +355,7 @@ extension MainView { // shouldReloadPending: $shouldReloadPending, shouldReloadBalances: $shouldReloadBalances) .navigationTitle(balancesTitle) - .background( Group { - NavigationLink(destination: sendDest, tag: 1, selection: $navModel.actionSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden() - NavigationLink(destination: requestDest, tag: 2, selection: $navModel.actionSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden() - NavigationLink(destination: depositDest, tag: 3, selection: $navModel.actionSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden() - NavigationLink(destination: manualWithdrawDest, tag: 4, selection: $navModel.actionSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden() - }) - .onNotification(.SendAction) { navModel.actionSelected = 1 } - .onNotification(.RequestAction) { navModel.actionSelected = 2 } - .onNotification(.DepositAction) { navModel.actionSelected = 3 } - .onNotification(.WithdrawAction){ navModel.actionSelected = 4 } + .background(balanceActions) }.id(viewState.rootViewId) // any change to rootViewId triggers popToRootView behaviour .navigationViewStyle(.stack) .tag(Tab.balances) @@ -361,6 +365,7 @@ extension MainView { NavigationView { SettingsView(stack: stack.push(), navTitle: settingsTitle) + .background(settingsActions) }.id(viewState2.rootViewId) // any change to rootViewId triggers popToRootView behaviour .navigationViewStyle(.stack) .tag(Tab.settings) @@ -371,7 +376,10 @@ extension MainView { .ignoresSafeArea(.keyboard, edges: .bottom) } // ZStack .frame(maxWidth: .infinity, maxHeight: .infinity) - + .onNotification(.SendAction) { triggerAction(1) } + .onNotification(.RequestAction) { triggerAction(2) } + .onNotification(.DepositAction) { triggerAction(3) } + .onNotification(.WithdrawAction){ triggerAction(4) } .onNotification(.KYCrequired) { notification in // show an alert with the KYC link (button) which opens in Safari if let transition = notification.userInfo?[TRANSACTIONTRANSITION] as? TransactionTransition { diff --git a/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift b/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift @@ -184,25 +184,19 @@ struct PayTemplateV: View { ScrollView { if summaryIsEditable { // after amount input, amountInput - .background(NavigationLink(destination: shortcutDestination, isActive: $shortcutSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden()) - .background( NavigationLink(destination: inputDestination, isActive: $buttonSelected1) - { EmptyView() }.frame(width: 0).opacity(0).hidden()) + .background( NavLink($shortcutSelected) { shortcutDestination } ) + .background( NavLink($buttonSelected1) { inputDestination} ) } else { amountInput - .background(NavigationLink(destination: finalDestinationS, isActive: $shortcutSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden()) - .background(NavigationLink(destination: finalDestinationI, isActive: $buttonSelected1) - { EmptyView() }.frame(width: 0).opacity(0).hidden()) + .background( NavLink($shortcutSelected) { finalDestinationS } ) + .background( NavLink($buttonSelected1) { finalDestinationI } ) } } // amountInput } else if summaryIsEditable { // template contract summary is not fixed => let the user input a summary ScrollView { inputDestination - .background(NavigationLink(destination: finalDestinationI, isActive: $buttonSelected2) - { EmptyView() }.frame(width: 0).opacity(0).hidden() - ) + .background( NavLink($buttonSelected2) { finalDestinationI } ) } // inputDestination } else { // both template contract amount and summary are fixed => directly show the payment // Attention: contains a List, thus mustn't be included in a ScrollView diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift @@ -150,12 +150,16 @@ struct WithdrawURIView: View { exchange: $exchange) if amountIsEditable { ScrollView { - let shortcutDestination = WithdrawAcceptView(stack: stack.push(), + let shortcutDest = WithdrawAcceptView(stack: stack.push(), url: url, scope: exchange.scopeInfo, amountToTransfer: $amountShortcut, wireFee: $wireFee, exchange: $exchange) + let actions = Group { + NavLink($shortcutSelected) { shortcutDest } + NavLink($buttonSelected) { acceptDestination } + } // TODO: input amount, then let amountLabel = minimalistic ? String(localized: "Amount:") : String(localized: "Amount to withdraw:") @@ -171,12 +175,7 @@ struct WithdrawURIView: View { buttonAction: buttonAction, feeIsNegative: true, computeFee: computeFeeWithdraw) - .background(NavigationLink(destination: shortcutDestination, isActive: $shortcutSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden() - ) // shortcutDestination - .background(NavigationLink(destination: acceptDestination, isActive: $buttonSelected) - { EmptyView() }.frame(width: 0).opacity(0).hidden() - ) // acceptDestination + .background(actions) } // ScrollView } else { acceptDestination