iOS: Assorted tweaks
This commit is contained in:
parent
cea2076244
commit
f5bb2ed2c3
|
@ -28,18 +28,21 @@ public struct BrowserView: View {
|
|||
|
||||
@ViewBuilder
|
||||
private var mainView: some View {
|
||||
VStack {
|
||||
switch state {
|
||||
case .loading:
|
||||
Spacer()
|
||||
loadingView
|
||||
.onAppear(perform: self.loadDocument)
|
||||
Spacer()
|
||||
case let .error(message):
|
||||
VStack {
|
||||
Text("An error occurred")
|
||||
.font(.headline)
|
||||
Text(message)
|
||||
}
|
||||
case let .document(doc):
|
||||
DocumentView(document: doc, scrollingEnabled: scrollingEnabled, changeURL: navigator.changeURL)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,8 +82,13 @@ public struct BrowserView: View {
|
|||
}
|
||||
|
||||
private func urlChanged(_ newValue: URL) {
|
||||
if case .loading = state {
|
||||
task?.cancel()
|
||||
loadDocument()
|
||||
} else {
|
||||
state = .loading
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension BrowserView {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import UIKit
|
||||
import SwiftUI
|
||||
import BrowserCore
|
||||
import Combine
|
||||
|
||||
class BrowserViewController: UIViewController, UIScrollViewDelegate {
|
||||
|
||||
|
@ -23,6 +24,8 @@ class BrowserViewController: UIViewController, UIScrollViewDelegate {
|
|||
|
||||
private var barAnimator: UIViewPropertyAnimator?
|
||||
|
||||
private var cancellables = [AnyCancellable]()
|
||||
|
||||
init(navigator: NavigationManager) {
|
||||
self.navigator = navigator
|
||||
|
||||
|
@ -40,6 +43,7 @@ class BrowserViewController: UIViewController, UIScrollViewDelegate {
|
|||
|
||||
scrollView = UIScrollView()
|
||||
scrollView.translatesAutoresizingMaskIntoConstraints = false
|
||||
scrollView.keyboardDismissMode = .interactive
|
||||
view.addSubview(scrollView)
|
||||
scrollView.delegate = self
|
||||
NSLayoutConstraint.activate([
|
||||
|
@ -62,7 +66,7 @@ class BrowserViewController: UIViewController, UIScrollViewDelegate {
|
|||
browserHost.view.widthAnchor.constraint(equalTo: view.widthAnchor),
|
||||
|
||||
// make sure the browser host view is at least the screen height so the loading indicator appears centered
|
||||
browserHost.view.heightAnchor.constraint(greaterThanOrEqualTo: view.safeAreaLayoutGuide.heightAnchor),
|
||||
browserHost.view.heightAnchor.constraint(greaterThanOrEqualTo: view.heightAnchor),
|
||||
])
|
||||
|
||||
navBarHost = UIHostingController(rootView: NavigationBar(navigator: navigator))
|
||||
|
@ -90,6 +94,14 @@ class BrowserViewController: UIViewController, UIScrollViewDelegate {
|
|||
toolBarHost.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
toolBarHost.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
|
||||
navigator.$currentURL
|
||||
.sink { (_) in
|
||||
self.scrollView.contentOffset = .zero
|
||||
self.navBarHost.view.transform = .identity
|
||||
self.toolBarHost.view.transform = .identity
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
override func viewDidLayoutSubviews() {
|
||||
|
@ -116,7 +128,9 @@ class BrowserViewController: UIViewController, UIScrollViewDelegate {
|
|||
|
||||
// When certain state changes happen, the scroll view seems to "scroll" by top the safe area inset.
|
||||
// It's not actually user scrolling, and this screws up our animation, so we ignore it.
|
||||
guard abs(scrollViewDelta) != view.safeAreaInsets.top, scrollViewDelta != 0 else { return }
|
||||
guard abs(scrollViewDelta) != view.safeAreaInsets.top,
|
||||
scrollViewDelta != 0,
|
||||
scrollView.contentOffset.y > 0 else { return }
|
||||
|
||||
let barAnimator: UIViewPropertyAnimator
|
||||
if let animator = self.barAnimator {
|
||||
|
|
|
@ -33,6 +33,9 @@ struct NavigationBar: View {
|
|||
.foregroundColor(Color(white: colorScheme == .dark ? 0.25 : 0.75))
|
||||
}
|
||||
.background(Color(UIColor.systemBackground).edgesIgnoringSafeArea(.top))
|
||||
.onReceive(navigator.$currentURL) { (newURL) in
|
||||
urlFieldContents = newURL.absoluteString
|
||||
}
|
||||
}
|
||||
|
||||
private func commitURL() {
|
||||
|
|
|
@ -66,6 +66,8 @@ struct ToolBar: View {
|
|||
|
||||
Spacer()
|
||||
}
|
||||
|
||||
Spacer(minLength: 4)
|
||||
}
|
||||
.background(Color(UIColor.systemBackground).edgesIgnoringSafeArea(.bottom))
|
||||
.sheet(isPresented: $showPreferencesSheet, content: {
|
||||
|
|
Loading…
Reference in New Issue