mirror of
https://github.com/status-im/react-native.git
synced 2025-02-25 23:55:23 +00:00
API for cancelling RCTTouchHandler
Reviewed By: spicyj Differential Revision: D2846573 fb-gh-sync-id: 652864c773d03c24f0d68dd8335401eb052fc1bf
This commit is contained in:
parent
528e30987a
commit
c14cc123d5
@ -123,6 +123,25 @@ extern NSString *const RCTContentDidAppearNotification;
|
||||
*/
|
||||
@property (nonatomic, strong) UIView *loadingView;
|
||||
|
||||
/**
|
||||
* Calling this will result in emitting a "touches cancelled" event to js,
|
||||
* which effectively cancels all js "gesture recognizers" such as as touchable
|
||||
* (unless they explicitely ignore cancellation events, but noone should do that).
|
||||
*
|
||||
* This API is exposed for integration purposes where you embed RN rootView
|
||||
* in a native view with a native gesture recognizer,
|
||||
* whose activation should prevent any in-flight js "gesture recognizer" from activating.
|
||||
*
|
||||
* An example would be RN rootView embedded in an UIScrollView.
|
||||
* When you touch down on a touchable component and drag your finger up,
|
||||
* you don't want any touch to be registered as soon as the UIScrollView starts scrolling.
|
||||
*
|
||||
* Note that this doesn't help with tapping on a touchable element that is being scrolled,
|
||||
* unless you can call cancelTouches exactly between "touches began" and "touches ended" events.
|
||||
* This is a reason why this API may be soon removed in favor of a better solution.
|
||||
*/
|
||||
- (void)cancelTouches;
|
||||
|
||||
/**
|
||||
* Timings for hiding the loading view after the content has loaded. Both of
|
||||
* these values default to 0.25 seconds.
|
||||
|
@ -38,6 +38,8 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat
|
||||
|
||||
@property (nonatomic, readonly) BOOL contentHasAppeared;
|
||||
|
||||
@property (nonatomic, readonly, strong) RCTTouchHandler *touchHandler;
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame bridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@end
|
||||
@ -257,6 +259,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
||||
[_contentView invalidate];
|
||||
}
|
||||
|
||||
- (void)cancelTouches
|
||||
{
|
||||
[[_contentView touchHandler] cancel];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTUIManager (RCTRootView)
|
||||
@ -273,7 +280,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
||||
@implementation RCTRootContentView
|
||||
{
|
||||
__weak RCTBridge *_bridge;
|
||||
RCTTouchHandler *_touchHandler;
|
||||
UIColor *_backgroundColor;
|
||||
}
|
||||
|
||||
@ -335,7 +341,8 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder)
|
||||
* the react tag is assigned every time we load new content.
|
||||
*/
|
||||
self.reactTag = [_bridge.uiManager allocateRootTag];
|
||||
[self addGestureRecognizer:[[RCTTouchHandler alloc] initWithBridge:_bridge]];
|
||||
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:_bridge];
|
||||
[self addGestureRecognizer:_touchHandler];
|
||||
[_bridge.uiManager registerRootView:self];
|
||||
}
|
||||
|
||||
|
@ -16,5 +16,6 @@
|
||||
@interface RCTTouchHandler : UIGestureRecognizer
|
||||
|
||||
- (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
|
||||
- (void)cancel;
|
||||
|
||||
@end
|
||||
|
@ -311,4 +311,10 @@ static BOOL RCTAnyTouchesChanged(NSSet<UITouch *> *touches)
|
||||
_dispatchedInitialTouches = NO;
|
||||
}
|
||||
|
||||
- (void)cancel
|
||||
{
|
||||
self.enabled = NO;
|
||||
self.enabled = YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
x
Reference in New Issue
Block a user