diff --git a/React/Views/RCTRefreshControl.h b/React/Views/RCTRefreshControl.h index fa0a1b49473c4d..0218d13d217975 100644 --- a/React/Views/RCTRefreshControl.h +++ b/React/Views/RCTRefreshControl.h @@ -8,8 +8,9 @@ #import #import +#import -@interface RCTRefreshControl : UIRefreshControl +@interface RCTRefreshControl : UIRefreshControl @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) RCTDirectEventBlock onRefresh; diff --git a/React/Views/ScrollView/RCTScrollView.m b/React/Views/ScrollView/RCTScrollView.m index 58661fa78488a5..4afdb379d4a0de 100644 --- a/React/Views/ScrollView/RCTScrollView.m +++ b/React/Views/ScrollView/RCTScrollView.m @@ -155,7 +155,7 @@ @interface RCTCustomScrollView : UIScrollView @property (nonatomic, assign) BOOL centerContent; #if !TARGET_OS_TV -@property (nonatomic, strong) RCTRefreshControl *rctRefreshControl; +@property (nonatomic, strong) UIView *customRefreshControl; @property (nonatomic, assign) BOOL pinchGestureEnabled; #endif @@ -329,13 +329,13 @@ - (void)setFrame:(CGRect)frame } #if !TARGET_OS_TV -- (void)setRctRefreshControl:(RCTRefreshControl *)refreshControl +- (void)setCustomRefreshControl:(UIView *)refreshControl { - if (_rctRefreshControl) { - [_rctRefreshControl removeFromSuperview]; + if (_customRefreshControl) { + [_customRefreshControl removeFromSuperview]; } - _rctRefreshControl = refreshControl; - [self addSubview:_rctRefreshControl]; + _customRefreshControl = refreshControl; + [self addSubview:_customRefreshControl]; } - (void)setPinchGestureEnabled:(BOOL)pinchGestureEnabled @@ -443,13 +443,12 @@ - (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex { [super insertReactSubview:view atIndex:atIndex]; #if !TARGET_OS_TV - if ([view isKindOfClass:[RCTRefreshControl class]]) { - [_scrollView setRctRefreshControl:(RCTRefreshControl *)view]; - } - else if ([view conformsToProtocol:@protocol(UIScrollViewDelegate)]) { - [self addScrollListener:(UIView *)view]; - [_scrollView addSubview:view]; - [_scrollView sendSubviewToBack:view]; + if ([view conformsToProtocol:@protocol(RCTCustomRefreshContolProtocol)]) { + [_scrollView setCustomRefreshControl:(UIView *)view]; + if (![view isKindOfClass:[UIRefreshControl class]] + && [view conformsToProtocol:@protocol(UIScrollViewDelegate)]) { + [self addScrollListener:(UIView *)view]; + } } else #endif { @@ -464,11 +463,12 @@ - (void)removeReactSubview:(UIView *)subview { [super removeReactSubview:subview]; #if !TARGET_OS_TV - if ([subview isKindOfClass:[RCTRefreshControl class]]) { - [_scrollView setRctRefreshControl:nil]; - } else if ([subview conformsToProtocol:@protocol(UIScrollViewDelegate)]) { - [self removeScrollListener:(UIView *)subview]; - [subview removeFromSuperview]; + if ([subview conformsToProtocol:@protocol(RCTCustomRefreshContolProtocol)]) { + [_scrollView setCustomRefreshControl:nil]; + if (![subview isKindOfClass:[UIRefreshControl class]] + && [subview conformsToProtocol:@protocol(UIScrollViewDelegate)]) { + [self removeScrollListener:(UIView *)subview]; + } } else #endif { @@ -519,8 +519,8 @@ - (void)layoutSubviews #if !TARGET_OS_TV // Adjust the refresh control frame if the scrollview layout changes. - RCTRefreshControl *refreshControl = _scrollView.rctRefreshControl; - if (refreshControl && refreshControl.refreshing) { + UIView *refreshControl = _scrollView.customRefreshControl; + if (refreshControl && refreshControl.isRefreshing) { refreshControl.frame = (CGRect){_scrollView.contentOffset, {_scrollView.frame.size.width, refreshControl.frame.size.height}}; } #endif diff --git a/React/Views/ScrollView/RCTScrollableProtocol.h b/React/Views/ScrollView/RCTScrollableProtocol.h index 33ed067ec4acac..f0f512855fc52b 100644 --- a/React/Views/ScrollView/RCTScrollableProtocol.h +++ b/React/Views/ScrollView/RCTScrollableProtocol.h @@ -6,6 +6,7 @@ */ #import +#import /** * Contains any methods related to scrolling. Any `RCTView` that has scrolling @@ -28,3 +29,13 @@ - (void)removeScrollListener:(NSObject *)scrollListener; @end + +/** + * Denotes a view which implements custom pull to refresh functionality. + */ +@protocol RCTCustomRefreshContolProtocol + +@property (nonatomic, copy) RCTDirectEventBlock onRefresh; +@property (nonatomic, readonly, getter=isRefreshing) BOOL refreshing; + +@end