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())) { Section(header: SettingsHeader(text: "Sections".localized())) {
#if os(macOS) #if os(macOS)
let list = ForEach(VisibleSection.allCases, id: \.self) { section in let list = ForEach(VisibleSection.allCases, id: \.self) { section in
VisibleSectionSelectionRow( MultiselectRow(
title: section.title, title: section.title,
selected: visibleSections.contains(section) selected: visibleSections.contains(section)
) { value in ) { value in
@ -110,7 +110,7 @@ struct BrowsingSettings: View {
} }
#else #else
ForEach(VisibleSection.allCases, id: \.self) { section in ForEach(VisibleSection.allCases, id: \.self) { section in
VisibleSectionSelectionRow( MultiselectRow(
title: section.title, title: section.title,
selected: visibleSections.contains(section) selected: visibleSections.contains(section)
) { value in ) { value in
@ -128,51 +128,13 @@ struct BrowsingSettings: View {
visibleSections.remove(section) 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 { struct BrowsingSettings_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
VStack {
BrowsingSettings() BrowsingSettings()
}
.injectFixtureEnvironmentObjects() .injectFixtureEnvironmentObjects()
} }
} }

View File

@ -9,13 +9,9 @@ struct MultiselectRow: View {
@State private var toggleChecked = false @State private var toggleChecked = false
var body: some View { var body: some View {
Button(action: { action(!selected) }) {
HStack {
#if os(macOS) #if os(macOS)
Toggle(isOn: $toggleChecked) { Toggle(title, isOn: $toggleChecked)
Text(self.title) .toggleStyle(.checkbox)
Spacer()
}
.onAppear { .onAppear {
guard !disabled else { return } guard !disabled else { return }
toggleChecked = selected toggleChecked = selected
@ -24,6 +20,8 @@ struct MultiselectRow: View {
action(new) action(new)
} }
#else #else
Button(action: { action(!selected) }) {
HStack {
Text(self.title) Text(self.title)
Spacer() Spacer()
if selected { if selected {
@ -32,7 +30,6 @@ struct MultiselectRow: View {
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
#endif #endif
} }
#endif
} }
.contentShape(Rectangle()) .contentShape(Rectangle())
} }
@ -40,6 +37,7 @@ struct MultiselectRow: View {
#if !os(tvOS) #if !os(tvOS)
.buttonStyle(.plain) .buttonStyle(.plain)
#endif #endif
#endif
} }
} }

View File

@ -19,8 +19,8 @@ struct SponsorBlockSettings: View {
} }
#if os(tvOS) #if os(tvOS)
.frame(maxWidth: 1000) .frame(maxWidth: 1000)
#elseif os(iOS) #else
.listStyle(.insetGrouped) .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
#endif #endif
.navigationTitle("SponsorBlock") .navigationTitle("SponsorBlock")
} }
@ -106,5 +106,6 @@ struct SponsorBlockSettings_Previews: PreviewProvider {
VStack { VStack {
SponsorBlockSettings() SponsorBlockSettings()
} }
.frame(maxHeight: 600)
} }
} }