diff options
author | Ivan Chen <ivan@tagg.id> | 2021-07-16 21:13:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-16 21:13:39 -0400 |
commit | c1b4e35862172b2268a3a53ece0acc807260652e (patch) | |
tree | 40703c8d2dd5abf0a24c07ab8932559ebc2f9cd5 /src/screens/moments/CameraScreen.tsx | |
parent | c22c19c9eeb28641d36cb9df38fe95301e0f768c (diff) | |
parent | 4ebb552aef8c5f6136c9359c54f2e4e1aa921241 (diff) |
Merge branch 'master' into tma988-remove-positioned-tags-for-video-moments
Diffstat (limited to 'src/screens/moments/CameraScreen.tsx')
-rw-r--r-- | src/screens/moments/CameraScreen.tsx | 121 |
1 files changed, 39 insertions, 82 deletions
diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index ee5834cb..33ee2347 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -8,16 +8,10 @@ import {StyleSheet, TouchableOpacity, View} from 'react-native'; import {CameraType, FlashMode, RNCamera} from 'react-native-camera'; import {AnimatedCircularProgress} from 'react-native-circular-progress'; import CloseIcon from '../../assets/ionicons/close-outline.svg'; -import { - FlashButton, - FlipButton, - GalleryIcon, - SaveButton, - TaggSquareButton, -} from '../../components'; +import {FlashButton, FlipButton, GalleryIcon} from '../../components'; import {TAGG_PURPLE} from '../../constants'; import {MainStackParams} from '../../routes'; -import {HeaderHeight, normalize, SCREEN_WIDTH} from '../../utils'; +import {HeaderHeight, SCREEN_WIDTH} from '../../utils'; import {showGIFFailureAlert, takePicture, takeVideo} from '../../utils/camera'; type CameraScreenRouteProps = RouteProp<MainStackParams, 'CameraScreen'>; @@ -35,9 +29,7 @@ const CameraScreen: React.FC<CameraScreenProps> = ({route, navigation}) => { const tabBarHeight = useBottomTabBarHeight(); const [cameraType, setCameraType] = useState<keyof CameraType>('front'); const [flashMode, setFlashMode] = useState<keyof FlashMode>('off'); - const [mediaFromGallery, setMediaFromGallery] = useState<string>(''); const [mostRecentPhoto, setMostRecentPhoto] = useState<string>(''); - const [showSaveButton, setShowSaveButton] = useState<boolean>(false); const [isRecording, setIsRecording] = useState<boolean>(false); useFocusEffect( @@ -62,14 +54,21 @@ const CameraScreen: React.FC<CameraScreenProps> = ({route, navigation}) => { .catch((_err) => console.log('Unable to fetch preview photo for gallery'), ); - }, [mediaFromGallery]); + }, []); - const navigateToCropper = (uri: string) => { - navigation.navigate('ZoomInCropper', { + const navigateToEditMedia = (uri: string) => { + navigation.navigate('EditMedia', { screenType, media: { uri, - isVideo: false, + isVideo: !( + uri.endsWith('jpg') || + uri.endsWith('JPG') || + uri.endsWith('PNG') || + uri.endsWith('png') || + uri.endsWith('GIF') || + uri.endsWith('gif') + ), }, selectedCategory, }); @@ -85,21 +84,11 @@ const CameraScreen: React.FC<CameraScreenProps> = ({route, navigation}) => { }); }; - /* - * If picture is not taken yet, exists from camera screen to profile view - * If picture is taken, exists from captured image's preview to camera - * */ const handleClose = () => { - if (showSaveButton) { - cameraRef.current?.resumePreview(); - setShowSaveButton(false); - setMediaFromGallery(''); - } else { - navigation.dangerouslyGetParent()?.setOptions({ - tabBarVisible: true, - }); - navigation.goBack(); - } + navigation.dangerouslyGetParent()?.setOptions({ + tabBarVisible: true, + }); + navigation.goBack(); }; return ( @@ -118,12 +107,13 @@ const CameraScreen: React.FC<CameraScreenProps> = ({route, navigation}) => { }} /> <View style={[styles.bottomContainer, {bottom: tabBarHeight}]}> - {showSaveButton ? ( - <SaveButton capturedImageURI={mediaFromGallery} /> - ) : ( - <FlipButton cameraType={cameraType} setCameraType={setCameraType} /> - )} + <FlipButton cameraType={cameraType} setCameraType={setCameraType} /> <TouchableOpacity + style={ + isRecording + ? styles.captureButtonVideoContainer + : styles.captureButtonContainer + } activeOpacity={1} onLongPress={() => { takeVideo(cameraRef, (vid) => { @@ -138,16 +128,8 @@ const CameraScreen: React.FC<CameraScreenProps> = ({route, navigation}) => { } }} onPress={() => { - takePicture(cameraRef, (pic) => { - setShowSaveButton(true); - setMediaFromGallery(pic.uri); - }); - }} - style={ - isRecording - ? styles.captureButtonVideoContainer - : styles.captureButtonContainer - }> + takePicture(cameraRef, (pic) => navigateToEditMedia(pic.uri)); + }}> <View style={styles.captureButton} /> </TouchableOpacity> {isRecording && ( @@ -163,32 +145,20 @@ const CameraScreen: React.FC<CameraScreenProps> = ({route, navigation}) => { /> )} <View style={styles.bottomRightContainer}> - {mediaFromGallery ? ( - <TaggSquareButton - onPress={() => navigateToCaptionScreen(false, mediaFromGallery)} - title={'Next'} - buttonStyle={'large'} - buttonColor={'blue'} - labelColor={'white'} - style={styles.nextButton} - labelStyle={styles.nextButtonLabel} - /> - ) : ( - <GalleryIcon - mostRecentPhotoUri={mostRecentPhoto} - callback={(media) => { - const filename = media.filename; - if ( - filename && - (filename.endsWith('gif') || filename.endsWith('GIF')) - ) { - showGIFFailureAlert(() => navigateToCropper(media.path)); - } else { - navigateToCropper(media.path); - } - }} - /> - )} + <GalleryIcon + mostRecentPhotoUri={mostRecentPhoto} + callback={(media) => { + const filename = media.filename; + if ( + filename && + (filename.endsWith('gif') || filename.endsWith('GIF')) + ) { + showGIFFailureAlert(() => navigateToEditMedia(media.path)); + } else { + navigateToEditMedia(media.path); + } + }} + /> </View> </View> </View> @@ -254,19 +224,6 @@ const styles = StyleSheet.create({ alignItems: 'center', width: (SCREEN_WIDTH - 100) / 2, }, - nextButton: { - zIndex: 1, - width: normalize(100), - height: normalize(37), - borderRadius: 10, - }, - nextButtonLabel: { - fontWeight: '700', - fontSize: normalize(15), - lineHeight: normalize(17.8), - letterSpacing: normalize(1.3), - textAlign: 'center', - }, }); export default CameraScreen; |