Fixed placing "Add account" below List; extracted AddAccountButtonView

This commit is contained in:
dankito 2020-08-10 16:23:48 +02:00
parent f168575e16
commit bb347c8335
2 changed files with 54 additions and 11 deletions

View File

@ -11,26 +11,30 @@ struct AccountsTab: View {
var body: some View { var body: some View {
VStack { VStack {
if data.banks.isNotEmpty { if data.banks.isEmpty {
Spacer()
AddAccountButtonView()
Spacer()
}
else {
Form { Form {
AllBanksListItem(banks: data.banks) AllBanksListItem(banks: data.banks)
ForEach(data.banks) { bank in ForEach(data.banks) { bank in
BankListItem(bank: bank) BankListItem(bank: bank)
} }
Section {
AddAccountButtonView()
}
.background(Color(UIColor.systemGroupedBackground))
.listRowInsets(EdgeInsets())
} }
} }
Spacer()
NavigationLink(destination: LazyView(AddAccountDialog())) {
Text("Add account")
}
.frame(height: 35)
Spacer()
} }
.frame(width: UIScreen.main.bounds.width)
.background(Color(UIColor.systemGroupedBackground)) .background(Color(UIColor.systemGroupedBackground))
} }

View File

@ -0,0 +1,39 @@
import SwiftUI
struct AddAccountButtonView: View {
@State private var showAddAccountDialog = false
var body: some View {
VStack {
HStack {
Spacer()
Button("Add account") { self.showAddAccountDialog = true }
Spacer()
}
.padding(.top, 10) // to fix that hidden NavigationLink below pulls HStack up
.frame(maxWidth: .infinity, minHeight: 40)
NavigationLink(destination: LazyView(AddAccountDialog()), isActive: $showAddAccountDialog) {
EmptyView()
}
.hidden()
.frame(height: 0)
}
}
}
struct AddAccountButtonView_Previews: PreviewProvider {
static var previews: some View {
AddAccountButtonView()
}
}