Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the GestureStateManager.begin() API (v3) and tightens manual activation behavior so gestures cannot be activated unless they have already transitioned into BEGAN (i.e., received touches / began recognition).
Changes:
- Remove
begin()from the v3GestureStateManagerAPI (native + web implementations). - Stop forcing
UNDETERMINED -> BEGAN -> ACTIVEin manual activation flows (web/iOS/Android). - Prevent
GestureHandler.activate()on web from transitioning fromUNDETERMINEDtoACTIVE.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/web/handlers/GestureHandler.ts | Disallows activation unless the handler is already in BEGAN. |
| packages/react-native-gesture-handler/src/v3/gestureStateManager.web.ts | Removes begin() and stops auto-begin in activate() for web v3. |
| packages/react-native-gesture-handler/src/v3/gestureStateManager.ts | Removes begin() from the exported v3 state manager type/impl. |
| packages/react-native-gesture-handler/apple/RNGestureHandlerModule.mm | Blocks ACTIVE state changes for handlers that never left UNDETERMINED. |
| packages/react-native-gesture-handler/apple/RNGestureHandler.h | Exposes lastState for the new activation guard; formatting changes. |
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt | Blocks UNDETERMINED -> ACTIVE and adjusts when handlers get recorded. |
Comments suppressed due to low confidence (1)
packages/react-native-gesture-handler/src/v3/gestureStateManager.web.ts:25
GestureStateManager.activatealways callsGestureHandlerOrchestrator.instance.recordHandlerIfNotPresent(handler)even whenhandler.activate(true)will no-op (e.g. when the handler is stillUNDETERMINED). Since the web orchestrator only cleans upEND/FAILED/CANCELLEDhandlers, this can leave anUNDETERMINEDhandler permanently recorded, causing an orchestrator list leak and extra processing. Consider checkinghandler.state === State.BEGANbefore recording/activating (or otherwise avoid recording when activation is ignored).
const handler = NodeManager.getHandler(handlerTag);
ensureHandlerAttached(handler);
GestureHandlerOrchestrator.instance.recordHandlerIfNotPresent(handler);
handler.activate(true);
},
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...e-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt
Outdated
Show resolved
Hide resolved
|
This PR intentionally breaks current StateManager example, I'm trying to think of a good replacement, if you have any ideas, let me know. |
packages/docs-gesture-handler/docs/fundamentals/state-manager.mdx
Outdated
Show resolved
Hide resolved
| @property (nonatomic, weak, nullable) RNGHUIView *hostDetectorView; | ||
| @property (nonatomic, nullable, assign) NSNumber *virtualViewTag; | ||
| @property (nonatomic, copy, nullable) NSNumber *viewTag; | ||
| @property (nonatomic, readonly) RNGestureHandlerState lastState; |
There was a problem hiding this comment.
This will be confusing given that we already have _lastState defined 20 lines above
There was a problem hiding this comment.
lastState is just a getter for _lastState, they are automatically linked. I kept it this way to ensure subclasses can modify the value, but it remains readonly elsewhere
Co-authored-by: Michał Bert <63123542+m-bert@users.noreply.github.com>
Description
We realised that there is no real use case for allowing to state manage gestures which did not receive touches. Thus we decided to remove the function
GestureStateManager.begin()altogether, as if gesture had received touches it's state is set to begun. Additonally StateManager will no longer force going through begin state in activate, thus if we attempt to use state manager to activate a non begun gesture it won't activate.Test plan
Tested on the following example
Details