Fix sticky headers when rerendering

Summary:
There was an issue that sometimes sticky headers would stop moving when re-rendering because we did not reattach events properly. This makes sure that we always detach and reatach on rerender in case the scroll view ref changes.

**Test plan**
Tested that this fixes issues with sticky headers we discovered when updating Expo to RN 0.44.
Closes https://github.com/facebook/react-native/pull/14012

Differential Revision: D5094418

Pulled By: javache

fbshipit-source-id: a56050ae786712e8a3de2a6e3b4e8749a2fde86e
This commit is contained in:
Janic Duplessis 2017-05-19 03:28:13 -07:00 committed by Facebook Github Bot
parent add1c7e38c
commit 0518a0ba12
1 changed files with 8 additions and 11 deletions

View File

@ -490,18 +490,15 @@ const ScrollView = React.createClass({
},
_updateAnimatedNodeAttachment: function() {
if (this._scrollAnimatedValueAttachment) {
this._scrollAnimatedValueAttachment.detach();
}
if (this.props.stickyHeaderIndices && this.props.stickyHeaderIndices.length > 0) {
if (!this._scrollAnimatedValueAttachment) {
this._scrollAnimatedValueAttachment = Animated.attachNativeEvent(
this._scrollViewRef,
'onScroll',
[{nativeEvent: {contentOffset: {y: this._scrollAnimatedValue}}}]
);
}
} else {
if (this._scrollAnimatedValueAttachment) {
this._scrollAnimatedValueAttachment.detach();
}
this._scrollAnimatedValueAttachment = Animated.attachNativeEvent(
this._scrollViewRef,
'onScroll',
[{nativeEvent: {contentOffset: {y: this._scrollAnimatedValue}}}]
);
}
},