Skip to content

Commit

Permalink
Fix RCTRefreshControl jumping
Browse files Browse the repository at this point in the history
Reviewed By: shergin

Differential Revision: D6470066

fbshipit-source-id: 44fb03c264d98af61dccfa0146690fd49ee9f2ab
  • Loading branch information
sophiebits authored and facebook-github-bot committed Dec 4, 2017
1 parent 6e1db1f commit 2e1707d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions React/Views/RCTRefreshControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@implementation RCTRefreshControl {
BOOL _isInitialRender;
BOOL _currentRefreshingState;
BOOL _refreshingProgrammatically;
NSString *_title;
UIColor *_titleColor;
}
Expand Down Expand Up @@ -48,8 +49,9 @@ - (void)layoutSubviews
_isInitialRender = false;
}

- (void)beginRefreshing
- (void)beginRefreshingProgrammatically
{
_refreshingProgrammatically = YES;
// When using begin refreshing we need to adjust the ScrollView content offset manually.
UIScrollView *scrollView = (UIScrollView *)self.superview;
CGPoint offset = {scrollView.contentOffset.x, scrollView.contentOffset.y - self.frame.size.height};
Expand All @@ -66,12 +68,12 @@ - (void)beginRefreshing
}];
}

- (void)endRefreshing
- (void)endRefreshingProgrammatically
{
// The contentOffset of the scrollview MUST be greater than 0 before calling
// endRefreshing otherwise the next pull to refresh will not work properly.
UIScrollView *scrollView = (UIScrollView *)self.superview;
if (scrollView.contentOffset.y < 0) {
if (_refreshingProgrammatically && scrollView.contentOffset.y < 0) {
CGPoint offset = {scrollView.contentOffset.x, 0};
[UIView animateWithDuration:0.25
delay:0
Expand Down Expand Up @@ -124,17 +126,18 @@ - (void)setRefreshing:(BOOL)refreshing

if (refreshing) {
if (!_isInitialRender) {
[self beginRefreshing];
[self beginRefreshingProgrammatically];
}
} else {
[self endRefreshing];
[self endRefreshingProgrammatically];
}
}
}

- (void)refreshControlValueChanged
{
_currentRefreshingState = super.refreshing;
_refreshingProgrammatically = NO;

if (_onRefresh) {
_onRefresh(nil);
Expand Down

1 comment on commit 2e1707d

@vonovak
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit unfortunately broke RefreshControl on initial render. Fix is here #17727

Please sign in to comment.