Skip to content

Commit

Permalink
Update _scrollAnimatedValue offset of ScrollViews. (#19481)
Browse files Browse the repository at this point in the history
Summary:
`_scrollAnimatedValue` offset of ScrollView is set once in `UNSAFE_componentWillMount` but it is never updated.
It causes unexpected render result.

![rn-scrollview-fix1](https://user-images.githubusercontent.com/143255/40640292-61843eca-6350-11e8-9412-f5383ea65ea0.gif)

So I suggest to update `_scrollAnimatedValue` offset when ScrollView contentInset is updated.
Pull Request resolved: #19481

Differential Revision: D14223304

Pulled By: cpojer

fbshipit-source-id: 4191cfcf6414adf3a0abd156517d5f9778565671
  • Loading branch information
miyabi authored and facebook-github-bot committed Feb 26, 2019
1 parent 14d9b2d commit 58c9567
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,18 @@ class ScrollView extends React.Component<Props, State> {
this._headerLayoutYs = new Map();
}

UNSAFE_componentWillReceiveProps(nextProps: Props) {
const currentContentInsetTop = this.props.contentInset
? this.props.contentInset.top
: 0;
const nextContentInsetTop = nextProps.contentInset
? nextProps.contentInset.top
: 0;
if (currentContentInsetTop !== nextContentInsetTop) {
this._scrollAnimatedValue.setOffset(nextContentInsetTop || 0);
}
}

componentDidMount() {
this._updateAnimatedNodeAttachment();
}
Expand Down

0 comments on commit 58c9567

Please sign in to comment.