From cb6b35d276c9e97e572227d3a711a0199bb87398 Mon Sep 17 00:00:00 2001 From: IORDAN RALUCA Date: Thu, 6 Jan 2022 18:10:07 +0200 Subject: [PATCH] Fixes #2939 - [iPad] The "Suggestion view" background is dismissed and the website shortcuts are visible in the page view (#2943) --- Blockzilla/BrowserViewController.swift | 18 ++++++++++++++++++ Blockzilla/ShortcutView.swift | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/Blockzilla/BrowserViewController.swift b/Blockzilla/BrowserViewController.swift index 8ecd42fe05..1463d653bc 100644 --- a/Blockzilla/BrowserViewController.swift +++ b/Blockzilla/BrowserViewController.swift @@ -994,6 +994,16 @@ extension BrowserViewController: FindInPageBarDelegate { let escaped = text.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\"") webViewController.evaluate("__firefox__.\(function)(\"\(escaped)\")", completion: nil) } + + private func shortcutContextMenuIsOpenOnIpad() -> Bool { + var shortcutContextMenuIsDisplayed: Bool = false + for element in shortcutsContainer.subviews { + if let shortcut = element as? ShortcutView, shortcut.contextMenuIsDisplayed { + shortcutContextMenuIsDisplayed = true + } + } + return isIPadRegularDimensions && shortcutContextMenuIsDisplayed + } } extension BrowserViewController: URLBarDelegate { @@ -1101,6 +1111,8 @@ extension BrowserViewController: URLBarDelegate { } func urlBarDidDismiss(_ urlBar: URLBar) { + + guard !shortcutContextMenuIsOpenOnIpad() else { return } overlayView.dismiss() toggleURLBarBackground(isBright: !webViewController.isLoading) shortcutsContainer.isHidden = urlBar.inBrowsingMode @@ -1225,6 +1237,12 @@ extension BrowserViewController: UIAdaptivePresentationControllerDelegate { } extension BrowserViewController: ShortcutViewDelegate { + + func dismissShortcut() { + guard isIPadRegularDimensions else { return } + urlBarDidDismiss(urlBar) + } + func shortcutTapped(shortcut: Shortcut) { ensureBrowsingMode() urlBar.url = shortcut.url diff --git a/Blockzilla/ShortcutView.swift b/Blockzilla/ShortcutView.swift index 83ea0c973a..2404299841 100644 --- a/Blockzilla/ShortcutView.swift +++ b/Blockzilla/ShortcutView.swift @@ -10,9 +10,11 @@ import CoreHaptics protocol ShortcutViewDelegate: AnyObject { func shortcutTapped(shortcut: Shortcut) func removeFromShortcutsAction(shortcut: Shortcut) + func dismissShortcut() } class ShortcutView: UIView { + var contextMenuIsDisplayed = false private var shortcut: Shortcut weak var delegate: ShortcutViewDelegate? @@ -116,4 +118,13 @@ extension ShortcutView: UIContextMenuInteractionDelegate { return UIMenu(children: [removeFromShortcutsAction]) }) } + + func contextMenuInteraction(_ interaction: UIContextMenuInteraction, willDisplayMenuFor configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) { + contextMenuIsDisplayed = true + } + + func contextMenuInteraction(_ interaction: UIContextMenuInteraction, willEndFor configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) { + contextMenuIsDisplayed = false + self.delegate?.dismissShortcut() + } }