From cba64717bf87020e8dcf229408a9ca79d6c7aa21 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 6 Aug 2021 18:44:04 -0400 Subject: Cleanup code, Fix preview bug --- src/screens/moments/CameraScreen.tsx | 43 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index 2294072b..c86f2efe 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -30,8 +30,8 @@ const CameraScreen: React.FC = ({route, navigation}) => { const [cameraType, setCameraType] = useState('back'); const [flashMode, setFlashMode] = useState('off'); const [mostRecentPhoto, setMostRecentPhoto] = useState(''); - const [isRecording, setIsRecording] = useState(false); - const [pictureProcessing, setPictureProcessing] = useState(false); + const [recordingStarted, setRecordingStarted] = useState(false); + const [showCaptureButtons, setShowCaptureButtons] = useState(false); const [showCamera, setShowCamera] = useState(true); const stopVideoRecording = async () => { @@ -45,15 +45,9 @@ const CameraScreen: React.FC = ({route, navigation}) => { navigation.dangerouslyGetParent()?.setOptions({ tabBarVisible: false, }); - - // reset in case we have returned to this screen - setPictureProcessing(false); - - // reset in case this wasn't properly called - setIsRecording(false); - + setRecordingStarted(false); + setShowCaptureButtons(true); setShowCamera(true); - return () => { setTimeout(() => { setShowCamera(false); @@ -107,7 +101,9 @@ const CameraScreen: React.FC = ({route, navigation}) => { + visible={ + recordingStarted && cameraType === 'front' && flashMode === 'on' + }> @@ -120,24 +116,24 @@ const CameraScreen: React.FC = ({route, navigation}) => { style={styles.camera} type={cameraType} flashMode={ - flashMode === 'on' && isRecording && cameraType === 'back' + flashMode === 'on' && recordingStarted && cameraType === 'back' ? 'torch' : flashMode } onDoubleTap={() => { - if (!pictureProcessing) { + if (showCaptureButtons) { setCameraType(cameraType === 'front' ? 'back' : 'front'); } }} - onRecordingStart={() => setIsRecording(true)} + onRecordingStart={() => setRecordingStarted(true)} /> )} - {!pictureProcessing && ( + {showCaptureButtons && ( = ({route, navigation}) => { takeVideo(cameraRef, (vid) => navigateToEditMedia(vid.uri)); }} onPressOut={async () => { - setPictureProcessing(true); - if (isRecording && (await cameraRef.current?.isRecording())) { + setShowCaptureButtons(false); + if ( + recordingStarted && + (await cameraRef.current?.isRecording()) + ) { cameraRef.current?.stopRecording(); } else { takePicture(cameraRef, (pic) => navigateToEditMedia(pic.uri)); } - setIsRecording(false); + setRecordingStarted(false); }} onPress={async () => { - if (!pictureProcessing) { - setPictureProcessing(true); + if (showCaptureButtons) { + setShowCaptureButtons(false); } takePicture(cameraRef, (pic) => navigateToEditMedia(pic.uri)); await stopVideoRecording(); }}> - {isRecording && ( + {recordingStarted && (