From 970af503ff264423caa9c0c2c2dd03a9d59fd299 Mon Sep 17 00:00:00 2001 From: Masayuki Iwai Date: Mon, 7 Aug 2017 12:11:45 +0900 Subject: [PATCH 1/7] Fix a bug with sticky headers don't stick at correct position. --- Libraries/Components/ScrollView/ScrollView.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 0d668a8eab6d48..abf0749206fb16 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -438,7 +438,8 @@ const ScrollView = createReactClass({ }, componentWillMount: function() { - this._scrollAnimatedValue = new Animated.Value(0); + this._scrollAnimatedValue = new Animated.Value(this.props.contentOffset ? this.props.contentOffset.y : 0); + this._scrollAnimatedValue.setOffset(this.props.contentInset ? this.props.contentInset.top : 0); this._stickyHeaderRefs = new Map(); this._headerLayoutYs = new Map(); }, From 44a5ec87d1c06f4fb52bb5602f62b9015f76a786 Mon Sep 17 00:00:00 2001 From: Masayuki Iwai Date: Mon, 7 Aug 2017 16:45:33 +0900 Subject: [PATCH 2/7] Support setting negative value for contentOffset. --- React/Views/RCTScrollView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index 6253599206cbc7..15821732cecf3b 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -317,8 +317,8 @@ - (void)setFrame:(CGRect)frame CGSize boundsSize = self.bounds.size; self.contentOffset = CGPointMake( - MAX(0, MIN(originalOffset.x, fullContentSize.width - boundsSize.width)), - MAX(0, MIN(originalOffset.y, fullContentSize.height - boundsSize.height))); + MAX(-contentInset.left, MIN(originalOffset.x, fullContentSize.width - boundsSize.width)), + MAX(-contentInset.top, MIN(originalOffset.y, fullContentSize.height - boundsSize.height))); } #if !TARGET_OS_TV From 7b60dfa124bbb51c5977409982bf4e2536783c0d Mon Sep 17 00:00:00 2001 From: Masayuki Iwai Date: Tue, 29 May 2018 11:15:19 +0900 Subject: [PATCH 3/7] Update _scrollAnimatedValue offset when ScrollView contentInset is updated. --- Libraries/Components/ScrollView/ScrollView.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 4b1b76848c7a7f..69b70460fda0f6 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -626,6 +626,13 @@ const ScrollView = createReactClass({ this._headerLayoutYs = new Map(); }, + UNSAFE_componentWillReceiveProps: function(nextProps: Props) { + this._scrollAnimatedValue.setOffset( + // $FlowFixMe + nextProps.contentInset ? nextProps.contentInset.top : 0, + ); + }, + componentDidMount: function() { this._updateAnimatedNodeAttachment(); }, From 8206a29a2c977be6223710d316b379db7ecc7ac6 Mon Sep 17 00:00:00 2001 From: Masayuki Iwai Date: Tue, 29 May 2018 11:15:19 +0900 Subject: [PATCH 4/7] Update _scrollAnimatedValue offset when ScrollView contentInset is updated. --- Libraries/Components/ScrollView/ScrollView.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 4b1b76848c7a7f..69b70460fda0f6 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -626,6 +626,13 @@ const ScrollView = createReactClass({ this._headerLayoutYs = new Map(); }, + UNSAFE_componentWillReceiveProps: function(nextProps: Props) { + this._scrollAnimatedValue.setOffset( + // $FlowFixMe + nextProps.contentInset ? nextProps.contentInset.top : 0, + ); + }, + componentDidMount: function() { this._updateAnimatedNodeAttachment(); }, From ea1323133aeb28650865e9fd4b535b4a9534f987 Mon Sep 17 00:00:00 2001 From: Masayuki Iwai Date: Tue, 26 Feb 2019 12:30:36 +0900 Subject: [PATCH 5/7] Invoke setOffset only when contentInset.top prop changed. --- Libraries/Components/ScrollView/ScrollView.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 8840c917bcde47..0640879592a236 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -659,10 +659,13 @@ class ScrollView extends React.Component { } UNSAFE_componentWillReceiveProps(nextProps: Props) { - this._scrollAnimatedValue.setOffset( - // $FlowFixMe - nextProps.contentInset ? nextProps.contentInset.top : 0, - ); + const currentContentInset = this.props.contentInset || {}; + const nextContentInset = nextProps.contentInset || {}; + if (currentContentInset.top !== nextContentInset.top) { + this._scrollAnimatedValue.setOffset( + nextContentInset.top || 0, + ); + } } componentDidMount() { From 86c8fb0d1d09f48101556d41cc9dc171f80b40da Mon Sep 17 00:00:00 2001 From: Masayuki Iwai Date: Tue, 26 Feb 2019 15:53:31 +0900 Subject: [PATCH 6/7] Fix format error. --- Libraries/Components/ScrollView/ScrollView.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 0640879592a236..bd5459a6c3a37c 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -662,9 +662,7 @@ class ScrollView extends React.Component { const currentContentInset = this.props.contentInset || {}; const nextContentInset = nextProps.contentInset || {}; if (currentContentInset.top !== nextContentInset.top) { - this._scrollAnimatedValue.setOffset( - nextContentInset.top || 0, - ); + this._scrollAnimatedValue.setOffset(nextContentInset.top || 0); } } From df80b387a043817ea4fa62ac58faeed6b9c9c6d5 Mon Sep 17 00:00:00 2001 From: Masayuki Iwai Date: Tue, 26 Feb 2019 17:49:23 +0900 Subject: [PATCH 7/7] Make not to create empty objects. --- Libraries/Components/ScrollView/ScrollView.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index bd5459a6c3a37c..dc166d41d54aed 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -659,10 +659,14 @@ class ScrollView extends React.Component { } UNSAFE_componentWillReceiveProps(nextProps: Props) { - const currentContentInset = this.props.contentInset || {}; - const nextContentInset = nextProps.contentInset || {}; - if (currentContentInset.top !== nextContentInset.top) { - this._scrollAnimatedValue.setOffset(nextContentInset.top || 0); + 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); } }