Skip to content

Commit

Permalink
Account for diffrent frame size when using maintainVisibleContentPosi…
Browse files Browse the repository at this point in the history
…tion in virtualized lists (#46979)

Summary:
Pull Request resolved: #46979

It seems that, when the items in a virtualized list don't have a fixed size (i.e. they dynamically scale with the size of the container), we need to also take into account their size when updating the scroll position as a consequense of setting `maintainVisibleContentPosition`.

Changelog:
[Android][Fixed] - Account for items dynamically scaling with the container when using `maintainVisibleContentPosition` in virtualized lists

Reviewed By: javache, NickGerleman

Differential Revision: D64238887

fbshipit-source-id: 9f05a461d178bc191137b1a350072337ba62e224
  • Loading branch information
fabriziocucci authored and facebook-github-bot committed Oct 14, 2024
1 parent b527177 commit 6c19996
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ private void updateScrollPositionInternal() {
firstVisibleView.getHitRect(newFrame);

if (mHorizontal) {
int deltaX = newFrame.left - mPrevFirstVisibleFrame.left;
int deltaX =
(newFrame.left - mPrevFirstVisibleFrame.left)
+ (newFrame.width() - mPrevFirstVisibleFrame.width());
if (deltaX != 0) {
int scrollX = mScrollView.getScrollX();
mScrollView.scrollToPreservingMomentum(scrollX + deltaX, mScrollView.getScrollY());
Expand All @@ -126,7 +128,9 @@ private void updateScrollPositionInternal() {
}
}
} else {
int deltaY = newFrame.top - mPrevFirstVisibleFrame.top;
int deltaY =
(newFrame.top - mPrevFirstVisibleFrame.top)
+ (newFrame.height() - mPrevFirstVisibleFrame.height());
if (deltaY != 0) {
int scrollY = mScrollView.getScrollY();
mScrollView.scrollToPreservingMomentum(mScrollView.getScrollX(), scrollY + deltaY);
Expand Down

0 comments on commit 6c19996

Please sign in to comment.