This commit is contained in:
Arkadiusz Fal
2022-11-11 19:53:52 +01:00
parent 5d033cbdfc
commit 611bcde238
3 changed files with 28 additions and 67 deletions

View File

@@ -89,7 +89,7 @@ struct BrowsingSettings: View {
Section(header: SettingsHeader(text: "Sections".localized())) {
#if os(macOS)
let list = ForEach(VisibleSection.allCases, id: \.self) { section in
VisibleSectionSelectionRow(
MultiselectRow(
title: section.title,
selected: visibleSections.contains(section)
) { value in
@@ -110,7 +110,7 @@ struct BrowsingSettings: View {
}
#else
ForEach(VisibleSection.allCases, id: \.self) { section in
VisibleSectionSelectionRow(
MultiselectRow(
title: section.title,
selected: visibleSections.contains(section)
) { value in
@@ -128,51 +128,13 @@ struct BrowsingSettings: View {
visibleSections.remove(section)
}
}
struct VisibleSectionSelectionRow: View {
let title: String
let selected: Bool
var action: (Bool) -> Void
@State private var toggleChecked = false
var body: some View {
Button(action: { action(!selected) }) {
HStack {
#if os(macOS)
Toggle(isOn: $toggleChecked) {
Text(self.title)
Spacer()
}
.onAppear {
toggleChecked = selected
}
.onChange(of: toggleChecked) { new in
action(new)
}
#else
Text(self.title)
Spacer()
if selected {
Image(systemName: "checkmark")
#if os(iOS)
.foregroundColor(.accentColor)
#endif
}
#endif
}
.contentShape(Rectangle())
}
#if !os(tvOS)
.buttonStyle(.plain)
#endif
}
}
}
struct BrowsingSettings_Previews: PreviewProvider {
static var previews: some View {
BrowsingSettings()
.injectFixtureEnvironmentObjects()
VStack {
BrowsingSettings()
}
.injectFixtureEnvironmentObjects()
}
}