From e0d1b3ab84cff848b61bb8bef53a890a7e1f92d3 Mon Sep 17 00:00:00 2001 From: Masayuki Iwai Date: Tue, 26 Feb 2019 01:38:11 -0800 Subject: [PATCH] Update _scrollAnimatedValue offset of ScrollViews. (#19481) 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: https://github.com/facebook/react-native/pull/19481 Differential Revision: D14223304 Pulled By: cpojer fbshipit-source-id: 4191cfcf6414adf3a0abd156517d5f9778565671 --- Libraries/Components/ScrollView/ScrollView.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index ece14320a2e..942cb73b7b6 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -662,6 +662,18 @@ class ScrollView extends React.Component { 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(); }