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(whenFinishFunction)();
runOnJS(setAnimationState)(false);
}
);
withTiming
andrunOnJS
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 berunOnJS
called with a single locally defined function reference, and any passed arguments (as shown in the example). – Cyprian