Gemini/Gemini-iOS/PreferencesView.swift

79 lines
2.0 KiB
Swift

//
// PreferencesView.swift
// Gemini-iOS
//
// Created by Shadowfacts on 9/27/20.
//
import SwiftUI
struct PreferencesView: View {
let dismiss: () -> Void
@ObservedObject var preferences: Preferences = .shared
var body: some View {
NavigationView {
List {
appearanceSection
safariSection
}
.navigationBarTitle("Preferences")
.insetOrGroupedListStyle()
.navigationBarItems(trailing: doneButton)
}
.navigationViewStyle(StackNavigationViewStyle())
.onDisappear {
Preferences.save()
}
}
private var doneButton: some View {
Button(action: {
dismiss()
}, label: {
Text("Done")
})
.hoverEffect(.highlight)
}
private var appearanceSection: some View {
Section(header: Text("Appearance")) {
Picker(selection: $preferences.theme, label: Text("Theme")) {
Text("Use System Theme").tag(UIUserInterfaceStyle.unspecified)
Text("Always Light").tag(UIUserInterfaceStyle.light)
Text("Always Dark").tag(UIUserInterfaceStyle.dark)
}
}
}
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(dismiss: {})
}
}