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,37 +1,123 @@
import SwiftUI import SwiftUI
import BankingUiSwift
struct ContentView: View { struct ContentView: View {
@ObservedObject var data: AppData = AppData() @ObservedObject var data: AppData = AppData()
@State private var selection = 0 @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 { var body: some View {
TabView(selection: $selection) { // NavigationView {
AccountsTab(data: data) VStack {
.tabItem { TabView(selection: $selection) {
VStack { AccountsTab(data: data)
Image("first") .tabItem {
Text("Accounts") VStack {
} Image("first")
} Text("Accounts")
.tag(0) }
}
.tag(0)
NavigationView { // actionSheet(isPresented: $showTransferMoneyOptionsActionSheet) {
VStack { // ActionSheet(
NavigationLink(destination: TransferMoneyDialog()) { // title: Text("Action"),
Text("Show transfer money dialog") // 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

@ -8,32 +8,31 @@ struct AccountsTab: View {
@ObservedObject var data: AppData @ObservedObject var data: AppData
var body: some View { var body: some View {
NavigationView { NavigationView {
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])
}
} }
} }
} }
Spacer() Spacer()
NavigationLink(destination: AddAccountDialog()) { NavigationLink(destination: AddAccountDialog()) {
Text("Add account") Text("Add account")
} }
Spacer() Spacer()
} }
.navigationBarHidden(true) .navigationBarHidden(true)
.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)
} }
} }