diff options
-rw-r--r-- | src/screens/moments/CameraScreen.tsx | 42 |
1 files 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<CameraScreenProps> = ({route, navigation}) => { const {screenType, selectedCategory} = route.params; const cameraRef = useRef<RNCamera>(null); const tabBarHeight = useBottomTabBarHeight(); + const focused = useIsFocused(); const [cameraType, setCameraType] = useState<keyof CameraType>('back'); const [flashMode, setFlashMode] = useState<keyof FlashMode>('off'); const [mostRecentPhoto, setMostRecentPhoto] = useState<string>(''); @@ -94,7 +95,6 @@ const CameraScreen: React.FC<CameraScreenProps> = ({route, navigation}) => { }, [vidUri]); const navigateToEditMedia = (uri: string) => { - cameraRef?.current?.resumePreview(); navigation.navigate('EditMedia', { screenType, media: { @@ -130,25 +130,27 @@ const CameraScreen: React.FC<CameraScreenProps> = ({route, navigation}) => { <CloseIcon height={25} width={25} color={'white'} /> </TouchableOpacity> <FlashButton flashMode={flashMode} setFlashMode={setFlashMode} /> - <RNCamera - ref={cameraRef} - style={styles.camera} - type={cameraType} - flashMode={ - flashMode === 'on' && isRecording && cameraType === 'back' - ? 'torch' - : flashMode - } - onDoubleTap={() => { - if (!pictureProcessing) { - setCameraType(cameraType === 'front' ? 'back' : 'front'); + {focused && ( + <RNCamera + ref={cameraRef} + style={styles.camera} + type={cameraType} + flashMode={ + flashMode === 'on' && isRecording && cameraType === 'back' + ? 'torch' + : flashMode } - }} - onRecordingStart={() => { - setIsRecording(true); - setVideoRecordStart(true); - }} - /> + onDoubleTap={() => { + if (!pictureProcessing) { + setCameraType(cameraType === 'front' ? 'back' : 'front'); + } + }} + onRecordingStart={() => { + setIsRecording(true); + setVideoRecordStart(true); + }} + /> + )} {!pictureProcessing && ( <View style={[styles.bottomContainer, {bottom: tabBarHeight}]}> <FlipButton cameraType={cameraType} setCameraType={setCameraType} /> |