Merge "Fix NPE in RecyclerView" into sc-dev

This commit is contained in:
George Mount
2021-04-02 16:20:06 +00:00
committed by Android (Google) Code Review

View File

@@ -2049,17 +2049,19 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
}
if (!dispatchNestedPreFling(velocityX, velocityY)) {
final View firstChild = mLayout.getChildAt(0);
final View lastChild = mLayout.getChildAt(mLayout.getChildCount() - 1);
boolean consumed = false;
if (velocityY < 0) {
consumed = getChildAdapterPosition(firstChild) > 0
|| firstChild.getTop() < getPaddingTop();
}
if (mLayout.getChildCount() > 0) {
final View firstChild = mLayout.getChildAt(0);
final View lastChild = mLayout.getChildAt(mLayout.getChildCount() - 1);
if (velocityY < 0) {
consumed = getChildAdapterPosition(firstChild) > 0
|| firstChild.getTop() < getPaddingTop();
}
if (velocityY > 0) {
consumed = getChildAdapterPosition(lastChild) < mAdapter.getItemCount() - 1
|| lastChild.getBottom() > getHeight() - getPaddingBottom();
if (velocityY > 0) {
consumed = getChildAdapterPosition(lastChild) < mAdapter.getItemCount() - 1
|| lastChild.getBottom() > getHeight() - getPaddingBottom();
}
}
dispatchNestedFling(velocityX, velocityY, consumed);