7

My React native expo application crashing without any error when call function() in withTiming() callback

example :

const whenFinishFunction = () => {
    // do some thing
  };
const [animationState, setAnimationState] = useState(false);

progress.value = withTiming(1,{duration: 200},
      () => {
       whenFinishFunction();
       setAnimationState(false);
      }
    );

solved by use runOnJS

like :

progress.value = withTiming(1,{duration: 200},
      () => {
        runOnJS(setAnimationState)(false);
        runOnJS(whenFinishFunction)();
      }
    );
Ahmed5G
  • 310
  • 2
  • 8
  • It's worth nothing, for anybody coming across this, that `withTiming` and `runOnJS` are *very* picky about how you use them. It has to be an arrow function *literal* for the withTiming callback, and the *only* thing inside the literal has to be `runOnJS` called with a single locally defined function *reference*, and any passed arguments (as shown in the example). – Geoff Davids Jul 31 '23 at 17:39

0 Answers0