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

This commit is contained in:
dankito 2020-07-23 22:53:04 +02:00
parent 56164f2ce4
commit 87bf88153e
4 changed files with 145 additions and 38 deletions

View File

@ -1,4 +1,6 @@
import SwiftUI import SwiftUI
import BankingUiSwift
struct ContentView: View { struct ContentView: View {
@ -6,32 +8,116 @@ struct ContentView: View {
@State private var selection = 0 @State private var selection = 0
var body: some View { @State private var showTransferMoneyOptionsActionSheet = false
TabView(selection: $selection) { @State private var selectedTransferMoneyOption: Int? = 0
AccountsTab(data: data)
.tabItem {
VStack {
Image("first")
Text("Accounts")
}
}
.tag(0)
NavigationView {
VStack { // TODO: remove again
NavigationLink(destination: TransferMoneyDialog()) { private let enterTanState: EnterTanState
Text("Show transfer money dialog")
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 {
// NavigationView {
VStack {
TabView(selection: $selection) {
AccountsTab(data: data)
.tabItem {
VStack {
Image("first")
Text("Accounts")
}
}
.tag(0)
// 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 { .hideNavigationBar()
VStack { // }
Image("second")
Text("Second")
}
}
.tag(1)
}
} }
} }

View File

@ -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() }
}

View File

@ -14,10 +14,8 @@ struct AccountsTab: View {
VStack { VStack {
if data.banks.isEmpty == false { if data.banks.isEmpty == false {
Form { Form {
ForEach(0 ..< data.banks.count) { bankIndex in ForEach(data.banks) { bank in
Section { BankListItem(bank: bank)
BankListItem(bank: self.data.banks[bankIndex])
}
} }
} }
} }
@ -34,6 +32,7 @@ struct AccountsTab: View {
.navigationBarTitle(Text("Accounts"), displayMode: .inline) .navigationBarTitle(Text("Accounts"), displayMode: .inline)
} }
} }
} }

View File

@ -8,22 +8,22 @@ struct BankListItem : View {
var body: some View { var body: some View {
NavigationLink(destination: AccountTransactionsDialog(title: bank.displayName, transactions: bank.accounts.flatMap { $0.bookedTransactions })) { Section {
VStack { NavigationLink(destination: AccountTransactionsDialog(title: bank.displayName, transactions: bank.accounts.flatMap { $0.bookedTransactions })) {
HStack { HStack {
Text(bank.displayName) Text(bank.displayName)
.font(.headline) .font(.headline)
Spacer() Spacer()
}.frame(height: 35) }.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)
} }
} }