diff options
author | Ivan Chen <ivan@tagg.id> | 2021-07-29 16:32:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-29 16:32:40 -0400 |
commit | e7fb70f6a5f24385e93bcb2df7da466a9089d4f7 (patch) | |
tree | 6c21f62ad09d45fbfabe7a1dee0adfcf213b6bd2 /src/components/moments/MomentPost.tsx | |
parent | 403314805c9192aa7f7adca9605a0d0a52997c9c (diff) | |
parent | 8974d48777d46aa8edb8857d892773c85dcd5efe (diff) |
Merge pull request #534 from IvanIFChen/tma1023-pause-video-out-of-focus
[TMA-1023] Pause Video In Background
Diffstat (limited to 'src/components/moments/MomentPost.tsx')
-rw-r--r-- | src/components/moments/MomentPost.tsx | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/components/moments/MomentPost.tsx b/src/components/moments/MomentPost.tsx index 921f7693..52b99d58 100644 --- a/src/components/moments/MomentPost.tsx +++ b/src/components/moments/MomentPost.tsx @@ -1,4 +1,4 @@ -import {useNavigation} from '@react-navigation/native'; +import {useIsFocused, useNavigation} from '@react-navigation/native'; import React, {useContext, useEffect, useMemo, useRef, useState} from 'react'; import { Image, @@ -93,7 +93,14 @@ const MomentPost: React.FC<MomentPostProps> = ({ ); const mediaHeight = SCREEN_WIDTH / aspectRatio; const [isVideoPaused, setIsVideoPaused] = useState<boolean>(false); + const screenIsFocused = useIsFocused(); const videoProgress = useSharedValue(0); + + // update play/pause icon based on video pause state + useEffect(() => { + setFadeValue(new Animated.Value(isVideoPaused ? 1 : 0)); + }, [isVideoPaused]); + /* * Load tags on initial render to pass tags data to moment header and content */ @@ -228,7 +235,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)) { @@ -294,9 +305,6 @@ const MomentPost: React.FC<MomentPostProps> = ({ onPress={() => { if (isVideo) { setIsVideoPaused(!isVideoPaused); - isVideoPaused - ? setFadeValue(new Animated.Value(0)) - : setFadeValue(new Animated.Value(1)); } else { setTagsVisible(!tagsVisible); setFadeValue(new Animated.Value(0)); |