try and guard play/pause against unmount
This commit is contained in:
@@ -1044,16 +1044,25 @@ function PlayPauseTapArea({
|
||||
const {isPlaying} = useEvent(player, 'playingChange', {
|
||||
isPlaying: player.playing,
|
||||
})
|
||||
const isMounted = useRef(false)
|
||||
|
||||
const togglePlayPause = () => {
|
||||
if (!player) return
|
||||
useEffect(() => {
|
||||
isMounted.current = true
|
||||
return () => {
|
||||
isMounted.current = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
const togglePlayPause = useNonReactiveCallback(() => {
|
||||
// gets called after a timeout, so guard against being called after unmount -sfn
|
||||
if (!player || !isMounted.current) return
|
||||
doubleTapRef.current = null
|
||||
if (player.playing) {
|
||||
player.pause()
|
||||
} else {
|
||||
player.play()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const onPress = () => {
|
||||
if (doubleTapRef.current) {
|
||||
|
||||
Reference in New Issue
Block a user