From 87bf88153e4e5fbd47aea33165d15508fde4ac82 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 23 Jul 2020 22:53:04 +0200 Subject: [PATCH] Fixed navigation problems to large parts by removing VStack directly after Section and by implementing Identifyable in model classes, with which ForEach can better cope with as with indicies --- .../BankingiOSApp/ContentView.swift | 128 +++++++++++++++--- .../persistence/Extensions.swift | 22 +++ .../BankingiOSApp/ui/views/AccountsTab.swift | 15 +- .../BankingiOSApp/ui/views/BankListItem.swift | 18 +-- 4 files changed, 145 insertions(+), 38 deletions(-) create mode 100644 ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift diff --git a/ui/BankingiOSApp/BankingiOSApp/ContentView.swift b/ui/BankingiOSApp/BankingiOSApp/ContentView.swift index 75be055a..1a027fb5 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ContentView.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ContentView.swift @@ -1,37 +1,123 @@ import SwiftUI +import BankingUiSwift + struct ContentView: View { @ObservedObject var data: AppData = AppData() @State private var selection = 0 + + @State private var showTransferMoneyOptionsActionSheet = false + @State private var selectedTransferMoneyOption: Int? = 0 + + + // TODO: remove again + private let enterTanState: EnterTanState + + + init() { + let customer = Customer(bankCode: "", customerId: "", password: "", finTsServerAddress: "") + let selectedTanProcedure = TanProcedure(displayName: "chipTAN optisch", type: .chiptanflickercode, bankInternalProcedureCode: "chipTAN optisch") + customer.supportedTanProcedures = [ + TanProcedure(displayName: "App TAN", type: .apptan, bankInternalProcedureCode: "App TAN"), + selectedTanProcedure, + TanProcedure(displayName: "SMS TAN", type: .smstan, bankInternalProcedureCode: "SMS TAN") + ] + customer.selectedTanProcedure = selectedTanProcedure + + customer.tanMedia = [ + TanMedium(displayName: "EC-Karte mit Nummer 12345678", status: .available), + TanMedium(displayName: "Handy mit Nummer 0170 / 12345678", status: .available) + ] + + self.enterTanState = EnterTanState(customer, TanChallenge(messageToShowToUser: "Gib die TAN ein du faules Stueck!", tanProcedure: selectedTanProcedure)) { result in } + } + var body: some View { - TabView(selection: $selection) { - AccountsTab(data: data) - .tabItem { - VStack { - Image("first") - Text("Accounts") - } - } - .tag(0) +// NavigationView { + VStack { + TabView(selection: $selection) { + AccountsTab(data: data) + .tabItem { + VStack { + Image("first") + Text("Accounts") + } + } + .tag(0) - NavigationView { - VStack { - NavigationLink(destination: TransferMoneyDialog()) { - Text("Show transfer money dialog") + // actionSheet(isPresented: $showTransferMoneyOptionsActionSheet) { + // ActionSheet( + // title: Text("Action"), + // message: Text("Available actions"), + // buttons: [ + // .default(Text("Show transfer money dialog")) { self.selectedTransferMoneyOption = 1 }, + // .destructive(Text("Delete")) + // ] + // ) + // } + + // TransferMoneyDialog() + // .tabItem { + // NavigationLink(destination: TransferMoneyDialog(), tag: 1, selection: $selectedTransferMoneyOption) { + // EmptyView() + // } + // VStack { + // Image("second") + // Text("Second") + // } + // .onTapGesture { + // NSLog("Tapped on second item") // TODO: remove again + // self.showTransferMoneyOptionsActionSheet = true + // } + // } + // NavigationView { + VStack { + NavigationLink(destination: TransferMoneyDialog()) { + Text("Show transfer money dialog") + } + + NavigationLink(destination: TransferMoneyDialog().onDisappear(perform: { + NSLog("Disappearing NavigationLink") // TODO: remove + self.selectedTransferMoneyOption = 0 + }), tag: 1, selection: $selectedTransferMoneyOption) { + EmptyView() + } + + SheetPresenter(presentingSheet: $showTransferMoneyOptionsActionSheet, content: + ActionSheet( + title: Text(""), + buttons: [ + .default(Text("Show transfer money dialog")) { self.selectedTransferMoneyOption = 1 }, + .cancel() + ] + ) + ) + } + // } + .tabItem { + VStack { + Image(systemName: "plus.circle.fill") + } + } + .tag(1) + + NavigationView { EnterTanDialog(self.enterTanState) } + .tabItem { + VStack { + Text("EnterTanDialog") + } } + .tag(2) + } + + } - .tabItem { - VStack { - Image("second") - Text("Second") - } - } - .tag(1) - } + .hideNavigationBar() +// } } } diff --git a/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift b/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift new file mode 100644 index 00000000..8bbf929e --- /dev/null +++ b/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift @@ -0,0 +1,22 @@ +import Foundation +import SwiftUI +import BankingUiSwift + + +extension Customer : Identifiable { + + public var id: UUID { UUID() } + +} + +extension BankAccount : Identifiable { + + public var id: UUID { UUID() } + +} + +extension AccountTransaction : Identifiable { + + public var id: UUID { UUID() } + +} diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountsTab.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountsTab.swift index f4c89de9..87943b30 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountsTab.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountsTab.swift @@ -8,32 +8,31 @@ struct AccountsTab: View { @ObservedObject var data: AppData - + var body: some View { NavigationView { VStack { if data.banks.isEmpty == false { Form { - ForEach(0 ..< data.banks.count) { bankIndex in - Section { - BankListItem(bank: self.data.banks[bankIndex]) - } + ForEach(data.banks) { bank in + BankListItem(bank: bank) } } } - + Spacer() - + NavigationLink(destination: AddAccountDialog()) { Text("Add account") } - + Spacer() } .navigationBarHidden(true) .navigationBarTitle(Text("Accounts"), displayMode: .inline) } } + } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift index 19a60212..af17fa31 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift @@ -8,22 +8,22 @@ struct BankListItem : View { var body: some View { - NavigationLink(destination: AccountTransactionsDialog(title: bank.displayName, transactions: bank.accounts.flatMap { $0.bookedTransactions })) { - VStack { + Section { + NavigationLink(destination: AccountTransactionsDialog(title: bank.displayName, transactions: bank.accounts.flatMap { $0.bookedTransactions })) { HStack { Text(bank.displayName) .font(.headline) Spacer() }.frame(height: 35) - - VStack { - ForEach(0 ..< bank.accounts.count) { accountIndex in - BankAccountListItem(account: self.bank.accounts[accountIndex]) - } - } - .padding(.leading, 18) } + + VStack { + ForEach(bank.accounts) { account in + BankAccountListItem(account: account) + } + } + .padding(.leading, 18) } }