Gemini/Gemini-iOS/PreferencesView.swift

79 lines
2.1 KiB
Swift
Raw Normal View History

2020-09-28 02:26:44 +00:00
//
// PreferencesView.swift
// Gemini-iOS
//
// Created by Shadowfacts on 9/27/20.
//
import SwiftUI
struct PreferencesView: View {
@ObservedObject var preferences: Preferences = .shared
@Environment(\.presentationMode) @Binding var presentationMode: PresentationMode
2020-09-28 02:26:44 +00:00
var body: some View {
NavigationView {
List {
2020-09-30 03:44:44 +00:00
appearanceSection
2020-09-28 02:26:44 +00:00
safariSection
}
.navigationBarTitle("Preferences")
.insetOrGroupedListStyle()
.navigationBarItems(trailing: doneButton)
}
2020-12-20 19:09:18 +00:00
.navigationViewStyle(StackNavigationViewStyle())
2020-09-29 19:29:12 +00:00
.onDisappear {
Preferences.save()
}
2020-09-28 02:26:44 +00:00
}
private var doneButton: some View {
Button(action: {
presentationMode.dismiss()
2020-09-28 02:26:44 +00:00
}, label: {
Text("Done")
})
.hoverEffect(.highlight)
2020-09-28 02:26:44 +00:00
}
2020-09-30 03:44:44 +00:00
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)
}
}
}
2020-09-28 02:26:44 +00:00
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()
2020-09-28 02:26:44 +00:00
}
}