From 3329ed720fb336d9e5f893158754f630c7c2509d Mon Sep 17 00:00:00 2001 From: Ivan Chen 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