Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

useAnimatedGestureHandler onStart method correct context argument type

$
0
0

TL;DRHas anyone have any examples what the correct generic is for useAnimatedGestureHandler?

Problem:

I am following this tutorial on Reanimated 2 gestures animation. There's this example:

//...const onGestureEvent = useAnimatedGestureHandler({  onStart: (_, ctx) => {    ctx.offsetX = translateX.value  },  //...})//...

i use typescript, when i copy the example in typescript i get ctx argument (context) type error:Property 'offset' does not exist on type '{}'. After some snooping around in onStart declaration i found that full type for GestureHandlers require a generic <T, TContext extends Context>:

//...export interface GestureHandlers<T, TContext extends Context> {  onStart?: Handler<T, TContext>;  //...}

Workaround:

i was able to work around this problem by simply passing a utility type Record (which is almost the same as saying 'any') , i don't like this.

const onGestureEvent = useAnimatedGestureHandler<    GestureEvent<PanGestureHandlerEventPayload>,    Record<string, unknown>>({    onStart: (_, ctx) => {    ctx.offsetX = translateX.value;    },    // onActive: () => {},    // onEnd: () => {},});

Question:

Has anyone have any examples what the correct generic is for useAnimatedGestureHandler?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>