[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the offset calculation for adding item after the last item. #648

Open
wants to merge 1 commit into
base: androidx-main
Choose a base branch
from
Open
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
Modify the offset calculation for adding item after the last item.
When the focus is on the last item and an item is added before the focus item. If the previous item of the same row cannot be found, the offset of the adjacent previous item should be used directly. If found, the offset of the item should be added with the size of the item and space as the current offset.

Test: run locally, no crash
  • Loading branch information
goweii committed Jan 17, 2024
commit bf8fba5364117cf737468baa3100fee048337f67
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,15 @@ private int calculateOffsetAfterLastItem(int row) {
cachedIndex--;
}
if (!foundCachedItemInSameRow) {
// Just use the offset of last item.
cachedIndex = getLastIndex();
return getLocation(cachedIndex);
}
// Assuming the cachedIndex is next to item on the same row, so the
// sum of offset of [cachedIndex + 1, itemIndex] should be size of the
// cached item plus spacing.
int offset = isReversedFlow() ? -getLocation(cachedIndex).mSize - mSpacing :
getLocation(cachedIndex).mSize + mSpacing;
for (int i = cachedIndex + 1; i <= getLastIndex(); i++) {
offset -= getLocation(i).mOffset;
}
return offset;
// offset of itemIndex should be size of the cached item plus spacing.
final Location loc = getLocation(cachedIndex);
return isReversedFlow() ? loc.mOffset - loc.mSize - mSpacing :
loc.mOffset + loc.mSize + mSpacing;
}


Expand Down