Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,12 @@ private int getSpanGroupIndex(RecyclerView.Recycler recycler, RecyclerView.State
if (!state.isPreLayout()) {
return mSpanSizeLookup.getCachedSpanGroupIndex(viewPosition, mSpanCount);
}
if (viewPosition < 0 || viewPosition >= state.getItemCount()) {
// the position belongs to a layout that is already gone, as happens when the item is
// asked about from a content changed event dispatched while the list is being laid out
Log.w(TAG, "Cannot find span size for pre layout position. " + viewPosition);
return 0;
}
final int adapterPosition = recycler.convertPreLayoutPositionToPostLayout(viewPosition);
if (adapterPosition == -1) {
if (DEBUG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ public RecyclerViewAccessibilityDelegate(@NonNull RecyclerView recyclerView) {
}

boolean shouldIgnore() {
return mRecyclerView.hasPendingAdapterUpdates();
// item positions are only settled once a layout pass is over: asking the layout manager
// about them from inside one, as a content changed event dispatched from layout does,
// would read positions that no longer exist and throw. the pre layout check is needed on
// its own because that event is dispatched right after the layout counter is cleared
return mRecyclerView.hasPendingAdapterUpdates()
|| mRecyclerView.isComputingLayout()
|| mRecyclerView.mState.isPreLayout();
}

@Override
Expand Down