Skip to content

Commit 780700b

Browse files
committed
fix(ios): test for gesture activation on first touch like Android
1 parent f58dd24 commit 780700b

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

packages/gesturehandler/platforms/ios/src/GestureHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ if (value != nil) recognizer.prop = [value type]; \
7878
//@property (nonatomic, weak, nullable) id<GestureHandlerEventEmitter> emitter;
7979
@property (nonatomic, readonly, nullable) UIGestureRecognizer *recognizer;
8080
@property (nonatomic) BOOL enabled;
81+
@property (nonatomic) BOOL activateOnBegin;
8182
@property(nonatomic) BOOL shouldCancelWhenOutside;
8283
@property (nullable, nonatomic, weak) id<GestureHandlerDelegate> delegate;
8384

packages/gesturehandler/platforms/ios/src/GestureHandler.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ - (instancetype)initWithTag:(NSNumber *)tag
7070
_tag = tag;
7171
_lastState = GestureHandlerStateUndetermined;
7272
_hitSlop = RNGHHitSlopEmpty;
73+
_activateOnBegin = YES;
7374
}
7475
return self;
7576
}
@@ -323,7 +324,7 @@ - (BOOL)containsPointInView
323324
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
324325
{
325326
[self reset];
326-
if (self.delegate && [self.delegate respondsToSelector:@selector(gestureHandler:shouldActivateForEvent:)]) {
327+
if (self.activateOnBegin && self.delegate && [self.delegate respondsToSelector:@selector(gestureHandler:shouldActivateForEvent:)]) {
327328
if (![self.delegate gestureHandler:self shouldActivateForEvent:[self eventExtraData:gestureRecognizer]]) {
328329
return FALSE;
329330
}

packages/gesturehandler/platforms/ios/src/PanHandler.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
7979
}
8080
#endif
8181
[super touchesBegan:touches withEvent:event];
82+
83+
// we check for active before UIGestureRecognizerStateBegan because otherwise
84+
// we dont behave as Android and activate on first touch
85+
if (![_gestureHandler.delegate gestureHandler:_gestureHandler shouldActivateForEvent:[_gestureHandler eventExtraData:self]]) {
86+
self.state = UIGestureRecognizerStateFailed;
87+
}
8288
}
8389

8490
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
@@ -187,6 +193,7 @@ - (instancetype)initWithTag:(NSNumber *)tag
187193
{
188194
if ((self = [super initWithTag:tag])) {
189195
_recognizer = [[BetterPanGestureRecognizer alloc] initWithGestureHandler:self];
196+
self.activateOnBegin = NO;
190197
}
191198
return self;
192199
}
@@ -275,4 +282,3 @@ - (void)setFailOffsetYEnd:(CGFloat)value {
275282
((BetterPanGestureRecognizer*)_recognizer).failOffsetYEnd = value;
276283
}
277284
@end
278-

0 commit comments

Comments
 (0)