Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fixes #631 Scroll & constraint issues in BrowserViewController #894

Merged
merged 14 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,7 @@ class BrowserViewController: UIViewController {
webViewContainerTopOffset = make.top.equalTo(readerModeBar?.snp.bottom ?? self.header.snp.bottom).constraint

let findInPageHeight = (findInPageBar == nil) ? 0 : UIConstants.ToolbarHeight
if let toolbar = self.toolbar {
make.bottom.equalTo(toolbar.snp.top).offset(-findInPageHeight)
} else {
make.bottom.equalTo(self.view).offset(-findInPageHeight)
}
make.bottom.equalTo(self.footer.snp.top).offset(-findInPageHeight)
}

// Setup the bottom toolbar
Expand All @@ -681,6 +677,9 @@ class BrowserViewController: UIViewController {
footer.snp.remakeConstraints { make in
scrollController.footerBottomConstraint = make.bottom.equalTo(self.view.snp.bottom).constraint
make.leading.trailing.equalTo(self.view)
if self.toolbar == nil {
make.height.equalTo(0.0)
}
}

urlBar.setNeedsUpdateConstraints()
Expand All @@ -691,22 +690,16 @@ class BrowserViewController: UIViewController {
webViewContainerTopOffset = make.top.equalTo(readerModeBar?.snp.bottom ?? self.header.snp.bottom).constraint

make.left.right.equalTo(self.view)
if self.homePanelIsInline {
make.bottom.equalTo(self.toolbar?.snp.top ?? self.view.snp.bottom)
} else {
make.bottom.equalTo(self.view.snp.bottom)
}
make.bottom.equalTo(self.footer.snp.top)
}

alertStackView.snp.remakeConstraints { make in
make.centerX.equalTo(self.view)
make.width.equalTo(self.view.snp.width)
if let keyboardHeight = keyboardState?.intersectionHeightForView(self.view), keyboardHeight > 0 {
make.bottom.equalTo(self.view).offset(-keyboardHeight)
} else if let toolbar = self.toolbar {
make.bottom.equalTo(toolbar.snp.top)
} else {
make.bottom.equalTo(self.view)
make.bottom.equalTo(self.footer.snp.top)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Client/Frontend/Browser/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class Tab: NSObject {
configuration!.preferences = WKPreferences()
configuration!.preferences.javaScriptCanOpenWindowsAutomatically = false
configuration!.allowsInlineMediaPlayback = true
// Enables Zoom in website by ignoring their javascript based viewport Scale limits.
configuration!.ignoresViewportScaleLimits = true
let webView = TabWebView(frame: .zero, configuration: configuration!)
webView.delegate = self
Expand Down
28 changes: 5 additions & 23 deletions Client/Frontend/Browser/TabScrollController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class TabScrollingController: NSObject {
weak var tab: Tab? {
willSet {
self.scrollView?.delegate = nil
self.scrollView?.removeGestureRecognizer(panGesture)
self.scrollView?.panGestureRecognizer.removeTarget(self, action: nil)
}

didSet {
self.scrollView?.addGestureRecognizer(panGesture)
self.scrollView?.panGestureRecognizer.addTarget(self, action: #selector(handlePan))
scrollView?.delegate = self
}
}
Expand All @@ -52,7 +52,7 @@ class TabScrollingController: NSObject {

fileprivate var headerTopOffset: CGFloat = 0 {
didSet {
headerTopConstraint?.update(offset: headerTopOffset - tabsBarOffset)
headerTopConstraint?.update(offset: headerTopOffset)
header?.superview?.setNeedsLayout()
}
}
Expand All @@ -70,13 +70,6 @@ class TabScrollingController: NSObject {
}
}

fileprivate lazy var panGesture: UIPanGestureRecognizer = {
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan))
panGesture.maximumNumberOfTouches = 1
panGesture.delegate = self
return panGesture
}()

fileprivate var scrollView: UIScrollView? { return tab?.webView?.scrollView }
fileprivate var contentOffset: CGPoint { return scrollView?.contentOffset ?? .zero }
fileprivate var contentSize: CGSize { return scrollView?.contentSize ?? .zero }
Expand Down Expand Up @@ -251,20 +244,9 @@ private extension TabScrollingController {
}

func animateToolbarsWithOffsets(_ animated: Bool, duration: TimeInterval, headerOffset: CGFloat, footerOffset: CGFloat, alpha: CGFloat, completion: ((_ finished: Bool) -> Void)?) {
guard let scrollView = scrollView else { return }
let initialContentOffset = scrollView.contentOffset

// If this function is used to fully animate the toolbar from hidden to shown, keep the page from scrolling by adjusting contentOffset,
// Otherwise when the toolbar is hidden and a link navigated, showing the toolbar will scroll the page and
// produce a ~50px page jumping effect in response to tap navigations.
let isShownFromHidden = headerTopOffset == -topScrollHeight && headerOffset == 0

self.headerTopOffset = headerOffset
self.footerBottomOffset = footerOffset
let animation: () -> Void = {
if isShownFromHidden {
scrollView.contentOffset = CGPoint(x: initialContentOffset.x, y: initialContentOffset.y + self.topScrollHeight)
}
self.headerTopOffset = headerOffset + self.tabsBarOffset
self.footerBottomOffset = footerOffset
self.urlBar?.updateAlphaForSubviews(alpha)
self.tabsBar?.view.alpha = alpha
self.header?.superview?.layoutIfNeeded()
Expand Down