Updating the scroll calculation from recyclerView to avoid view inflation

> Updating the LayoutManager's scroll calculation instead of a separate
  implementation to better support recyclerView's calculations
> Caching the view sizes during layout to avoid view-inflation for
  unknown types
> Fixing scrollbar jump during scroll when widget list is expanded
> Fixing scrollbar never reaching end when onboarding card is displayed
  in work tab

Bug: 240343082
Test: Verified on device that new views are not inflated
Change-Id: Ied11ccf65b053691c5c126c4bf8de306ec24786d
This commit is contained in:
Sunny Goyal
2022-07-26 16:38:19 -07:00
parent 676d19c171
commit 20bbe95ddb
12 changed files with 212 additions and 211 deletions

View File

@@ -26,7 +26,9 @@ import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.core.view.accessibility.AccessibilityRecordCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.Adapter;
import com.android.launcher3.util.ScrollableLayoutManager;
import com.android.launcher3.views.ActivityContext;
import java.util.List;
@@ -62,10 +64,10 @@ public class AllAppsGridAdapter<T extends Context & ActivityContext> extends
/**
* A subclass of GridLayoutManager that overrides accessibility values during app search.
*/
public class AppsGridLayoutManager extends GridLayoutManager {
public class AppsGridLayoutManager extends ScrollableLayoutManager {
public AppsGridLayoutManager(Context context) {
super(context, 1, GridLayoutManager.VERTICAL, false);
super(context);
}
@Override
@@ -125,6 +127,15 @@ public class AllAppsGridAdapter<T extends Context & ActivityContext> extends
}
return extraRows;
}
@Override
protected int incrementTotalHeight(Adapter adapter, int position, int heightUntilLastPos) {
AllAppsGridAdapter.AdapterItem item = mApps.getAdapterItems().get(position);
// only account for the first icon in the row since they are the same size within a row
return (isIconViewType(item.viewType) && item.rowAppIndex != 0)
? heightUntilLastPos
: (heightUntilLastPos + mCachedSizes.get(item.viewType));
}
}
@Override