我正在尝试在 withRepeat 回调中设置状态,以在动画完成但应用关闭时显示按钮。如何根据动画结束更新状态?
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>
)}
)