fix: gesture not activating due to outdated handler tag #3578
+3
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This fixes an issue where the manual activation of a handler wouldn't work.
I unfortunately didn't had time to make a full reproduction. The scenario roughly looks like this:
This is being used in a component on a screen. When we navigate from the screen the component gets unmounted and I can see that his logic is being triggered:
react-native-gesture-handler/packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/index.tsx
Lines 152 to 168 in 1e1f4e0
I think the screen might get frozen instead of unmounted, but not entirely sure, but the cleanup function gets called and the handler gets dropped.
Now, when reopening the screen the handlers will reattach, but have a different handler tag now.
When I now run the gesture I can see that the
manager
still has the previous handler tag, and thus on the native side it can't find the handler to activate. Its callingsetGestureHandlerState(1 /* previous id */)
here (when I callmanager.activate
):react-native-gesture-handler/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt
Line 108 in 1e1f4e0
I found that attaching the handler tag to the GestureStateMangaer and recreating it if it has changed fixes the issue.
If you need a full reproduction to proceed with this change I can understand, just let me know then I can try to find time to create one 👍
Test plan
Well, shamefully I didn't create a reproduction so I guess the test plan is "trust me bro" 😅 not the best I know - sorry.