Disabling EditButton if no account has been added yet

This commit is contained in:
dankito 2020-09-05 02:31:00 +02:00
parent eac6ec7d62
commit 5d29a12f02
2 changed files with 7 additions and 2 deletions

View File

@ -5,15 +5,20 @@ struct SectionHeaderWithRightAlignedEditButton: View {
private let sectionTitle: LocalizedStringKey private let sectionTitle: LocalizedStringKey
private let isEditButtonEnabled: Bool
init(_ sectionTitle: LocalizedStringKey) {
init(_ sectionTitle: LocalizedStringKey, isEditButtonEnabled: Bool = true) {
self.sectionTitle = sectionTitle self.sectionTitle = sectionTitle
self.isEditButtonEnabled = isEditButtonEnabled
} }
var body: some View { var body: some View {
EditButton() EditButton()
.frame(maxWidth: .infinity, alignment: .trailing) .frame(maxWidth: .infinity, alignment: .trailing)
.disabled( !isEditButtonEnabled)
.overlay(Text(sectionTitle), alignment: .leading) .overlay(Text(sectionTitle), alignment: .leading)
} }

View File

@ -14,7 +14,7 @@ struct SettingsDialog: View {
var body: some View { var body: some View {
Form { Form {
Section(header: SectionHeaderWithRightAlignedEditButton("Bank Credentials")) { Section(header: SectionHeaderWithRightAlignedEditButton("Bank Credentials", isEditButtonEnabled: data.hasAtLeastOneAccountBeenAdded)) {
ForEach(data.banksSorted) { bank in ForEach(data.banksSorted) { bank in
NavigationLink(destination: LazyView(BankSettingsDialog(bank))) { NavigationLink(destination: LazyView(BankSettingsDialog(bank))) {
IconedTitleView(bank) IconedTitleView(bank)