From 335fdf317cf932774476e259f8653ab0e268b651 Mon Sep 17 00:00:00 2001 From: Shamali P Date: Tue, 26 Mar 2024 23:16:36 +0000 Subject: [PATCH] Fix issue that old search results list show up momentarily After exiting the search, we clear the search results and hide the results lists (because that recycler view shouldn't be accessible after it). However, it often doesn't get chance to layout the empty data. So, the next time we show the search results list again with new data, it first animates to clear the old results and then animates in the new ones. In this fix, [demo](http://screencast/cast/NDg5OTg2NzIyMTU1NzI0OHxhMTk0NzEzZS1hYw), we swap the adapter to remove any old views, because old search results aren't valid anymore. Spoke with yigit who worked on RV in past and they suggested swapAdapter was fine for this. Other options explored: 1. set item animator = null; so, it doesn't animate flushing out old results -> but we want animations 2. delay the visibility update to let layout happen -> but, if we are hiding the section, why wait making the other UI updates until layout? Bug: 274051332 Flag: N/A Test: Manual Change-Id: I9f9c5a67b47b5415b2d9e4caa23fd4b6daf7cdea (cherry picked from commit 809e1a8efbbc1cc299848133139ba2785951e6ff) --- .../android/launcher3/widget/picker/WidgetsFullSheet.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java index f5742af9f6..103ec572d2 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java @@ -541,6 +541,14 @@ public class WidgetsFullSheet extends BaseWidgetSheet public void exitSearchMode() { if (!mIsInSearchMode) return; onSearchResults(new ArrayList<>()); + WidgetsRecyclerView searchRecyclerView = mAdapters.get( + AdapterHolder.SEARCH).mWidgetsRecyclerView; + // Remove all views when exiting the search mode; this prevents animating from stale results + // to new ones the next time we enter search mode. By the time recycler view is hidden, + // layout may not have happened to clear up existing results. So, instead of waiting for it + // to happen, we clear the views here. + searchRecyclerView.swapAdapter( + searchRecyclerView.getAdapter(), /*removeAndRecycleExistingViews=*/ true); setViewVisibilityBasedOnSearch(/*isInSearchMode=*/ false); if (mHasWorkProfile) { mViewPager.snapToPage(AdapterHolder.PRIMARY);