From 0518a0ba12e7cafc8228be0455403cc23b055a79 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Fri, 19 May 2017 03:28:13 -0700 Subject: [PATCH] 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 --- Libraries/Components/ScrollView/ScrollView.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 723bcfa4f..4c5e66ae9 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -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}}}] + ); } },