From 394d238bbc555d3e6c59f9bb672e586b4af58a2b Mon Sep 17 00:00:00 2001 From: Carson Ramsden Date: Mon, 16 Dec 2024 10:51:47 -0700 Subject: [PATCH] Refactor FXIOS-10541 [Homepage Rebuild] Add keyboard dismissal logic to new homepage (#23759) * Add tap gesture recognizer to dismiss keyboard * move gesture recognizer to view did load instead of init --- .../HomepageViewController.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/firefox-ios/Client/Frontend/Home/Homepage Rebuild/HomepageViewController.swift b/firefox-ios/Client/Frontend/Home/Homepage Rebuild/HomepageViewController.swift index 48974129e917..94a2491e5bd3 100644 --- a/firefox-ios/Client/Frontend/Home/Homepage Rebuild/HomepageViewController.swift +++ b/firefox-ios/Client/Frontend/Home/Homepage Rebuild/HomepageViewController.swift @@ -108,6 +108,7 @@ final class HomepageViewController: UIViewController, listenForThemeChange(view) applyTheme() + addTapGestureRecognizerToDismissKeyboard() } override func viewWillAppear(_ animated: Bool) { @@ -452,13 +453,27 @@ final class HomepageViewController: UIViewController, } } + // MARK: Tap Geasutre Recognizer + private func addTapGestureRecognizerToDismissKeyboard() { + // We want any interaction with the homepage to dismiss the keyboard, including taps + let tap = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) + tap.cancelsTouchesInView = false + view.addGestureRecognizer(tap) + } + + @objc + private func dismissKeyboard() { + let action = ToolbarAction(windowUUID: windowUUID, actionType: ToolbarActionType.cancelEdit) + store.dispatch(action) + } + // MARK: Long Press (Photon Action Sheet) private lazy var longPressRecognizer: UILongPressGestureRecognizer = { return UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress)) }() @objc - fileprivate func handleLongPress(_ longPressGestureRecognizer: UILongPressGestureRecognizer) { + private func handleLongPress(_ longPressGestureRecognizer: UILongPressGestureRecognizer) { guard longPressGestureRecognizer.state == .began else { return } // TODO: FXIOS-10613 - Pass proper action data to context menu navigateToContextMenu()