0

I am trying to get the translateY.value into a state or some other way to control other component. This is inside a "bottomSheet" but in my Main where i import the bottomSheet i want to use the y value it is at while it is moving to control other components. Using react-native-gestru-handler

  const [tapNumber, setTapNumber] = useState(0);

  const gesture = Gesture.Pan()
    .onStart(() => {
        animatedByValue.value = { y: translateY.value };
    }).onUpdate((event) => {
        translateY.value = event.translationY + animatedByValue.value.y;
        translateY.value = Math.max(translateY.value, MAX_TRANSLATE_Y)
        setTapNumber((value) => value + 1); // makes the app crash


    }).onEnd(() => {
        if (translateY.value > -SCREEN_HEIGHT / 4) { // snap close
            scrollTo(-SCREEN_HEIGHT * 0.2);  
        } else if (translateY.value < -SCREEN_HEIGHT / 1.5) { // snap to top
            scrollTo(MAX_TRANSLATE_Y);
        }


    });

I belive i need to add some kind of listner, but haven't had any luck doing so. Trying to set a state inside the onUpdate crashes the app with:

JNI DETECTED ERROR IN APPLICATION: JNI GetObjectRefType called with pending exception java.lang.RuntimeException: Tried to synchronously call function {bound dispatchSetState} from a different thread.

But works fine in debug mode. If there is a simple way to get y value while inside "onUpdate" in Animated.event from react-native, please share a solution.

KLK
  • 49
  • 7

1 Answers1

0

Didn't find a good solution. Switched to passing the Sharedvalue as a prop. Found out the Reanimated 2 works on the UI thread, and state is handled in the JS thread.

KLK
  • 49
  • 7