Skip to content

Commit 7581fde

Browse files
authored
Reset relevant handler when recognizer gets reset. (#2705)
## Description At the moment `reset` method is only called in `gestureRecognizerShouldBegin`: https://github.com/software-mansion/react-native-gesture-handler/blob/35ec17d636220c1ad4226456aa3b03c846ba16a8/apple/RNGestureHandler.m#L487 However, I've noticed that this method is called after some events are already sent, mainly the `BEGIN` event, which is often sent as soon as `onTouchesBegan` is executed for the first pointer. According to the [apple documentation](https://developer.apple.com/documentation/uikit/uigesturerecognizer/1620004-reset?language=objc), the `reset` method of recognizer is the place to reset the internal state of recognizer, which in this case in my opinion should also include the state of the handler. The issue this fixes is the one described in #2628: > One thing that could be related is the fact that when the gesture fails before activation, the gesture stays in the Began state until the finger is lifted. This still needs to be investigated. This was coming from the fact that the handler was failing before it was allowed to 'begin' (iOS begin not RNGH begin), so `gestureRecognizerShouldBegin` was not called, thus not resetting the failing handler. Because of that, it was sending events containing wrong states. ## Test plan Tested on the Example app.
1 parent 7c115be commit 7581fde

10 files changed

+16
-0
lines changed

apple/Handlers/RNFlingHandler.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ - (void)reset
7272
[_gestureHandler.pointerTracker reset];
7373
_hasBegan = NO;
7474
[super reset];
75+
[_gestureHandler reset];
7576
}
7677

7778
- (CGPoint)getLastLocation

apple/Handlers/RNForceTouchHandler.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ - (void)reset
125125
{
126126
[_gestureHandler.pointerTracker reset];
127127
[super reset];
128+
[_gestureHandler reset];
128129
_force = 0;
129130
_firstTouch = NULL;
130131
}

apple/Handlers/RNHoverHandler.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ - (void)cancel
5656
self.enabled = NO;
5757
}
5858

59+
- (void)reset
60+
{
61+
[super reset];
62+
[_gestureHandler reset];
63+
}
64+
5965
- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region
6066
{
6167
if (interaction.view != nil && _hoverEffect != RNGestureHandlerHoverEffectNone) {

apple/Handlers/RNLongPressHandler.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ - (void)reset
103103
[_gestureHandler.pointerTracker reset];
104104

105105
[super reset];
106+
[_gestureHandler reset];
106107
}
107108

108109
- (NSUInteger)getDuration

apple/Handlers/RNManualHandler.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ - (void)reset
6262
{
6363
[_gestureHandler.pointerTracker reset];
6464
[super reset];
65+
[_gestureHandler reset];
6566

6667
_shouldSendBeginEvent = YES;
6768
}

apple/Handlers/RNNativeViewHandler.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ - (void)reset
6565
{
6666
[_gestureHandler.pointerTracker reset];
6767
[super reset];
68+
[_gestureHandler reset];
6869
}
6970

7071
@end

apple/Handlers/RNPanHandler.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ - (void)interactionsMoved:(NSSet *)touches withEvent:(UIEvent *)event
123123

124124
if (self.state == UIGestureRecognizerStatePossible && [self shouldFailUnderCustomCriteria]) {
125125
self.state = UIGestureRecognizerStateFailed;
126+
[self triggerAction];
126127
return;
127128
}
128129

@@ -218,6 +219,7 @@ - (void)reset
218219
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(activateAfterLongPress) object:nil];
219220
self.enabled = YES;
220221
[super reset];
222+
[_gestureHandler reset];
221223
}
222224

223225
- (void)updateHasCustomActivationCriteria

apple/Handlers/RNPinchHandler.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ - (void)reset
120120
{
121121
[_gestureHandler.pointerTracker reset];
122122
[super reset];
123+
[_gestureHandler reset];
123124
}
124125

125126
@end

apple/Handlers/RNRotationHandler.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ - (void)reset
113113
{
114114
[_gestureHandler.pointerTracker reset];
115115
[super reset];
116+
[_gestureHandler reset];
116117
}
117118

118119
@end

apple/Handlers/RNTapHandler.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ - (void)reset
251251
_maxNumberOfTouches = 0;
252252
self.enabled = YES;
253253
[super reset];
254+
[_gestureHandler reset];
254255
}
255256

256257
@end

0 commit comments

Comments
 (0)