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

Commit

Permalink
Fixes #2939 - [iPad] The "Suggestion view" background is dismissed an…
Browse files Browse the repository at this point in the history
…d the website shortcuts are visible in the page view (#2943) (#2944)

(cherry picked from commit cb6b35d)

Co-authored-by: IORDAN RALUCA <[email protected]>
  • Loading branch information
mergify[bot] and rilury authored Jan 6, 2022
1 parent 3cee7be commit 44119db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Blockzilla/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions Blockzilla/ShortcutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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()
}
}

0 comments on commit 44119db

Please sign in to comment.