Gemini/Gemini-iOS/PreferencesView.swift

62 lines
1.4 KiB
Swift

//
// PreferencesView.swift
// Gemini-iOS
//
// Created by Shadowfacts on 9/27/20.
//
import SwiftUI
struct PreferencesView: View {
@ObservedObject var preferences: Preferences = .shared
@Binding var presented: Bool
var body: some View {
NavigationView {
List {
safariSection
}
.navigationBarTitle("Preferences")
.insetOrGroupedListStyle()
.navigationBarItems(trailing: doneButton)
}
}
private var doneButton: some View {
Button(action: {
presented = false
}, label: {
Text("Done")
})
}
private var safariSection: some View {
Section(header: Text("Safari")) {
Toggle("Use In-App Safari", isOn: $preferences.useInAppSafari)
Toggle("Use Reader Mode", isOn: $preferences.useReaderMode)
.disabled(!preferences.useInAppSafari)
}
}
}
fileprivate extension View {
@ViewBuilder
func insetOrGroupedListStyle() -> some View {
if #available(iOS 14.0, *) {
self.listStyle(InsetGroupedListStyle())
} else {
self.listStyle(GroupedListStyle())
}
}
}
struct PreferencesView_Previews: PreviewProvider {
@State static var presented = true
static var previews: some View {
PreferencesView(presented: $presented)
}
}