You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check if handler was dropped before reattaching (#3247)
## Description
Currently Gesture Handler crashes apps that use `StrictMode`.
### Problem description
`StrictMode` [calls effects twice](https://react.dev/reference/react/StrictMode#fixing-bugs-found-by-re-running-effects-in-development). That means that `attachGestureHandler` and `dropGestureHandler` will be called extra time. However, when `attachGestureHandler` is called for the first time, `view` is not yet initialized. It means that instead of attaching handler, we [schedule another attach later](https://github.com/software-mansion/react-native-gesture-handler/blob/fe66fe168ad102199f06d8365cbf5b20ad24e87e/apple/RNGestureHandlerManager.mm#L170). In the meantime, `dropGestureHandler` removes handler from registry. When we finally try to attach handler one more time, it no longer exists, therefore application crashes.
### Solution
While it is not the best solution, we decided to check which handlers were dropped. If we try to reattach already dropped handler, we simply don't do that. On the other hand, if we try to reattach handler that wasn't dropped, app will crash. In other words, we simply reattach handler iff handler has not been dropped before.
Fixes#3184
## Test plan
<details>
<summary>Tested on the following reproduction:</summary>
```jsx
import { StrictMode } from 'react';
import { View } from 'react-native';
import {
Gesture,
GestureDetector,
GestureHandlerRootView,
} from 'react-native-gesture-handler';
const Example = () => {
const gesture = Gesture.Pan();
return (
<StrictMode>
<GestureHandlerRootView>
<GestureDetector gesture={gesture}>
<View />
</GestureDetector>
</GestureHandlerRootView>
</StrictMode>
);
};
export default Example;
```
</details>
0 commit comments