forked from software-mansion/react-native-gesture-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNRootViewGestureRecognizer.m
93 lines (78 loc) · 2.62 KB
/
RNRootViewGestureRecognizer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// RNRootViewGestureRecognizer.m
// RNGestureHandler
//
// Created by Krzysztof Magiera on 12/10/2017.
// Copyright © 2017 Software Mansion. All rights reserved.
//
#import "RNRootViewGestureRecognizer.h"
#import <UIKit/UIGestureRecognizerSubclass.h>
#import <React/RCTTouchHandler.h>
@implementation RNRootViewGestureRecognizer
{
BOOL _active;
}
@dynamic delegate;
- (instancetype)init
{
if (self = [super init]) {
self.delaysTouchesEnded = NO;
self.delaysTouchesBegan = NO;
}
return self;
}
- (BOOL)shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
// This method is used to implement "enabled" feature for gesture handlers. We enforce gesture
// recognizers that are connected with "disabled" handlers to wait for the root gesture
// recognizer to fail and this way we block them from acting.
RNGestureHandler *otherHandler = [RNGestureHandler
findGestureHandlerByRecognizer:otherGestureRecognizer];
if (otherHandler != nil && otherHandler.enabled == NO) {
return YES;
}
return NO;
}
- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer
{
return ![preventedGestureRecognizer isKindOfClass:[RCTTouchHandler class]];
}
- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer
{
// When this method is called it means that one of handlers has activated, in this case we want
// to send an info to JS so that it cancells all JS responders
[self.delegate gestureRecognizer:preventingGestureRecognizer didActivateInRootView:self.view];
return [super canBePreventedByGestureRecognizer:preventingGestureRecognizer];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
_active = YES;
self.state = UIGestureRecognizerStatePossible;
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
self.state = UIGestureRecognizerStatePossible;
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (self.state == UIGestureRecognizerStateBegan || self.state == UIGestureRecognizerStateChanged) {
self.state = UIGestureRecognizerStateEnded;
} else {
self.state = UIGestureRecognizerStateFailed;
}
[self reset];
_active = NO;
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
self.state = UIGestureRecognizerStateCancelled;
[self reset];
_active = NO;
}
- (void)blockOtherRecognizers
{
if (_active) {
self.state = UIGestureRecognizerStateBegan;
}
}
@end