Fix RCTRefreshControl jumping

Reviewed By: shergin

Differential Revision: D6470066

fbshipit-source-id: 44fb03c264d98af61dccfa0146690fd49ee9f2ab
This commit is contained in:
Sophie Alpert 2017-12-03 16:03:38 -08:00 committed by Facebook Github Bot
parent 6e1db1f1ee
commit 2e1707d0e6
1 changed files with 8 additions and 5 deletions

View File

@ -14,6 +14,7 @@
@implementation RCTRefreshControl {
BOOL _isInitialRender;
BOOL _currentRefreshingState;
BOOL _refreshingProgrammatically;
NSString *_title;
UIColor *_titleColor;
}
@ -48,8 +49,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
_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 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
}];
}
- (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,10 +126,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
if (refreshing) {
if (!_isInitialRender) {
[self beginRefreshing];
[self beginRefreshingProgrammatically];
}
} else {
[self endRefreshing];
[self endRefreshingProgrammatically];
}
}
}
@ -135,6 +137,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
- (void)refreshControlValueChanged
{
_currentRefreshingState = super.refreshing;
_refreshingProgrammatically = NO;
if (_onRefresh) {
_onRefresh(nil);