From 9c5dd791bb2fdd8197c6d0f34b7030dff839429d Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 29 Jul 2021 14:39:55 -0400 Subject: Use useIsFocused --- src/components/moments/MomentPost.tsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/components/moments/MomentPost.tsx b/src/components/moments/MomentPost.tsx index 5b71c64b..f4970f1e 100644 --- a/src/components/moments/MomentPost.tsx +++ b/src/components/moments/MomentPost.tsx @@ -1,4 +1,8 @@ -import {useFocusEffect, useNavigation} from '@react-navigation/native'; +import { + useFocusEffect, + useIsFocused, + useNavigation, +} from '@react-navigation/native'; import React, { useCallback, useContext, @@ -100,15 +104,9 @@ const MomentPost: React.FC = ({ ); const mediaHeight = SCREEN_WIDTH / aspectRatio; const [isVideoPaused, setIsVideoPaused] = useState(false); + const screenIsFocused = useIsFocused(); const videoProgress = useSharedValue(0); - // pause video when out of focus - useFocusEffect( - useCallback(() => { - return () => setIsVideoPaused(true); - }, []), - ); - // update play/pause icon based on video pause state useEffect(() => { setFadeValue(new Animated.Value(isVideoPaused ? 1 : 0)); @@ -248,7 +246,11 @@ const MomentPost: React.FC = ({ const {width, height} = response.naturalSize; setAspectRatio(width / height); }} - paused={moment.moment_id !== currentVisibleMomentId || isVideoPaused} + paused={ + moment.moment_id !== currentVisibleMomentId || + isVideoPaused || + !screenIsFocused + } onProgress={({currentTime, seekableDuration}) => { const localProgress = currentTime / seekableDuration; if (!isNaN(localProgress)) { -- cgit v1.2.3-70-g09d2