Skip to content

Commit

Permalink
Hide bar if user does any navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed May 9, 2024
1 parent 230e895 commit cb48a88
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ class MainViewController: UIViewController {

@IBAction func onFirePressed() {
Pixel.fire(pixel: .forgetAllPressedBrowsing)

hideNotificationBarIfBrokenSitePromptShown()
wakeLazyFireButtonAnimator()

if let spec = DaxDialogs.shared.fireButtonEducationMessage() {
Expand All @@ -807,7 +807,6 @@ class MainViewController: UIViewController {

func onQuickFirePressed() {
wakeLazyFireButtonAnimator()

forgetAllWithAnimation {}
dismiss(animated: true)
if KeyboardSettings().onAppLaunch {
Expand All @@ -823,12 +822,14 @@ class MainViewController: UIViewController {

@IBAction func onBackPressed() {
Pixel.fire(pixel: .tabBarBackPressed)
hideNotificationBarIfBrokenSitePromptShown()
currentTab?.goBack()
refreshOmniBar()
}

@IBAction func onForwardPressed() {
Pixel.fire(pixel: .tabBarForwardPressed)
hideNotificationBarIfBrokenSitePromptShown()
currentTab?.goForward()
}

Expand Down Expand Up @@ -1040,6 +1041,16 @@ class MainViewController: UIViewController {
refreshOmniBar()
}

private func hideNotificationBarIfBrokenSitePromptShown(afterRefresh: Bool = false) {
guard brokenSitePromptViewHostingController != nil,
let event = brokenSitePromptEvent?.rawValue else { return }
brokenSitePromptViewHostingController = nil
let pixel: Pixel.Event = afterRefresh ? .siteNotWorkingDismissByRefresh: .siteNotWorkingDismissByNavigation
Pixel.fire(pixel: .siteNotWorkingDismissByNavigation,
withAdditionalParameters: [UserBehaviorEvent.Parameter.event: event])
hideNotification()
}

fileprivate func refreshBackForwardButtons() {
viewCoordinator.toolbarBackButton.isEnabled = currentTab?.canGoBack ?? false
viewCoordinator.toolbarForwardButton.isEnabled = currentTab?.canGoForward ?? false
Expand Down Expand Up @@ -1277,7 +1288,11 @@ class MainViewController: UIViewController {
notificationView == nil,
!isPad,
DefaultTutorialSettings().hasSeenOnboarding else { return }
self.showBrokenSitePrompt(after: event)

// We're using async to ensure the view dismissal happens on the first runloop after a refresh. This prevents the scenario where the view briefly appears and then immediately disappears after a refresh.
DispatchQueue.main.async {
self.showBrokenSitePrompt(after: event)
}
}

private func showBrokenSitePrompt(after event: UserBehaviorEvent) {
Expand Down Expand Up @@ -1712,11 +1727,7 @@ extension MainViewController: OmniBarDelegate {
}
loadQuery(query)
hideSuggestionTray()
if brokenSitePromptViewHostingController != nil, let event = brokenSitePromptEvent?.rawValue {
Pixel.fire(pixel: .siteNotWorkingDismissByNavigation,
withAdditionalParameters: [UserBehaviorEvent.Parameter.event: event])
}
// hideNotification()
hideNotificationBarIfBrokenSitePromptShown()
showHomeRowReminder()
}

Expand Down Expand Up @@ -1870,17 +1881,13 @@ extension MainViewController: OmniBarDelegate {
homeController.launchNewSearch()
return selectQueryText
}

func onRefreshPressed() {
hideSuggestionTray()
currentTab?.refresh()
if brokenSitePromptViewHostingController != nil, let event = brokenSitePromptEvent?.rawValue {
// hideNotification()
Pixel.fire(pixel: .siteNotWorkingDismissByRefresh,
withAdditionalParameters: [UserBehaviorEvent.Parameter.event: event])
}
hideNotificationBarIfBrokenSitePromptShown(afterRefresh: true)
}

func onSharePressed() {
hideSuggestionTray()
guard let link = currentTab?.link else { return }
Expand Down Expand Up @@ -2059,7 +2066,7 @@ extension MainViewController: TabDelegate {
didRequestNewWebViewWithConfiguration configuration: WKWebViewConfiguration,
for navigationAction: WKNavigationAction,
inheritingAttribution: AdClickAttributionLogic.State?) -> WKWebView? {

hideNotificationBarIfBrokenSitePromptShown()
showBars()
currentTab?.dismiss()

Expand Down Expand Up @@ -2120,7 +2127,7 @@ extension MainViewController: TabDelegate {
openedByPage: Bool,
inheritingAttribution attribution: AdClickAttributionLogic.State?) {
_ = findInPageView.resignFirstResponder()

hideNotificationBarIfBrokenSitePromptShown()
if openedByPage {
showBars()
newTabAnimation {
Expand Down Expand Up @@ -2300,6 +2307,7 @@ extension MainViewController: TabSwitcherDelegate {
func closeTab(_ tab: Tab) {
guard let index = tabManager.model.indexOf(tab: tab) else { return }
hideSuggestionTray()
hideNotificationBarIfBrokenSitePromptShown()
tabManager.remove(at: index)
updateCurrentTab()
tabsBarController?.refresh(tabsModel: tabManager.model)
Expand Down Expand Up @@ -2341,7 +2349,7 @@ extension MainViewController: TabSwitcherButtonDelegate {
guard currentTab ?? tabManager.current(createIfNeeded: true) != nil else {
fatalError("Unable to get current tab")
}

hideNotificationBarIfBrokenSitePromptShown()
updatePreviewForCurrentTab {
ViewHighlighter.hideAll()
self.segueToTabSwitcher()
Expand Down

0 comments on commit cb48a88

Please sign in to comment.