rive.pause() not working with visilibity API?
Im using react runtime rive, it works fine, when I add custom buttons to pause/play rive it also works, but when using this flow with visibility API, the pause() is not working, even though all conditions are matched for it to run
const { rive, RiveComponent } = useRive({
...riveParams,
onLoad: () => {
rive?.resizeDrawingSurfaceToCanvas();
setLoading(false);
},
});
const handleVisibilityChange = useCallback(() => {
if (!rive) return;
console.log("handleVisibilityChange", document.hidden);
document.hidden ? rive.pause() : rive.play();
}, [rive]);
useEffect(() => {
document.addEventListener("visibilitychange", handleVisibilityChange);
return () => {
document.removeEventListener("visibilitychange", handleVisibilityChange);
rive?.cleanup();
};
}, [handleVisibilityChange, rive]);