Gemini/Gemini-iOS/PreferencesView.swift

101 lines
2.6 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 {
let dismiss: () -> Void
2020-09-28 02:26:44 +00:00
@ObservedObject var preferences: Preferences = .shared
2020-09-28 02:26:44 +00:00
var body: some View {
NavigationView {
List {
2021-06-16 03:21:22 +00:00
untitledSection
2020-09-30 03:44:44 +00:00
appearanceSection
2020-09-28 02:26:44 +00:00
safariSection
2021-10-02 15:12:20 +00:00
behaviorSection
2020-09-28 02:26:44 +00:00
}
.navigationBarTitle("Preferences")
.insetOrGroupedListStyle()
.navigationBarItems(trailing: doneButton)
}
2021-06-16 03:21:22 +00:00
.navigationViewStyle(.stack)
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: {
dismiss()
2020-09-28 02:26:44 +00:00
}, label: {
Text("Done")
})
.hoverEffect(.highlight)
2020-09-28 02:26:44 +00:00
}
2021-06-16 03:21:22 +00:00
private var untitledSection: some View {
Section {
NavigationLink(destination: HomepagePrefView()) {
Text("Homepage")
}
}
}
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)
}
2021-06-16 02:42:16 +00:00
Toggle("Show Link Icons", isOn: $preferences.showLinkIcons)
2020-09-30 03:44:44 +00:00
}
}
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)
}
}
2021-10-02 15:12:20 +00:00
private var behaviorSection: some View {
Section(header: Text("Behavior")) {
2021-10-02 15:18:38 +00:00
Toggle("Pull to Refresh", isOn: $preferences.pullToRefreshEnabled)
2021-10-02 15:12:20 +00:00
Toggle("Hide Toolbars When Scrolling", isOn: $preferences.hideToolbarsWhenScrolling)
}
}
2020-09-28 02:26:44 +00:00
}
fileprivate extension View {
@ViewBuilder
func insetOrGroupedListStyle() -> some View {
if #available(iOS 14.0, *) {
2021-06-16 03:21:22 +00:00
self.listStyle(.insetGrouped)
2020-09-28 02:26:44 +00:00
} else {
2021-06-16 03:21:22 +00:00
self.listStyle(.grouped)
2020-09-28 02:26:44 +00:00
}
}
}
struct PreferencesView_Previews: PreviewProvider {
@State static var presented = true
static var previews: some View {
PreferencesView(dismiss: {})
2020-09-28 02:26:44 +00:00
}
}