Skip to content

Commit

Permalink
In onLayoutChange, only scroll if the view is shown and the content v…
Browse files Browse the repository at this point in the history
…iew is ready

Summary:
ScrollViews don't properly maintain position where they are hidden and shown. When a ScrollView's content is laid out, onLayoutChange is triggered. This is also fired when the views are hidden, which is not desirable as the layout may not be accurate when the view is hidden. Check that the scroll view is showing before attempting a scroll.

Changelog:
[Internal][Fixed] - In onLayoutChange, only scroll if the view is shown and the content view is ready

Reviewed By: sshic

Differential Revision: D42808119

fbshipit-source-id: 0197ae55fa7d80e52c2ea483609e62d512a117f3
  • Loading branch information
genkikondo authored and facebook-github-bot committed Jan 30, 2023
1 parent 9e65ba2 commit 115dbe9
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1127,10 +1127,12 @@ public void onLayoutChange(
mMaintainVisibleContentPositionHelper.updateScrollPosition();
}

int currentScrollY = getScrollY();
int maxScrollY = getMaxScrollY();
if (currentScrollY > maxScrollY) {
scrollTo(getScrollX(), maxScrollY);
if (isShown() && isContentReady()) {
int currentScrollY = getScrollY();
int maxScrollY = getMaxScrollY();
if (currentScrollY > maxScrollY) {
scrollTo(getScrollX(), maxScrollY);
}
}
}

Expand Down

0 comments on commit 115dbe9

Please sign in to comment.