Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert using content insets to fix page position problem #2356

Merged
merged 2 commits into from
Jan 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
{
"identity" : "trackerradarkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/TrackerRadarKit",
"location" : "https://github.com/duckduckgo/TrackerRadarKit.git",
"state" : {
"revision" : "a6b7ba151d9dc6684484f3785293875ec01cc1ff",
"version" : "1.2.2"
Expand Down
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
Loading