-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UIRefreshControl added to scroll view #4205
Changes from all commits
888d4ac
6aaf3f8
e99fe6e
4da9972
6ce3254
37c24e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,7 @@ @interface RCTCustomScrollView : UIScrollView<UIGestureRecognizerDelegate> | |
|
||
@property (nonatomic, copy) NSIndexSet *stickyHeaderIndices; | ||
@property (nonatomic, assign) BOOL centerContent; | ||
@property (nonatomic, strong) UIRefreshControl *refreshControl; | ||
|
||
@end | ||
|
||
|
@@ -352,6 +353,15 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event | |
return hitView ?: [super hitTest:point withEvent:event]; | ||
} | ||
|
||
- (void)setRefreshControl:(UIRefreshControl *)refreshControl | ||
{ | ||
if (_refreshControl) { | ||
[_refreshControl removeFromSuperview]; | ||
} | ||
_refreshControl = refreshControl; | ||
[self addSubview:_refreshControl]; | ||
} | ||
|
||
@end | ||
|
||
@implementation RCTScrollView | ||
|
@@ -844,6 +854,34 @@ - (id)valueForUndefinedKey:(NSString *)key | |
return [_scrollView valueForKey:key]; | ||
} | ||
|
||
- (void)setOnRefreshStart:(RCTDirectEventBlock)onRefreshStart | ||
{ | ||
if (!onRefreshStart) { | ||
_onRefreshStart = nil; | ||
_scrollView.refreshControl = nil; | ||
return; | ||
} | ||
_onRefreshStart = [onRefreshStart copy]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably check if onRefreshStart is nil and remove the refreshControl if it is. Also, if onRefreshStart is not nil, and _scrollView.refreshControl is already not nil, there's no need to create and assign a new UIRefreshControl. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
|
||
if (!_scrollView.refreshControl) { | ||
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; | ||
[refreshControl addTarget:self action:@selector(refreshControlValueChanged) forControlEvents:UIControlEventValueChanged]; | ||
_scrollView.refreshControl = refreshControl; | ||
} | ||
} | ||
|
||
- (void)refreshControlValueChanged | ||
{ | ||
if (self.onRefreshStart) { | ||
self.onRefreshStart(nil); | ||
} | ||
} | ||
|
||
- (void)endRefreshing | ||
{ | ||
[_scrollView.refreshControl endRefreshing]; | ||
} | ||
|
||
@end | ||
|
||
@implementation RCTEventDispatcher (RCTScrollView) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use arrow functions instead of
bind