I'm trying to setState inside withRepeat callback to show the button when the animations isFinished but the app closes. How can I update the state based on animation end?
const [showBtn, setShowBtn] = React.useState(false);
// ...
React.useEffect(() => {
circle.value = withRepeat(
withSequence(
withTiming(1, {
duration: 4000,
}),
withTiming(1, {
duration: 2000,
}),
withTiming(0, {
duration: 4000,
})
),
2,
false,
(isFinished) => {
setShowBtn(true); // <- app closes
}
);
}, [showBtn]);
return (
{showBtn && (
<Button onPress={() => {
circle.value = 0;
setShowBtn(false);
}}>Restart</Button>
)}
)