From a51561d8b834a3612b97fa811b49e9680c9bbdc3 Mon Sep 17 00:00:00 2001 From: dsn5ft <1420597+dsn5ft@users.noreply.github.com> Date: Wed, 27 Sep 2023 16:12:55 +0000 Subject: [PATCH] [SearchView][Predictive Back] Fix issue where predictive back is not enabled in SearchView after rotating the screen or restarting the activity when the SearchView is already expanded Resolves https://github.com/material-components/material-components-android/issues/3594 Resolves https://github.com/material-components/material-components-android/pull/3604 PiperOrigin-RevId: 568869369 --- lib/java/com/google/android/material/search/SearchView.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/java/com/google/android/material/search/SearchView.java b/lib/java/com/google/android/material/search/SearchView.java index 3a065c5ace8..da5a82c52e8 100644 --- a/lib/java/com/google/android/material/search/SearchView.java +++ b/lib/java/com/google/android/material/search/SearchView.java @@ -564,6 +564,7 @@ public void setupWithSearchBar(@Nullable SearchBar searchBar) { } updateNavigationIconIfNeeded(); setUpBackgroundViewElevationOverlay(); + updateListeningForBackCallbacks(getCurrentTransitionState()); } /** @@ -814,6 +815,10 @@ private void setTransitionState( listener.onStateChanged(this, previousState, state); } + updateListeningForBackCallbacks(state); + } + + private void updateListeningForBackCallbacks(@NonNull TransitionState state) { // Only automatically handle back if we have a search bar to collapse to, and if back handling // is enabled for the SearchView. if (searchBar != null && backHandlingEnabled) {