Skip to content

Commit

Permalink
Fix ManualGestureHandler shouldCancelWhenOutside on iOS (#2274)
Browse files Browse the repository at this point in the history
## Description

This PR adds changes in `ManualGestureHandler` on iOS. It should now properly react to `shouldCancelWhenOutside` prop. This PR should solve part of #2265 issue.

## Test plan

Tested on example app
  • Loading branch information
m-bert authored Oct 17, 2022
1 parent 234ec68 commit 1091a01
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions ios/Handlers/RNManualHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@interface RNManualRecognizer : UIGestureRecognizer

- (id)initWithGestureHandler:(RNGestureHandler*)gestureHandler;
- (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler;

@end

Expand All @@ -24,7 +24,7 @@ - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
[_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];

if (_shouldSendBeginEvent) {
[_gestureHandler handleGesture:self];
_shouldSendBeginEvent = NO;
Expand All @@ -35,6 +35,14 @@ - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
[_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];

if ([self shouldFail]) {
self.state = (self.state == UIGestureRecognizerStatePossible)
? UIGestureRecognizerStateFailed
: UIGestureRecognizerStateCancelled;

[self reset];
}
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
Expand All @@ -53,21 +61,29 @@ - (void)reset
{
[_gestureHandler.pointerTracker reset];
[super reset];

_shouldSendBeginEvent = YES;
}

- (BOOL)shouldFail
{
if (_gestureHandler.shouldCancelWhenOutside && ![_gestureHandler containsPointInView]) {
return YES;
} else {
return NO;
}
}

@end

@implementation RNManualGestureHandler

- (instancetype)initWithTag:(NSNumber *)tag
{
if ((self = [super initWithTag:tag])) {
_recognizer = [[RNManualRecognizer alloc] initWithGestureHandler:self];

}
return self;
if ((self = [super initWithTag:tag])) {
_recognizer = [[RNManualRecognizer alloc] initWithGestureHandler:self];
}
return self;
}

@end

0 comments on commit 1091a01

Please sign in to comment.