From 38cde2c6282cbe8650590352b51ef7824fa2bc80 Mon Sep 17 00:00:00 2001
From: Louis Romero <lpromero@google.com>
Date: Fri, 5 Jan 2024 16:36:58 +0000
Subject: [PATCH] Dismiss the keyboard when dragging Tab Grid search results

This CL dismisses the keyboard as soon as the scrollview with the search
results is scrolled.

Prior to the new Compositional Layout, this was not an issue, as there
was a bug where the Suggested Actions had a way too large height,
leading to the Suggested Actions not being able to be occluded by the
keyboard. But the Compositional Layout gives it its correct height,
leaving it hidden behind the keyboard.

An alternative fix would be to subscribe to the keyboard notifications,
and adapt the scroll view's additional safe area insets but it's more
cumbersome.

Fixed: 1515895
Change-Id: I411b5bb0deb9fa62e4e43805a2eb5d2601da891e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5172556
Reviewed-by: Aliona Dangla <alionadangla@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Auto-Submit: Louis Romero <lpromero@google.com>
Commit-Queue: Aliona Dangla <alionadangla@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1243454}
---
 .../ui/tab_switcher/tab_grid/grid/base_grid_view_controller.mm   | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/base_grid_view_controller.mm b/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/base_grid_view_controller.mm
index 02544d8779ae1..3301fea1e5050 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/base_grid_view_controller.mm
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/base_grid_view_controller.mm
@@ -244,6 +244,7 @@ NSString* GroupGridCellAccessibilityIdentifier(NSUInteger index) {
   // collectionView contentInset manually to fit in the safe area instead.
   collectionView.contentInsetAdjustmentBehavior =
       UIScrollViewContentInsetAdjustmentNever;
+  collectionView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
   self.collectionView = collectionView;
   self.view = collectionView;