Permalink
Browse files

Fix RCTRefreshControl jumping

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 2e1707d0e600a30057511390dd87c18c00f19a59
Showing with 8 additions and 5 deletions.
  1. +8 −5 React/Views/RCTRefreshControl.m
@@ -14,6 +14,7 @@
@implementation RCTRefreshControl {
BOOL _isInitialRender;
BOOL _currentRefreshingState;
BOOL _refreshingProgrammatically;
NSString *_title;
UIColor *_titleColor;
}
@@ -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};
@@ -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
@@ -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);

1 comment on commit 2e1707d

@vonovak

This comment has been minimized.

Contributor

vonovak commented on 2e1707d Jan 24, 2018

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

Please sign in to comment.