From 54ca15a4d68d107be767938a83612843db2d04c2 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 6 Aug 2021 19:13:50 -0400 Subject: Add pause preview, Cleanup logics --- src/screens/moments/CameraScreen.tsx | 34 ++++++++++------------------------ src/utils/camera.ts | 2 +- 2 files changed, 11 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index c86f2efe..bd94bf63 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -33,12 +33,13 @@ const CameraScreen: React.FC = ({route, navigation}) => { const [recordingStarted, setRecordingStarted] = useState(false); const [showCaptureButtons, setShowCaptureButtons] = useState(false); const [showCamera, setShowCamera] = useState(true); + const [videoUri, setVideoUri] = useState(); - const stopVideoRecording = async () => { - if (await cameraRef.current?.isRecording()) { - cameraRef.current?.stopRecording(); + useEffect(() => { + if (recordingStarted && videoUri) { + navigateToEditMedia(videoUri); } - }; + }, [videoUri]); useFocusEffect( useCallback(() => { @@ -138,28 +139,13 @@ const CameraScreen: React.FC = ({route, navigation}) => { : styles.captureButtonContainer } activeOpacity={1} - onLongPress={async () => { - await stopVideoRecording(); - takeVideo(cameraRef, (vid) => navigateToEditMedia(vid.uri)); - }} - onPressOut={async () => { + onLongPress={() => + takeVideo(cameraRef, (vid) => setVideoUri(vid.uri)) + } + onPressOut={() => cameraRef.current?.stopRecording()} + onPress={() => { setShowCaptureButtons(false); - if ( - recordingStarted && - (await cameraRef.current?.isRecording()) - ) { - cameraRef.current?.stopRecording(); - } else { - takePicture(cameraRef, (pic) => navigateToEditMedia(pic.uri)); - } - setRecordingStarted(false); - }} - onPress={async () => { - if (showCaptureButtons) { - setShowCaptureButtons(false); - } takePicture(cameraRef, (pic) => navigateToEditMedia(pic.uri)); - await stopVideoRecording(); }}> diff --git a/src/utils/camera.ts b/src/utils/camera.ts index ec2615de..5f02f653 100644 --- a/src/utils/camera.ts +++ b/src/utils/camera.ts @@ -24,11 +24,11 @@ export const takePicture = ( callback: (pic: TakePictureResponse) => void, ) => { if (cameraRef !== null) { + cameraRef.current?.pausePreview(); 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