pavelbabenko / react-native-awesome-gallery

Performant, native-like, and well-customizable gallery for React Native.
MIT License
495 stars 54 forks source link

ReanimatedError occurred when using onTranslationYChange #84

Open starheH opened 2 months ago

starheH commented 2 months ago

When I set the onTranslationYChange event and drag the image up and down, the following exception occurs: ReanimatedError: [Reanimated] Tried to synchronously call a non-worklet function on the UI thread.

It seems that onTranslationYChange is not called through runOnJS.

RN: 0.75 react-native-awesome-gallery: 0.4.2

LinhNguyen1059 commented 2 weeks ago

I face this too, here is my code:

const onTranslationYChange = useCallback((translationY, shouldClose) => {
    console.log('🚀 ~ translationY:', translationY);
}, []);

So I fixed it by adding the worklet before the console.log and it works.

const onTranslationYChange = useCallback((translationY, shouldClose) => {
    'worklet';

    console.log('🚀 ~ translationY:', translationY);
}, []);