Gemini/Gemini-iOS/PreferencesView.swift

92 lines
2.3 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
}
.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)
}
}
}
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
}
}