App crashes when calling function inside Gesture detector

105 views Asked by At

I am having the problem that my app keeps crashing, when trying to call a function inside a Gesture detector. I have seen multiple answers which suggested to use runOnJS or writing worklet in the wished function and it seems that many people could solve their issues with it, but none of these worked out for me. Maybe someone of you can figure out what's my problem here...

My code snippet:


 const SortingModal = React.forwardRef(({rollDown},ref) => {


   const {height: MAX_MODAL_HEIGHT} = Dimensions.get('screen');

   const translateY = useSharedValue(0);

    const context = useSharedValue({y: 0});

    const gesture = Gesture.Pan()
    .onStart(()=>{
        context.value ={ y: translateY.value};
    })
    .onUpdate((event) => {
        
        if(event.translationY < MAX_MODAL_HEIGHT){
            translateY.value = event.translationY + context.value.y;
            translateY.value = Math.max(translateY.value, -MAX_MODAL_HEIGHT)
        }
    }).onEnd(()=>{
        if(translateY.value > -MAX_MODAL_HEIGHT*0.5){
            translateY.value = withSpring(0, {damping: 15});
            callRollDown(); //My function, also tried runOnJS(callRollDown)()
        }else{
            translateY.value = withSpring(-MAX_MODAL_HEIGHT, {damping: 15});
        }

    });

   
    const rBottomSheetStyle = useAnimatedStyle(() => {
        return {
            transform: [{translateY:translateY.value}]
        };
    },[translateY]);

    const callRollDown = () =>{
        'worklet'
        rollDown();
    }
}

I think this should be enough to understand what I am trying to do.

If not, please fell free to ask for more code.

Any help is appreciated and thanks for your time :^).

0

There are 0 answers