diff options
author | Ivan Chen <ivan@tagg.id> | 2021-07-29 14:39:55 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-07-29 14:39:55 -0400 |
commit | 9c5dd791bb2fdd8197c6d0f34b7030dff839429d (patch) | |
tree | 60cae4a4a0aa3a9b9af964bd93438274cf0b5996 /src | |
parent | d14a1933276d82f68581be6236e1bc47e69611e6 (diff) |
Use useIsFocused
Diffstat (limited to 'src')
-rw-r--r-- | src/components/moments/MomentPost.tsx | 20 |
1 files changed, 11 insertions, 9 deletions
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<MomentPostProps> = ({ ); const mediaHeight = SCREEN_WIDTH / aspectRatio; const [isVideoPaused, setIsVideoPaused] = useState<boolean>(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<MomentPostProps> = ({ 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)) { |