mirror of
https://github.com/status-im/react-native.git
synced 2025-01-19 14:02:10 +00:00
Fixed OSS scroll view bug caused by FBPullToRefresh
Summary: When I bridged FBPullToRefresh to RN, the integration with ScrollView caused a bug on OSS TLDR; assuming that a scrollview subview that implemented UIScrollViewDelegate protocol was a custom PTR was a bad idea. This caused some scrollviews to break in OSS. The solution is to define a more explicit protocol. Further details here: https://github.com/facebook/react-native/issues/20324 Reviewed By: mmmulani Differential Revision: D8953893 fbshipit-source-id: 98cdc7fcced41d9e98e77293a03934f10c798665
This commit is contained in:
parent
1f545743b9
commit
fab5fffbb3
@ -8,8 +8,9 @@
|
|||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
#import <React/RCTComponent.h>
|
#import <React/RCTComponent.h>
|
||||||
|
#import <React/RCTScrollableProtocol.h>
|
||||||
|
|
||||||
@interface RCTRefreshControl : UIRefreshControl
|
@interface RCTRefreshControl : UIRefreshControl <RCTCustomRefreshContolProtocol>
|
||||||
|
|
||||||
@property (nonatomic, copy) NSString *title;
|
@property (nonatomic, copy) NSString *title;
|
||||||
@property (nonatomic, copy) RCTDirectEventBlock onRefresh;
|
@property (nonatomic, copy) RCTDirectEventBlock onRefresh;
|
||||||
|
@ -155,7 +155,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||||||
|
|
||||||
@property (nonatomic, assign) BOOL centerContent;
|
@property (nonatomic, assign) BOOL centerContent;
|
||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
@property (nonatomic, strong) RCTRefreshControl *rctRefreshControl;
|
@property (nonatomic, strong) UIView<RCTCustomRefreshContolProtocol> *customRefreshControl;
|
||||||
@property (nonatomic, assign) BOOL pinchGestureEnabled;
|
@property (nonatomic, assign) BOOL pinchGestureEnabled;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -329,13 +329,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
- (void)setRctRefreshControl:(RCTRefreshControl *)refreshControl
|
- (void)setCustomRefreshControl:(UIView<RCTCustomRefreshContolProtocol> *)refreshControl
|
||||||
{
|
{
|
||||||
if (_rctRefreshControl) {
|
if (_customRefreshControl) {
|
||||||
[_rctRefreshControl removeFromSuperview];
|
[_customRefreshControl removeFromSuperview];
|
||||||
}
|
}
|
||||||
_rctRefreshControl = refreshControl;
|
_customRefreshControl = refreshControl;
|
||||||
[self addSubview:_rctRefreshControl];
|
[self addSubview:_customRefreshControl];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setPinchGestureEnabled:(BOOL)pinchGestureEnabled
|
- (void)setPinchGestureEnabled:(BOOL)pinchGestureEnabled
|
||||||
@ -443,13 +443,12 @@ static inline void RCTApplyTransformationAccordingLayoutDirection(UIView *view,
|
|||||||
{
|
{
|
||||||
[super insertReactSubview:view atIndex:atIndex];
|
[super insertReactSubview:view atIndex:atIndex];
|
||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
if ([view isKindOfClass:[RCTRefreshControl class]]) {
|
if ([view conformsToProtocol:@protocol(RCTCustomRefreshContolProtocol)]) {
|
||||||
[_scrollView setRctRefreshControl:(RCTRefreshControl *)view];
|
[_scrollView setCustomRefreshControl:(UIView<RCTCustomRefreshContolProtocol> *)view];
|
||||||
}
|
if (![view isKindOfClass:[UIRefreshControl class]]
|
||||||
else if ([view conformsToProtocol:@protocol(UIScrollViewDelegate)]) {
|
&& [view conformsToProtocol:@protocol(UIScrollViewDelegate)]) {
|
||||||
[self addScrollListener:(UIView<UIScrollViewDelegate> *)view];
|
[self addScrollListener:(UIView<UIScrollViewDelegate> *)view];
|
||||||
[_scrollView addSubview:view];
|
}
|
||||||
[_scrollView sendSubviewToBack:view];
|
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@ -464,11 +463,12 @@ static inline void RCTApplyTransformationAccordingLayoutDirection(UIView *view,
|
|||||||
{
|
{
|
||||||
[super removeReactSubview:subview];
|
[super removeReactSubview:subview];
|
||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
if ([subview isKindOfClass:[RCTRefreshControl class]]) {
|
if ([subview conformsToProtocol:@protocol(RCTCustomRefreshContolProtocol)]) {
|
||||||
[_scrollView setRctRefreshControl:nil];
|
[_scrollView setCustomRefreshControl:nil];
|
||||||
} else if ([subview conformsToProtocol:@protocol(UIScrollViewDelegate)]) {
|
if (![subview isKindOfClass:[UIRefreshControl class]]
|
||||||
[self removeScrollListener:(UIView<UIScrollViewDelegate> *)subview];
|
&& [subview conformsToProtocol:@protocol(UIScrollViewDelegate)]) {
|
||||||
[subview removeFromSuperview];
|
[self removeScrollListener:(UIView<UIScrollViewDelegate> *)subview];
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@ -519,8 +519,8 @@ static inline void RCTApplyTransformationAccordingLayoutDirection(UIView *view,
|
|||||||
|
|
||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
// Adjust the refresh control frame if the scrollview layout changes.
|
// Adjust the refresh control frame if the scrollview layout changes.
|
||||||
RCTRefreshControl *refreshControl = _scrollView.rctRefreshControl;
|
UIView<RCTCustomRefreshContolProtocol> *refreshControl = _scrollView.customRefreshControl;
|
||||||
if (refreshControl && refreshControl.refreshing) {
|
if (refreshControl && refreshControl.isRefreshing) {
|
||||||
refreshControl.frame = (CGRect){_scrollView.contentOffset, {_scrollView.frame.size.width, refreshControl.frame.size.height}};
|
refreshControl.frame = (CGRect){_scrollView.contentOffset, {_scrollView.frame.size.width, refreshControl.frame.size.height}};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <React/RCTComponent.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains any methods related to scrolling. Any `RCTView` that has scrolling
|
* Contains any methods related to scrolling. Any `RCTView` that has scrolling
|
||||||
@ -28,3 +29,13 @@
|
|||||||
- (void)removeScrollListener:(NSObject<UIScrollViewDelegate> *)scrollListener;
|
- (void)removeScrollListener:(NSObject<UIScrollViewDelegate> *)scrollListener;
|
||||||
|
|
||||||
@end
|
@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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user