Renamed SectionWithRightAlignedEditButton to SectionHeaderWithRightAlignedEditButton and building now Section in View.body

This commit is contained in:
dankito 2020-09-05 02:28:30 +02:00
parent 0133787ee4
commit eac6ec7d62
4 changed files with 31 additions and 37 deletions

View File

@ -74,7 +74,7 @@ struct BankSettingsDialog: View {
LabelledUIKitTextField(label: "FinTS server address", value: bank.finTsServerAddress) // TODO: senseful? LabelledUIKitTextField(label: "FinTS server address", value: bank.finTsServerAddress) // TODO: senseful?
} }
SectionWithRightAlignedEditButton(sectionTitle: "Accounts") { Section(header: SectionHeaderWithRightAlignedEditButton("Accounts")) {
ForEach(accountsSorted) { account in ForEach(accountsSorted) { account in
NavigationLink(destination: LazyView(BankAccountSettingsDialog(account))) { NavigationLink(destination: LazyView(BankAccountSettingsDialog(account))) {
Text(account.displayName) Text(account.displayName)

View File

@ -0,0 +1,29 @@
import SwiftUI
struct SectionHeaderWithRightAlignedEditButton: View {
private let sectionTitle: LocalizedStringKey
init(_ sectionTitle: LocalizedStringKey) {
self.sectionTitle = sectionTitle
}
var body: some View {
EditButton()
.frame(maxWidth: .infinity, alignment: .trailing)
.overlay(Text(sectionTitle), alignment: .leading)
}
}
struct SectionHeaderWithRightAlignedEditButton_Previews: PreviewProvider {
static var previews: some View {
SectionHeaderWithRightAlignedEditButton("Section")
}
}

View File

@ -1,35 +0,0 @@
import SwiftUI
struct SectionWithRightAlignedEditButton<Content: View>: View {
private let sectionTitle: LocalizedStringKey
private let content: Content
init(sectionTitle: LocalizedStringKey, @ViewBuilder content: () -> Content) {
self.sectionTitle = sectionTitle
self.content = content()
}
var body: some View {
Section(header: EditButton().frame(maxWidth: .infinity, alignment: .trailing)
.overlay(Text(sectionTitle), alignment: .leading)) {
content
}
}
}
struct SectionWithRightAlignedEditButton_Previews: PreviewProvider {
static var previews: some View {
SectionWithRightAlignedEditButton(sectionTitle: "Section") {
Text("Body")
}
}
}

View File

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