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
|
|
|
|
|
2020-10-01 00:28:08 +00:00
|
|
|
@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-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: {
|
2020-10-01 00:28:08 +00:00
|
|
|
presentationMode.dismiss()
|
2020-09-28 02:26:44 +00:00
|
|
|
}, label: {
|
|
|
|
Text("Done")
|
|
|
|
})
|
2020-09-30 22:14:38 +00:00
|
|
|
.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 {
|
2020-10-01 00:28:08 +00:00
|
|
|
PreferencesView()
|
2020-09-28 02:26:44 +00:00
|
|
|
}
|
|
|
|
}
|