Skip to content

Commit

Permalink
Fix cancelling manual activation gestures blocking interactivity on i…
Browse files Browse the repository at this point in the history
…OS (#3007)

## Description

Having a `gesture` with `manualActivation` set to `true` freezes
interactions globally when such gesture gets cancelled. If a touch or
palm cancellation is triggered by the device, all touchable elements,
both the native and the gesturized ones in the app become disabled.
This state is fixed when the cancelled gesture is triggered again.

closes #2885
## Test plan

Using the attached example on iOS iPad, perform the following sequence:
- tap the `OUTSIDE PRESSABLE` - see how it turns red
- press the grey area with an entire palm so that a cancellation
notification dispatches to the console
- now try tapping the `OUTSIDE PRESSABLE` yet again
- on the `main` branch, you will see no red indicator, on this branch
you should see one, which is the intended behaviour

## Code:
```js
import React from 'react-native';
import { TouchableHighlight, View, Text, StyleSheet } from 'react-native';
import {
  Gesture,
  GestureHandlerRootView,
  GestureDetector,
} from 'react-native-gesture-handler';

export default function EmptyExample() {
  const pan = Gesture.Pinch()
    .manualActivation(true)
    .onTouchesDown((event) => {
      console.log('down', event);
    })
    .onTouchesCancelled((event) => {
      console.log('cancelled', event);
    })
    .onStart(() => console.log('started'));

  return (
    <GestureHandlerRootView style={exampleStyles.root}>
      <TouchableHighlight
        onPress={() => console.log(2)}
        underlayColor={'red'}
        style={[exampleStyles.button, { backgroundColor: '#21da1a' }]}>
        <Text>OUTSIDE DETECTOR</Text>
      </TouchableHighlight>
      <GestureDetector gesture={pan}>
        <View style={[exampleStyles.area, { backgroundColor: '#5e5e5e' }]}>
          <TouchableHighlight
            onPress={() => console.log(1)}
            underlayColor={'red'}
            style={[exampleStyles.button, { backgroundColor: '#dad41a' }]}>
            <Text>INSIDE DETECTOR</Text>
          </TouchableHighlight>
        </View>
      </GestureDetector>
    </GestureHandlerRootView>
  );
}

const exampleStyles = StyleSheet.create({
  root: {
    flex: 1,
  },
  area: { flex: 1, marginTop: 100 },
  button: {
    width: 100,
    height: 100,
    zIndex: 100,
    position: 'absolute',
  },
});
```
  • Loading branch information
latekvo authored Jul 26, 2024
1 parent e2098dc commit 39a8426
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions apple/Handlers/RNFlingHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
_lastPoint = [[[touches allObjects] objectAtIndex:0] locationInView:_gestureHandler.recognizer.view];
[super touchesCancelled:touches withEvent:event];
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

- (void)triggerAction
Expand Down
1 change: 1 addition & 0 deletions apple/Handlers/RNForceTouchHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
{
[super touchesCancelled:touches withEvent:event];
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

- (void)handleForceWithTouches:(NSSet<RNGHUITouch *> *)touches
Expand Down
1 change: 1 addition & 0 deletions apple/Handlers/RNLongPressHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
{
[super touchesCancelled:touches withEvent:event];
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

- (void)reset
Expand Down
1 change: 1 addition & 0 deletions apple/Handlers/RNManualHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
{
[super touchesCancelled:touches withEvent:event];
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

- (void)reset
Expand Down
1 change: 1 addition & 0 deletions apple/Handlers/RNPanHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ - (void)interactionsEnded:(NSSet *)touches withEvent:(UIEvent *)event
- (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

#if TARGET_OS_OSX
Expand Down
1 change: 1 addition & 0 deletions apple/Handlers/RNPinchHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ - (void)interactionsEnded:(NSSet *)touches withEvent:(UIEvent *)event
- (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

#if TARGET_OS_OSX
Expand Down
1 change: 1 addition & 0 deletions apple/Handlers/RNRotationHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ - (void)interactionsEnded:(NSSet *)touches withEvent:(UIEvent *)event
- (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

#if TARGET_OS_OSX
Expand Down
1 change: 1 addition & 0 deletions apple/Handlers/RNTapHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
{
[super touchesCancelled:touches withEvent:event];
[self interactionsCancelled:touches withEvent:event];
[self reset];
}

#endif
Expand Down

0 comments on commit 39a8426

Please sign in to comment.