Skip to content

Commit

Permalink
Merge branch 'brindy/page-position-fix-tweak' into brindy/pull-to-ref…
Browse files Browse the repository at this point in the history
…resh
  • Loading branch information
brindy committed Jan 18, 2024
2 parents 9fa7a41 + 250c48f commit 146d567
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 61 deletions.
19 changes: 0 additions & 19 deletions DuckDuckGo/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class MainViewFactory {
extension MainViewFactory {

private func createViews() {
createWebViewContainer()
createLogoBackground()
createContentContainer()
createSuggestionTrayContainer()
Expand All @@ -66,12 +65,6 @@ extension MainViewFactory {
createToolbar()
}

final class WebViewContainerView: UIView { }
private func createWebViewContainer() {
coordinator.webViewContainer = WebViewContainerView()
superview.addSubview(coordinator.webViewContainer)
}

private func createProgressView() {
coordinator.progress = ProgressView()
superview.addSubview(coordinator.progress)
Expand Down Expand Up @@ -163,7 +156,6 @@ extension MainViewFactory {
extension MainViewFactory {

private func constrainViews() {
constrainWebViewContainer()
constrainLogoBackground()
constrainContentContainer()
constrainSuggestionTrayContainer()
Expand All @@ -174,16 +166,6 @@ extension MainViewFactory {
constrainProgress()
constrainToolbar()
}

private func constrainWebViewContainer() {
let webViewContainer = coordinator.webViewContainer!
NSLayoutConstraint.activate([
webViewContainer.constrainView(superview, by: .width),
webViewContainer.constrainView(superview, by: .height),
webViewContainer.constrainView(superview, by: .centerX),
webViewContainer.constrainView(superview, by: .centerY),
])
}

private func constrainProgress() {
let progress = coordinator.progress!
Expand Down Expand Up @@ -351,7 +333,6 @@ class MainViewCoordinator {
var toolbarFireButton: UIBarButtonItem!
var toolbarForwardButton: UIBarButtonItem!
var toolbarTabSwitcherButton: UIBarButtonItem!
var webViewContainer: UIView!

let constraints = Constraints()

Expand Down
51 changes: 9 additions & 42 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ class MainViewController: UIViewController {
@objc func onAddressBarPositionChanged() {
viewCoordinator.moveAddressBarToPosition(appSettings.currentAddressBarPosition)
refreshViewsBasedOnAddressBarPosition(appSettings.currentAddressBarPosition)
refreshWebViewContentInsets()
}

func refreshViewsBasedOnAddressBarPosition(_ position: AddressBarPosition) {
Expand Down Expand Up @@ -479,7 +478,6 @@ class MainViewController: UIViewController {

findInPageBottomLayoutConstraint.constant = height
keyboardHeight = height
refreshWebViewContentInsets()

if let suggestionsTray = suggestionTrayController {
let suggestionsFrameInView = suggestionsTray.view.convert(suggestionsTray.contentFrame, to: view)
Expand Down Expand Up @@ -644,7 +642,7 @@ class MainViewController: UIViewController {
guard let tab = tabManager.current(createIfNeeded: true) else {
fatalError("Unable to create tab")
}
addToWebViewContainer(tab: tab)
attachTab(tab: tab)
refreshControls()
} else {
attachHomeScreen()
Expand Down Expand Up @@ -853,7 +851,7 @@ class MainViewController: UIViewController {
private func addTab(url: URL?, inheritedAttribution: AdClickAttributionLogic.State?) {
let tab = tabManager.add(url: url, inheritedAttribution: inheritedAttribution)
dismissOmniBar()
addToWebViewContainer(tab: tab)
attachTab(tab: tab)
}

func select(tabAt index: Int) {
Expand All @@ -867,7 +865,7 @@ class MainViewController: UIViewController {
if tab.link == nil {
attachHomeScreen()
} else {
addToWebViewContainer(tab: tab)
attachTab(tab: tab)
refreshControls()
}
tabsBarController?.refresh(tabsModel: tabManager.model, scrollToSelected: true)
Expand All @@ -876,21 +874,15 @@ class MainViewController: UIViewController {
}
}

private func addToWebViewContainer(tab: TabViewController) {
private func attachTab(tab: TabViewController) {
removeHomeScreen()
updateFindInPage()
currentTab?.progressWorker.progressBar = nil
currentTab?.chromeDelegate = nil
currentTab?.webView.scrollView.contentInsetAdjustmentBehavior = .never

addChild(tab)
viewCoordinator.webViewContainer.subviews.forEach { $0.removeFromSuperview() }
viewCoordinator.webViewContainer.addSubview(tab.view)
tab.view.frame = self.viewCoordinator.webViewContainer.bounds
tab.didMove(toParent: self)


addToContentContainer(controller: tab)

viewCoordinator.logoContainer.isHidden = true
viewCoordinator.contentContainer.isHidden = true

tab.progressWorker.progressBar = viewCoordinator.progress
chromeManager.attach(to: tab.webView.scrollView)
Expand Down Expand Up @@ -1338,35 +1330,11 @@ extension MainViewController: BrowserChromeDelegate {
}

if animated {
UIView.animate(withDuration: ChromeAnimationConstants.duration, animations: updateBlock) { _ in
self.refreshWebViewContentInsets()
}
UIView.animate(withDuration: ChromeAnimationConstants.duration, animations: updateBlock)
} else {
updateBlock()
self.refreshWebViewContentInsets()
}
}

func refreshWebViewContentInsets() {
guard let webView = currentTab?.webView else { return }

let top = viewCoordinator.statusBackground.frame.height
let bottom: CGFloat
if isToolbarHidden {
bottom = 0
} else if appSettings.currentAddressBarPosition.isBottom {
bottom = viewCoordinator.toolbar.frame.height
+ viewCoordinator.navigationBarContainer.frame.height
+ view.safeAreaInsets.bottom + additionalSafeAreaInsets.bottom
+ keyboardHeight
} else {
bottom = viewCoordinator.toolbar.frame.height
+ view.safeAreaInsets.bottom + additionalSafeAreaInsets.bottom
+ keyboardHeight
}

webView.scrollView.contentInset = .init(top: top, left: 0, bottom: bottom, right: 0)
}

func setNavigationBarHidden(_ hidden: Bool) {
if hidden { hideKeyboard() }
Expand Down Expand Up @@ -1733,7 +1701,7 @@ extension MainViewController: TabDelegate {
guard self.tabManager.model.tabs.contains(newTab.tabModel) else { return }

self.dismissOmniBar()
self.addToWebViewContainer(tab: newTab)
self.attachTab(tab: newTab)
self.refreshOmniBar()
}

Expand Down Expand Up @@ -1837,7 +1805,6 @@ extension MainViewController: TabDelegate {

func showBars() {
chromeManager.reset()
refreshWebViewContentInsets()
}

func tabDidRequestFindInPage(tab: TabViewController) {
Expand Down

0 comments on commit 146d567

Please sign in to comment.