Skip to content

Commit 2e1707d

Browse files
sophiebitsfacebook-github-bot
authored andcommitted
Fix RCTRefreshControl jumping
Reviewed By: shergin Differential Revision: D6470066 fbshipit-source-id: 44fb03c264d98af61dccfa0146690fd49ee9f2ab
1 parent 6e1db1f commit 2e1707d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Diff for: React/Views/RCTRefreshControl.m

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@implementation RCTRefreshControl {
1515
BOOL _isInitialRender;
1616
BOOL _currentRefreshingState;
17+
BOOL _refreshingProgrammatically;
1718
NSString *_title;
1819
UIColor *_titleColor;
1920
}
@@ -48,8 +49,9 @@ - (void)layoutSubviews
4849
_isInitialRender = false;
4950
}
5051

51-
- (void)beginRefreshing
52+
- (void)beginRefreshingProgrammatically
5253
{
54+
_refreshingProgrammatically = YES;
5355
// When using begin refreshing we need to adjust the ScrollView content offset manually.
5456
UIScrollView *scrollView = (UIScrollView *)self.superview;
5557
CGPoint offset = {scrollView.contentOffset.x, scrollView.contentOffset.y - self.frame.size.height};
@@ -66,12 +68,12 @@ - (void)beginRefreshing
6668
}];
6769
}
6870

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

125127
if (refreshing) {
126128
if (!_isInitialRender) {
127-
[self beginRefreshing];
129+
[self beginRefreshingProgrammatically];
128130
}
129131
} else {
130-
[self endRefreshing];
132+
[self endRefreshingProgrammatically];
131133
}
132134
}
133135
}
134136

135137
- (void)refreshControlValueChanged
136138
{
137139
_currentRefreshingState = super.refreshing;
140+
_refreshingProgrammatically = NO;
138141

139142
if (_onRefresh) {
140143
_onRefresh(nil);

0 commit comments

Comments
 (0)