From fe9d21f6fa4825b669201995b4590c208947015d Mon Sep 17 00:00:00 2001 From: Junhui Park Date: Mon, 1 Apr 2019 12:50:46 -0700 Subject: [PATCH] Fix setting the contentOffset value when refresh ends (#24191) Summary: It closes #24170. I opened the issue yesterday, and I think I found the way how to resolve it. So, I'm opening this PR directly without any comment on the issue. In the `endRefreshProgrammatically` of `RCTRefreshControl.m`, the comment says that " The contentOffset of the scrollview MUST be greater than 0". However, if the `contentInset` prop is set for the `FlatList`, I think `contentOffset` can be a negative value after refreshing and should be greater than `-contentInset.top`. As I reported the bug in that issue, If I am using `contentInset` prop to the `FlatList`, making `contentOffset` value be always 0 when refreshing ends causes something wrong situation. [iOS] [Fixed] - Fix setting the contnetOffset when refreshing ends Pull Request resolved: https://github.com/facebook/react-native/pull/24191 Differential Revision: D14710987 Pulled By: sahrens fbshipit-source-id: 03f06df9a93a2a46a7cc0b56269091778805917e --- React/Views/RCTRefreshControl.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/React/Views/RCTRefreshControl.m b/React/Views/RCTRefreshControl.m index 24090c83e4..26856be070 100644 --- a/React/Views/RCTRefreshControl.m +++ b/React/Views/RCTRefreshControl.m @@ -76,12 +76,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) - (void)endRefreshingProgrammatically { - // The contentOffset of the scrollview MUST be greater than 0 before calling + // The contentOffset of the scrollview MUST be greater than the contentInset before calling // endRefreshing otherwise the next pull to refresh will not work properly. UIScrollView *scrollView = (UIScrollView *)self.superview; - if (_refreshingProgrammatically && scrollView.contentOffset.y < 0) { + if (_refreshingProgrammatically && scrollView.contentOffset.y < -scrollView.contentInset.top) { UInt64 endRefreshingTimestamp = _currentRefreshingStateTimestamp; - CGPoint offset = {scrollView.contentOffset.x, 0}; + CGPoint offset = {scrollView.contentOffset.x, -scrollView.contentInset.top}; [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState