Add preference for hiding toolbars

This commit is contained in:
Shadowfacts 2021-10-02 11:12:20 -04:00
parent b313f37170
commit 86719b4528
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 34 additions and 4 deletions

View File

@ -111,6 +111,17 @@ class BrowserNavigationController: UIViewController {
.store(in: &cancellables) .store(in: &cancellables)
view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(panGestureRecognized))) view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(panGestureRecognized)))
Preferences.shared.$hideToolbarsWhenScrolling
.sink { [unowned self] (hideToolbarsWhenScrolling) in
if !hideToolbarsWhenScrolling {
// animate just in case the preference change came from another window and we're currently visible
UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseInOut) {
self.toolbarOffset = 0
}
}
}
.store(in: &cancellables)
} }
override func viewDidLayoutSubviews() { override func viewDidLayoutSubviews() {
@ -341,6 +352,7 @@ extension BrowserNavigationController {
extension BrowserNavigationController: UIScrollViewDelegate { extension BrowserNavigationController: UIScrollViewDelegate {
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
guard Preferences.shared.hideToolbarsWhenScrolling else { return }
trackingScroll = true trackingScroll = true
prevScrollViewContentOffset = scrollView.contentOffset prevScrollViewContentOffset = scrollView.contentOffset
scrollStartedBelowEnd = scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.bounds.height + scrollView.safeAreaInsets.bottom) scrollStartedBelowEnd = scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.bounds.height + scrollView.safeAreaInsets.bottom)

View File

@ -45,6 +45,10 @@ class Preferences: Codable, ObservableObject {
useInAppSafari = try container.decode(Bool.self, forKey: .useInAppSafari) useInAppSafari = try container.decode(Bool.self, forKey: .useInAppSafari)
useReaderMode = try container.decode(Bool.self, forKey: .useReaderMode) useReaderMode = try container.decode(Bool.self, forKey: .useReaderMode)
if let stored = try container.decodeIfPresent(Bool.self, forKey: .hideToolbarsWhenScrolling) {
hideToolbarsWhenScrolling = stored
}
} }
func encode(to encoder: Encoder) throws { func encode(to encoder: Encoder) throws {
@ -57,6 +61,8 @@ class Preferences: Codable, ObservableObject {
try container.encode(useInAppSafari, forKey: .useInAppSafari) try container.encode(useInAppSafari, forKey: .useInAppSafari)
try container.encode(useReaderMode, forKey: .useReaderMode) try container.encode(useReaderMode, forKey: .useReaderMode)
try container.encode(hideToolbarsWhenScrolling, forKey: .hideToolbarsWhenScrolling)
} }
@Published var homepage = AppDelegate.defaultHomepage @Published var homepage = AppDelegate.defaultHomepage
@ -67,6 +73,8 @@ class Preferences: Codable, ObservableObject {
@Published var useInAppSafari = false @Published var useInAppSafari = false
@Published var useReaderMode = false @Published var useReaderMode = false
@Published var hideToolbarsWhenScrolling = true
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case homepage case homepage
@ -75,6 +83,8 @@ class Preferences: Codable, ObservableObject {
case useInAppSafari case useInAppSafari
case useReaderMode case useReaderMode
case hideToolbarsWhenScrolling
} }
} }

View File

@ -20,6 +20,8 @@ struct PreferencesView: View {
appearanceSection appearanceSection
safariSection safariSection
behaviorSection
} }
.navigationBarTitle("Preferences") .navigationBarTitle("Preferences")
.insetOrGroupedListStyle() .insetOrGroupedListStyle()
@ -69,6 +71,12 @@ struct PreferencesView: View {
.disabled(!preferences.useInAppSafari) .disabled(!preferences.useInAppSafari)
} }
} }
private var behaviorSection: some View {
Section(header: Text("Behavior")) {
Toggle("Hide Toolbars When Scrolling", isOn: $preferences.hideToolbarsWhenScrolling)
}
}
} }
fileprivate extension View { fileprivate extension View {

View File

@ -7,7 +7,7 @@
<key>BrowserCore.xcscheme_^#shared#^_</key> <key>BrowserCore.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>3</integer> <integer>5</integer>
</dict> </dict>
<key>Gemini-iOS.xcscheme_^#shared#^_</key> <key>Gemini-iOS.xcscheme_^#shared#^_</key>
<dict> <dict>
@ -27,17 +27,17 @@
<key>GeminiIntents.xcscheme_^#shared#^_</key> <key>GeminiIntents.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>6</integer> <integer>3</integer>
</dict> </dict>
<key>GeminiProtocol.xcscheme_^#shared#^_</key> <key>GeminiProtocol.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>4</integer> <integer>6</integer>
</dict> </dict>
<key>GeminiRenderer.xcscheme_^#shared#^_</key> <key>GeminiRenderer.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>5</integer> <integer>4</integer>
</dict> </dict>
</dict> </dict>
<key>SuppressBuildableAutocreation</key> <key>SuppressBuildableAutocreation</key>