From e595e314f306c703fca779dff174690b33ebd612 Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Fri, 6 Aug 2021 15:30:09 -0400 Subject: Basic additions --- src/screens/moments/CameraScreen.tsx | 61 +++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index c3ecdb14..483bfe38 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -33,6 +33,8 @@ const CameraScreen: React.FC = ({route, navigation}) => { const [isRecording, setIsRecording] = useState(false); const [pictureProcessing, setPictureProcessing] = useState(false); const [mounted, setMounted] = useState(false); + const [vidUri, setVidUri] = useState(); + const [videoRecordStart, setVideoRecordStart] = useState(false); useFocusEffect( useCallback(() => { @@ -43,6 +45,9 @@ const CameraScreen: React.FC = ({route, navigation}) => { // reset in case we have returned to this screen setPictureProcessing(false); + // reset in case this wasn't properly called + setIsRecording(false); + // in case the preview image gets stuck if (mounted) { cameraRef?.current?.resumePreview(); @@ -121,6 +126,25 @@ const CameraScreen: React.FC = ({route, navigation}) => { setCameraType(cameraType === 'front' ? 'back' : 'front'); } }} + onRecordingStart={(event: { + nativeEvent: { + uri: string; + videoOrientation: number; + deviceOrientation: number; + }; + }) => { + console.log('start', event.nativeEvent.uri); + setIsRecording(true); + setVidUri(event.nativeEvent.uri); + setVideoRecordStart(true); + }} + onRecordingEnd={() => { + if (videoRecordStart && vidUri) { + navigateToEditMedia(vidUri); + } + setVideoRecordStart(false); + setIsRecording(false); + }} /> {!pictureProcessing && ( @@ -132,29 +156,38 @@ const CameraScreen: React.FC = ({route, navigation}) => { : styles.captureButtonContainer } activeOpacity={1} - onLongPress={() => { - takeVideo(cameraRef, (vid) => navigateToEditMedia(vid.uri)); - setIsRecording(true); + onLongPress={async () => { + const resetAndStartCameraRecording = async () => { + if (await cameraRef.current?.isRecording()) { + cameraRef.current?.stopRecording(); + } + }; + + await resetAndStartCameraRecording(); + takeVideo(cameraRef, (vid) => setVidUri(vid.uri)); }} onPressOut={async () => { const cancelRecording = async () => { - if (await cameraRef.current?.isRecording()) { + if (isRecording && (await cameraRef.current?.isRecording())) { cameraRef.current?.stopRecording(); - setIsRecording(false); + } else { + takePicture(cameraRef, (pic) => navigateToEditMedia(pic.uri)); } + setIsRecording(false); }; + setPictureProcessing(true); cancelRecording(); // tmp fix for when the animation glitches during the beginning of // recording causing onPressOut to not be detected. - setTimeout(() => { - cancelRecording(); - }, 500); - setTimeout(() => { - cancelRecording(); - }, 1000); - setTimeout(() => { - cancelRecording(); - }, 1500); + // setTimeout(() => { + // cancelRecording(); + // }, 500); + // setTimeout(() => { + // cancelRecording(); + // }, 1000); + // setTimeout(() => { + // cancelRecording(); + // }, 1500); }} onPress={() => { if (!pictureProcessing) { -- cgit v1.2.3-70-g09d2 From 59975109d3f6945ac5153e775e6f91f933acc67e Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Fri, 6 Aug 2021 16:06:20 -0400 Subject: Correct changes --- src/screens/moments/CameraScreen.tsx | 57 ++++++++++++++---------------------- 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index 483bfe38..c57755b4 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -36,6 +36,13 @@ const CameraScreen: React.FC = ({route, navigation}) => { const [vidUri, setVidUri] = useState(); const [videoRecordStart, setVideoRecordStart] = useState(false); + const killUnnecessaryVideo = async () => { + setVideoRecordStart(false); + if (await cameraRef.current?.isRecording()) { + cameraRef.current?.stopRecording(); + } + }; + useFocusEffect( useCallback(() => { navigation.dangerouslyGetParent()?.setOptions({ @@ -75,6 +82,17 @@ const CameraScreen: React.FC = ({route, navigation}) => { setMounted(true); }, []); + /* + * Triggers when vidUri updates + */ + useEffect(() => { + if (videoRecordStart && vidUri) { + navigateToEditMedia(vidUri); + } + setVideoRecordStart(false); + setIsRecording(false); + }, [vidUri]); + const navigateToEditMedia = (uri: string) => { cameraRef?.current?.resumePreview(); navigation.navigate('EditMedia', { @@ -126,25 +144,10 @@ const CameraScreen: React.FC = ({route, navigation}) => { setCameraType(cameraType === 'front' ? 'back' : 'front'); } }} - onRecordingStart={(event: { - nativeEvent: { - uri: string; - videoOrientation: number; - deviceOrientation: number; - }; - }) => { - console.log('start', event.nativeEvent.uri); + onRecordingStart={() => { setIsRecording(true); - setVidUri(event.nativeEvent.uri); setVideoRecordStart(true); }} - onRecordingEnd={() => { - if (videoRecordStart && vidUri) { - navigateToEditMedia(vidUri); - } - setVideoRecordStart(false); - setIsRecording(false); - }} /> {!pictureProcessing && ( @@ -157,13 +160,7 @@ const CameraScreen: React.FC = ({route, navigation}) => { } activeOpacity={1} onLongPress={async () => { - const resetAndStartCameraRecording = async () => { - if (await cameraRef.current?.isRecording()) { - cameraRef.current?.stopRecording(); - } - }; - - await resetAndStartCameraRecording(); + await killUnnecessaryVideo(); takeVideo(cameraRef, (vid) => setVidUri(vid.uri)); }} onPressOut={async () => { @@ -177,23 +174,13 @@ const CameraScreen: React.FC = ({route, navigation}) => { }; setPictureProcessing(true); cancelRecording(); - // tmp fix for when the animation glitches during the beginning of - // recording causing onPressOut to not be detected. - // setTimeout(() => { - // cancelRecording(); - // }, 500); - // setTimeout(() => { - // cancelRecording(); - // }, 1000); - // setTimeout(() => { - // cancelRecording(); - // }, 1500); }} - onPress={() => { + onPress={async () => { if (!pictureProcessing) { setPictureProcessing(true); } takePicture(cameraRef, (pic) => navigateToEditMedia(pic.uri)); + await killUnnecessaryVideo(); }}> -- cgit v1.2.3-70-g09d2 From 90f9056e26b300e63a862e54eefac6c5befaba3b Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Fri, 6 Aug 2021 16:11:35 -0400 Subject: Adding extra kills --- src/screens/moments/CameraScreen.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index c57755b4..ba692ded 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -54,6 +54,7 @@ const CameraScreen: React.FC = ({route, navigation}) => { // reset in case this wasn't properly called setIsRecording(false); + killUnnecessaryVideo(); // in case the preview image gets stuck if (mounted) { @@ -173,7 +174,8 @@ const CameraScreen: React.FC = ({route, navigation}) => { setIsRecording(false); }; setPictureProcessing(true); - cancelRecording(); + await cancelRecording(); + await killUnnecessaryVideo(); }} onPress={async () => { if (!pictureProcessing) { -- cgit v1.2.3-70-g09d2 From f7cb9ac034829d986b781dc5ea97c3dd0beed047 Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Fri, 6 Aug 2021 16:16:26 -0400 Subject: Fix unnecessary kill --- src/screens/moments/CameraScreen.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index ba692ded..f2c55b9c 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -87,7 +87,9 @@ const CameraScreen: React.FC = ({route, navigation}) => { * Triggers when vidUri updates */ useEffect(() => { + console.log('effect', videoRecordStart, vidUri); if (videoRecordStart && vidUri) { + console.log('navigate'); navigateToEditMedia(vidUri); } setVideoRecordStart(false); @@ -175,7 +177,6 @@ const CameraScreen: React.FC = ({route, navigation}) => { }; setPictureProcessing(true); await cancelRecording(); - await killUnnecessaryVideo(); }} onPress={async () => { if (!pictureProcessing) { -- cgit v1.2.3-70-g09d2 From f75d83f1de9f0f49a128c8c1712590337fe30ffc Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Fri, 6 Aug 2021 16:17:52 -0400 Subject: Killed another unnecessary kill --- src/screens/moments/CameraScreen.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index f2c55b9c..69b6a30d 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -54,7 +54,6 @@ const CameraScreen: React.FC = ({route, navigation}) => { // reset in case this wasn't properly called setIsRecording(false); - killUnnecessaryVideo(); // in case the preview image gets stuck if (mounted) { -- cgit v1.2.3-70-g09d2 From 183255b98b79f5402bfde7c405f566741f38f759 Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Fri, 6 Aug 2021 16:58:24 -0400 Subject: Remove print statements --- src/screens/moments/CameraScreen.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index 69b6a30d..46e68a98 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -86,9 +86,7 @@ const CameraScreen: React.FC = ({route, navigation}) => { * Triggers when vidUri updates */ useEffect(() => { - console.log('effect', videoRecordStart, vidUri); if (videoRecordStart && vidUri) { - console.log('navigate'); navigateToEditMedia(vidUri); } setVideoRecordStart(false); -- cgit v1.2.3-70-g09d2 From eb2409404c5e3fe11529b5b237ac5863ae383e16 Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Fri, 6 Aug 2021 17:11:10 -0400 Subject: Unrender camera when not in focus --- src/screens/moments/CameraScreen.tsx | 42 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index 46e68a98..78a9169d 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -1,7 +1,7 @@ import CameraRoll from '@react-native-community/cameraroll'; import {useBottomTabBarHeight} from '@react-navigation/bottom-tabs'; import {RouteProp} from '@react-navigation/core'; -import {useFocusEffect} from '@react-navigation/native'; +import {useFocusEffect, useIsFocused} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; import React, {useRef, useCallback, useEffect, useState} from 'react'; import {Modal, StyleSheet, TouchableOpacity, View} from 'react-native'; @@ -27,6 +27,7 @@ const CameraScreen: React.FC = ({route, navigation}) => { const {screenType, selectedCategory} = route.params; const cameraRef = useRef(null); const tabBarHeight = useBottomTabBarHeight(); + const focused = useIsFocused(); const [cameraType, setCameraType] = useState('back'); const [flashMode, setFlashMode] = useState('off'); const [mostRecentPhoto, setMostRecentPhoto] = useState(''); @@ -94,7 +95,6 @@ const CameraScreen: React.FC = ({route, navigation}) => { }, [vidUri]); const navigateToEditMedia = (uri: string) => { - cameraRef?.current?.resumePreview(); navigation.navigate('EditMedia', { screenType, media: { @@ -130,25 +130,27 @@ const CameraScreen: React.FC = ({route, navigation}) => { - { - if (!pictureProcessing) { - setCameraType(cameraType === 'front' ? 'back' : 'front'); + {focused && ( + { - setIsRecording(true); - setVideoRecordStart(true); - }} - /> + onDoubleTap={() => { + if (!pictureProcessing) { + setCameraType(cameraType === 'front' ? 'back' : 'front'); + } + }} + onRecordingStart={() => { + setIsRecording(true); + setVideoRecordStart(true); + }} + /> + )} {!pictureProcessing && ( -- cgit v1.2.3-70-g09d2 From f4f8336bc66ed8de46ebdb2902a5cb37aac1b932 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 6 Aug 2021 17:32:13 -0400 Subject: Add show camera --- src/screens/moments/CameraScreen.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index 78a9169d..1f38a0bf 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -33,7 +33,7 @@ const CameraScreen: React.FC = ({route, navigation}) => { const [mostRecentPhoto, setMostRecentPhoto] = useState(''); const [isRecording, setIsRecording] = useState(false); const [pictureProcessing, setPictureProcessing] = useState(false); - const [mounted, setMounted] = useState(false); + const [showCamera, setShowCamera] = useState(true); const [vidUri, setVidUri] = useState(); const [videoRecordStart, setVideoRecordStart] = useState(false); @@ -44,6 +44,14 @@ const CameraScreen: React.FC = ({route, navigation}) => { } }; + useEffect(() => { + if (!focused) { + setTimeout(() => { + setShowCamera(false); + }, 500); + } + }, [focused]); + useFocusEffect( useCallback(() => { navigation.dangerouslyGetParent()?.setOptions({ @@ -56,10 +64,7 @@ const CameraScreen: React.FC = ({route, navigation}) => { // reset in case this wasn't properly called setIsRecording(false); - // in case the preview image gets stuck - if (mounted) { - cameraRef?.current?.resumePreview(); - } + setShowCamera(true); return () => setIsRecording(false); }, [navigation]), @@ -79,8 +84,6 @@ const CameraScreen: React.FC = ({route, navigation}) => { .catch((_err) => console.log('Unable to fetch preview photo for gallery'), ); - - setMounted(true); }, []); /* @@ -130,7 +133,7 @@ const CameraScreen: React.FC = ({route, navigation}) => { - {focused && ( + {showCamera && ( Date: Fri, 6 Aug 2021 17:47:57 -0400 Subject: Cleanup code, Pause preview earlier --- src/screens/moments/CameraScreen.tsx | 15 +++++---------- src/utils/camera.ts | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index 1f38a0bf..739461a8 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -27,7 +27,6 @@ const CameraScreen: React.FC = ({route, navigation}) => { const {screenType, selectedCategory} = route.params; const cameraRef = useRef(null); const tabBarHeight = useBottomTabBarHeight(); - const focused = useIsFocused(); const [cameraType, setCameraType] = useState('back'); const [flashMode, setFlashMode] = useState('off'); const [mostRecentPhoto, setMostRecentPhoto] = useState(''); @@ -44,14 +43,6 @@ const CameraScreen: React.FC = ({route, navigation}) => { } }; - useEffect(() => { - if (!focused) { - setTimeout(() => { - setShowCamera(false); - }, 500); - } - }, [focused]); - useFocusEffect( useCallback(() => { navigation.dangerouslyGetParent()?.setOptions({ @@ -66,7 +57,11 @@ const CameraScreen: React.FC = ({route, navigation}) => { setShowCamera(true); - return () => setIsRecording(false); + return () => { + setTimeout(() => { + setShowCamera(false); + }, 500); + }; }, [navigation]), ); diff --git a/src/utils/camera.ts b/src/utils/camera.ts index ec2615de..c9dec292 100644 --- a/src/utils/camera.ts +++ b/src/utils/camera.ts @@ -23,12 +23,12 @@ export const takePicture = ( cameraRef: RefObject, callback: (pic: TakePictureResponse) => void, ) => { + cameraRef.current?.pausePreview(); if (cameraRef !== null) { const options: TakePictureOptions = { forceUpOrientation: true, orientation: 'portrait', writeExif: false, - pauseAfterCapture: true, }; cameraRef.current?.takePictureAsync(options).then((pic) => { callback(pic); -- cgit v1.2.3-70-g09d2 From 2dfbf05b9f7bdd4237f771dd8cc5a9dcbc2a3b06 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 6 Aug 2021 18:01:58 -0400 Subject: Add slight delay before playing video --- src/components/moments/TrimmerPlayer.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/moments/TrimmerPlayer.tsx b/src/components/moments/TrimmerPlayer.tsx index 8d1cd156..d884e6bd 100644 --- a/src/components/moments/TrimmerPlayer.tsx +++ b/src/components/moments/TrimmerPlayer.tsx @@ -25,13 +25,19 @@ const TrimmerPlayer: React.FC = ({ const playerRef = useRef