Skip to content

Commit

Permalink
clip content offset when scroll view is restored from shadow tree (fa…
Browse files Browse the repository at this point in the history
…cebook#44704)

Summary:
Pull Request resolved: facebook#44704

changelog: [internal]

Checkout the code comments for explanation.

Reviewed By: javache

Differential Revision: D57903106

fbshipit-source-id: 202edfa0b93ce222997ed793313cdc3ca32f8818
  • Loading branch information
sammy-SC authored and facebook-github-bot committed May 29, 2024
1 parent 690df7a commit 3c31e9d
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,26 @@ - (void)updateState:(const State::Shared &)state oldState:(const State::Shared &

auto contentOffset = RCTCGPointFromPoint(data.contentOffset);
if (!oldState && !CGPointEqualToPoint(contentOffset, CGPointZero)) {
/*
* When <ScrollView /> is suspended, it is removed from view hierarchy and its offset is stored in
* state. We want to restore this offset from the state but it must be snapped to be within UIScrollView's
* content to remove any overscroll.
*
* This can happen, for example, with pull to refresh. The UIScrollView will be overscrolled into negative offset.
* If the offset is not adjusted to be within the content area, it leads to a gap and UIScrollView does not adjust
* its offset until user scrolls.
*/

// Adjusting overscroll on the top.
contentOffset.y = fmax(contentOffset.y, -_scrollView.contentInset.top);

// Adjusting overscroll on the left.
contentOffset.x = fmax(contentOffset.x, -_scrollView.contentInset.left);

// TODO: T190695447 - Protect against over scroll on the bottom and right as well.
// This is not easily done because we need to flip the order of method calls for
// ShadowViewMutation::Insert. updateLayout must come before updateState.

_scrollView.contentOffset = contentOffset;
}

Expand Down

0 comments on commit 3c31e9d

Please sign in to comment.