Repository navigation
[General] Allow explicit opt-in for the Animated codepaths when not using native driver - #3824
Merged
Merged
Conversation
j-piasecki
commented
Nov 19, 2025
j-piasecki
left a comment
Member
Author
There was a problem hiding this comment.
Let me know if you prefer the AnimatedEvent type fixes to be in a separate PR
Comment on lines
+28
to
+30
| onUpdate?: | ||
| | ((event: GestureUpdateEvent<THandlerData>) => void) | ||
| | AnimatedEvent; |
Member
Author
There was a problem hiding this comment.
Instead of a function or an AnimatedEvent, it was a function that was returning void or AnimatedEvent.
This was irritating, as it was the reason types in InterceptingGestureDetector were correct.
Comment on lines
+129
to
+137
| if (typeof gesture?.detectorCallbacks[key] === 'function') { | ||
| // @ts-expect-error passing event to a union of functions where only one is typed as such | ||
| gesture.detectorCallbacks[key](e); | ||
| } | ||
|
|
||
| virtualChildren.forEach((child) => { | ||
| const method = child.methods[key]; | ||
| if (method) { | ||
| if (typeof method === 'function') { | ||
| // @ts-expect-error passing event to a union of functions where only one is typed as such |
| (key: keyof DetectorCallbacks<THandlerData>) => { | ||
| return (e: GestureHandlerEvent<THandlerData>) => { | ||
| if (gesture?.detectorCallbacks[key]) { | ||
| if (typeof gesture?.detectorCallbacks[key] === 'function') { |
Member
Author
There was a problem hiding this comment.
This is also covering undefined check, typeof undefined === 'undefined'
Comment on lines
+54
to
56
| export type AnimatedEvent = { | ||
| _argMapping: (Animated.Mapping | null)[]; | ||
| }; |
Member
Author
There was a problem hiding this comment.
After fixing the type above, this started breaking type inference and every onUpdate was being typed as (...any) => void
m-bert
approved these changes
Nov 19, 2025
| import { useReanimatedTouchEvent } from './callbacks/reanimated/useReanimatedTouchEvent'; | ||
| import { tagMessage } from '../../utils'; | ||
|
|
||
| function guardJSAnimatedEvent(handler: (...args: unknown[]) => void) { |
Collaborator
There was a problem hiding this comment.
I'm not a fun of this name, but I cannot think of any better.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Currently, we're enabling the Animated codepath only when the handler passed to
onUpdateis anAnimated.EventwithuseNativeDriver. WhenuseNativeDriveris not enabled,Animated.eventreturns a function, and we have no way of differentiating between it and a function passed by the user.This is not ideal since the animated codepath receives events in a different format (wrapped with
nativeEvent). This meant that the code would stop working when switching between using the native driver and not. The same would happen when trying to use a native driver in code supposed to also run on web, where it's not available - the gesture would work on mobile, but crash on web.To avoid this, this PR adds an option to explicitly opt-in to the animated codepath by setting
useAnimatedin the gesture config. This will automatically disable Reanimated and throw an error when user if the user tries to reenable it.Test plan
Tested on the
Native Detectorexample in the basic app, as well as on the expo app on the same example for web.