aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/assets/icons/camera/flash-off.svg2
-rw-r--r--src/assets/icons/camera/flash-on.svg2
-rw-r--r--src/components/camera/FlashButton.tsx53
-rw-r--r--src/components/camera/styles.tsx27
-rw-r--r--src/components/moments/TrimmerPlayer.tsx11
-rw-r--r--src/screens/moments/CameraScreen.tsx171
-rw-r--r--src/utils/camera.ts24
7 files changed, 169 insertions, 121 deletions
diff --git a/src/assets/icons/camera/flash-off.svg b/src/assets/icons/camera/flash-off.svg
index fb04efd2..b4608b75 100644
--- a/src/assets/icons/camera/flash-off.svg
+++ b/src/assets/icons/camera/flash-off.svg
@@ -1 +1 @@
-<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 720"><defs><style>.cls-1{fill:#fff;}</style></defs><path class="cls-1" d="M361.84,13.57,128.3,360c-3.94,2.81-6.8,11.94-7.74,16.16-4.5,29.23,19.23,41.69,31.66,44.27H289.39l-26,253c-2.11,10.3-1.13,33.3,19.69,42.86s38.69-1.18,45-7.73l260.27-373.1,9.85-16.16c8.44-32.61-14.78-46.38-27.44-49.19H400.53L427.26,38.16c1.13-17.42-11.26-29.28-17.59-33C386.6-7.23,368.17,5.61,361.84,13.57Z"/></svg> \ No newline at end of file
+<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 720"><defs><style>.cls-1{fill:#fff;}</style></defs><path class="cls-1" d="M413.14,36.09,387.86,255.37h5.7L251.35,397.57H153c-11.76-2.43-34.2-14.21-29.95-41.86.89-4,3.6-12.62,7.32-15.28L351.28,12.83c6-7.53,23.41-19.67,45.23-8C402.5,8.4,414.2,19.61,413.14,36.09Z"/><path class="cls-1" d="M594.91,341l-9.32,15.28L339.45,709.1c-6,6.2-22.89,16.35-42.58,7.31s-20.62-30.78-18.63-40.53L297,493.2,495.79,294.46H569C580.94,297.12,602.89,310.14,594.91,341Z"/><path class="cls-1" d="M634.48,114.82a29,29,0,0,1-8.5,20.53L486.15,275.18,287.4,473.92,135.09,626.24A29,29,0,1,1,94,585.18l167.8-167.8L404,275.18,584.92,94.29a29,29,0,0,1,49.56,20.53Z"/></svg> \ No newline at end of file
diff --git a/src/assets/icons/camera/flash-on.svg b/src/assets/icons/camera/flash-on.svg
index b4608b75..fb04efd2 100644
--- a/src/assets/icons/camera/flash-on.svg
+++ b/src/assets/icons/camera/flash-on.svg
@@ -1 +1 @@
-<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 720"><defs><style>.cls-1{fill:#fff;}</style></defs><path class="cls-1" d="M413.14,36.09,387.86,255.37h5.7L251.35,397.57H153c-11.76-2.43-34.2-14.21-29.95-41.86.89-4,3.6-12.62,7.32-15.28L351.28,12.83c6-7.53,23.41-19.67,45.23-8C402.5,8.4,414.2,19.61,413.14,36.09Z"/><path class="cls-1" d="M594.91,341l-9.32,15.28L339.45,709.1c-6,6.2-22.89,16.35-42.58,7.31s-20.62-30.78-18.63-40.53L297,493.2,495.79,294.46H569C580.94,297.12,602.89,310.14,594.91,341Z"/><path class="cls-1" d="M634.48,114.82a29,29,0,0,1-8.5,20.53L486.15,275.18,287.4,473.92,135.09,626.24A29,29,0,1,1,94,585.18l167.8-167.8L404,275.18,584.92,94.29a29,29,0,0,1,49.56,20.53Z"/></svg> \ No newline at end of file
+<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 720"><defs><style>.cls-1{fill:#fff;}</style></defs><path class="cls-1" d="M361.84,13.57,128.3,360c-3.94,2.81-6.8,11.94-7.74,16.16-4.5,29.23,19.23,41.69,31.66,44.27H289.39l-26,253c-2.11,10.3-1.13,33.3,19.69,42.86s38.69-1.18,45-7.73l260.27-373.1,9.85-16.16c8.44-32.61-14.78-46.38-27.44-49.19H400.53L427.26,38.16c1.13-17.42-11.26-29.28-17.59-33C386.6-7.23,368.17,5.61,361.84,13.57Z"/></svg> \ No newline at end of file
diff --git a/src/components/camera/FlashButton.tsx b/src/components/camera/FlashButton.tsx
index 06a4e44e..65c773d9 100644
--- a/src/components/camera/FlashButton.tsx
+++ b/src/components/camera/FlashButton.tsx
@@ -1,8 +1,9 @@
+import {BlurView} from '@react-native-community/blur';
import React, {Dispatch, SetStateAction} from 'react';
-import {Text, TouchableOpacity} from 'react-native';
+import {Text, TouchableOpacity, View} from 'react-native';
import {FlashMode} from 'react-native-camera';
-import FlashOffIcon from '../../assets/icons/camera/flash-off.svg';
import FlashOnIcon from '../../assets/icons/camera/flash-on.svg';
+import FlashOffIcon from '../../assets/icons/camera/flash-off.svg';
import {styles} from './styles';
interface FlashButtonProps {
@@ -16,27 +17,33 @@ interface FlashButtonProps {
export const FlashButton: React.FC<FlashButtonProps> = ({
flashMode,
setFlashMode,
-}) => (
- <TouchableOpacity
- onPress={() => setFlashMode(flashMode === 'on' ? 'off' : 'on')}
- style={styles.flashButtonContainer}>
- {flashMode === 'on' ? (
- <FlashOnIcon
- height={30}
- width={20}
- color={'white'}
- style={styles.flashIcon}
- />
- ) : (
- <FlashOffIcon
- height={30}
- width={20}
- color={'white'}
- style={styles.flashIcon}
+}) => {
+ return (
+ <>
+ <BlurView
+ blurType={'ultraThinMaterialDark'}
+ blurAmount={1}
+ style={styles.blurView}
/>
- )}
- <Text style={styles.saveButtonLabel}>Flash</Text>
- </TouchableOpacity>
-);
+ <TouchableOpacity
+ onPress={() => setFlashMode(flashMode === 'on' ? 'off' : 'on')}
+ style={styles.flashButtonContainerBackground}>
+ <View
+ style={[
+ styles.flashButtonContainer,
+ // eslint-disable-next-line react-native/no-inline-styles
+ {opacity: flashMode === 'off' ? 0.5 : 1},
+ ]}>
+ {flashMode === 'off' ? (
+ <FlashOffIcon height={30} width={20} color={'white'} />
+ ) : (
+ <FlashOnIcon height={30} width={20} color={'white'} />
+ )}
+ <Text style={styles.saveButtonLabel}>Flash</Text>
+ </View>
+ </TouchableOpacity>
+ </>
+ );
+};
export default FlashButton;
diff --git a/src/components/camera/styles.tsx b/src/components/camera/styles.tsx
index 33b47cc4..dbe1500b 100644
--- a/src/components/camera/styles.tsx
+++ b/src/components/camera/styles.tsx
@@ -18,9 +18,16 @@ export const styles = StyleSheet.create({
zIndex: 999,
},
flashButtonContainer: {
+ zIndex: 3,
+ height: 86,
+ width: 49,
+ flexDirection: 'column',
+ justifyContent: 'center',
+ alignItems: 'center',
+ borderRadius: 30,
+ },
+ flashButtonContainerBackground: {
position: 'absolute',
- backgroundColor: '#808080',
- opacity: 0.25,
zIndex: 1,
top: normalize(50),
right: 0,
@@ -30,7 +37,7 @@ export const styles = StyleSheet.create({
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
- borderRadius: 30,
+ borderRadius: 50,
},
galleryIcon: {
borderWidth: 2,
@@ -47,7 +54,17 @@ export const styles = StyleSheet.create({
height: 40,
backgroundColor: 'grey',
},
- flashIcon: {
- zIndex: 2,
+ blurView: {
+ position: 'absolute',
+ zIndex: 1,
+ top: normalize(50),
+ right: 0,
+ marginRight: normalize(18),
+ height: 86,
+ width: 49,
+ flexDirection: 'column',
+ justifyContent: 'center',
+ alignItems: 'center',
+ borderRadius: 24.5,
},
});
diff --git a/src/components/moments/TrimmerPlayer.tsx b/src/components/moments/TrimmerPlayer.tsx
index 8d1cd156..daec98cf 100644
--- a/src/components/moments/TrimmerPlayer.tsx
+++ b/src/components/moments/TrimmerPlayer.tsx
@@ -25,13 +25,22 @@ const TrimmerPlayer: React.FC<TrimmerPlayerProps> = ({
const playerRef = useRef<Video>();
// Stores where the video is playing (seekTime)
const [seekTime, setSeekTime] = useState<number>(0);
- const [paused, setPaused] = useState<boolean>(false);
+ const [paused, setPaused] = useState<boolean>(true);
// Stores where the tracker is
const [trackerTime, setTrackerTime] = useState<number>(0);
// Stores start/end of desired trimmed video
const [end, setEnd] = useState<number>(60);
const [start, setStart] = useState<number>(0);
+ // Slight delay to play video since RNCamera can't record and play video here
+ // at the same time.
+ // see: https://github.com/react-native-camera/react-native-camera/issues/2592
+ useEffect(() => {
+ setTimeout(() => {
+ setPaused(false);
+ }, 1000);
+ }, []);
+
useEffect(() => {
playerRef.current?.seek(seekTime);
}, [seekTime]);
diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx
index 07b697d0..bd94bf63 100644
--- a/src/screens/moments/CameraScreen.tsx
+++ b/src/screens/moments/CameraScreen.tsx
@@ -3,7 +3,7 @@ import {useBottomTabBarHeight} from '@react-navigation/bottom-tabs';
import {RouteProp} from '@react-navigation/core';
import {useFocusEffect} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
-import React, {createRef, useCallback, useEffect, useState} from 'react';
+import React, {useCallback, useEffect, useRef, useState} from 'react';
import {Modal, StyleSheet, TouchableOpacity, View} from 'react-native';
import {CameraType, FlashMode, RNCamera} from 'react-native-camera';
import {AnimatedCircularProgress} from 'react-native-circular-progress';
@@ -25,19 +25,35 @@ interface CameraScreenProps {
}
const CameraScreen: React.FC<CameraScreenProps> = ({route, navigation}) => {
const {screenType, selectedCategory} = route.params;
- const cameraRef = createRef<RNCamera>();
+ const cameraRef = useRef<RNCamera>(null);
const tabBarHeight = useBottomTabBarHeight();
const [cameraType, setCameraType] = useState<keyof CameraType>('back');
const [flashMode, setFlashMode] = useState<keyof FlashMode>('off');
const [mostRecentPhoto, setMostRecentPhoto] = useState<string>('');
- const [isRecording, setIsRecording] = useState<boolean>(false);
+ const [recordingStarted, setRecordingStarted] = useState<boolean>(false);
+ const [showCaptureButtons, setShowCaptureButtons] = useState<boolean>(false);
+ const [showCamera, setShowCamera] = useState<boolean>(true);
+ const [videoUri, setVideoUri] = useState<string | undefined>();
+
+ useEffect(() => {
+ if (recordingStarted && videoUri) {
+ navigateToEditMedia(videoUri);
+ }
+ }, [videoUri]);
useFocusEffect(
useCallback(() => {
navigation.dangerouslyGetParent()?.setOptions({
tabBarVisible: false,
});
- return () => setIsRecording(false);
+ setRecordingStarted(false);
+ setShowCaptureButtons(true);
+ setShowCamera(true);
+ return () => {
+ setTimeout(() => {
+ setShowCamera(false);
+ }, 500);
+ };
}, [navigation]),
);
@@ -58,7 +74,6 @@ const CameraScreen: React.FC<CameraScreenProps> = ({route, navigation}) => {
}, []);
const navigateToEditMedia = (uri: string) => {
- cameraRef.current?.resumePreview();
navigation.navigate('EditMedia', {
screenType,
media: {
@@ -87,93 +102,83 @@ const CameraScreen: React.FC<CameraScreenProps> = ({route, navigation}) => {
<View style={styles.container}>
<Modal
transparent={true}
- visible={isRecording && cameraType === 'front' && flashMode === 'on'}>
+ visible={
+ recordingStarted && cameraType === 'front' && flashMode === 'on'
+ }>
<View style={styles.flashView} />
</Modal>
<TouchableOpacity style={styles.closeButton} onPress={handleClose}>
<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={() => {
- setCameraType(cameraType === 'front' ? 'back' : 'front');
- }}
- />
- <View style={[styles.bottomContainer, {bottom: tabBarHeight}]}>
- <FlipButton cameraType={cameraType} setCameraType={setCameraType} />
- <TouchableOpacity
- style={
- isRecording
- ? styles.captureButtonVideoContainer
- : styles.captureButtonContainer
+ {showCamera && (
+ <RNCamera
+ ref={cameraRef}
+ style={styles.camera}
+ type={cameraType}
+ flashMode={
+ flashMode === 'on' && recordingStarted && cameraType === 'back'
+ ? 'torch'
+ : flashMode
}
- activeOpacity={1}
- onLongPress={() => {
- takeVideo(cameraRef, (vid) => navigateToEditMedia(vid.uri));
- setIsRecording(true);
- }}
- onPressOut={async () => {
- const cancelRecording = async () => {
- if (await cameraRef.current?.isRecording()) {
- cameraRef.current?.stopRecording();
- setIsRecording(false);
- }
- };
- cancelRecording();
- // tmp fix for when the animation glitches during the beginning of
- // recording causing onPressOut to not be detected.
- setTimeout(() => {
- cancelRecording();
- }, 500);
- setTimeout(() => {
- cancelRecording();
- }, 1000);
- setTimeout(() => {
- cancelRecording();
- }, 1500);
+ onDoubleTap={() => {
+ if (showCaptureButtons) {
+ setCameraType(cameraType === 'front' ? 'back' : 'front');
+ }
}}
- onPress={() => {
- takePicture(cameraRef, (pic) => navigateToEditMedia(pic.uri));
- }}>
- <View style={styles.captureButton} />
- </TouchableOpacity>
- {isRecording && (
- <AnimatedCircularProgress
- size={95}
- width={6}
- fill={100}
- rotation={0}
- duration={(MAX_VIDEO_RECORDING_DURATION + 1) * 1000} // an extra second for UI to load
- tintColor={TAGG_PURPLE}
- style={styles.bottomContainer}
- lineCap={'round'}
- />
- )}
- <View style={styles.bottomRightContainer}>
- <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);
- }
- }}
- />
+ onRecordingStart={() => setRecordingStarted(true)}
+ />
+ )}
+ {showCaptureButtons && (
+ <View style={[styles.bottomContainer, {bottom: tabBarHeight}]}>
+ <FlipButton cameraType={cameraType} setCameraType={setCameraType} />
+ <TouchableOpacity
+ style={
+ recordingStarted
+ ? styles.captureButtonVideoContainer
+ : styles.captureButtonContainer
+ }
+ activeOpacity={1}
+ onLongPress={() =>
+ takeVideo(cameraRef, (vid) => setVideoUri(vid.uri))
+ }
+ onPressOut={() => cameraRef.current?.stopRecording()}
+ onPress={() => {
+ setShowCaptureButtons(false);
+ takePicture(cameraRef, (pic) => navigateToEditMedia(pic.uri));
+ }}>
+ <View style={styles.captureButton} />
+ </TouchableOpacity>
+ {recordingStarted && (
+ <AnimatedCircularProgress
+ size={95}
+ width={6}
+ fill={100}
+ rotation={0}
+ duration={(MAX_VIDEO_RECORDING_DURATION + 1) * 1000} // an extra second for UI to load
+ tintColor={TAGG_PURPLE}
+ style={styles.bottomContainer}
+ lineCap={'round'}
+ />
+ )}
+ <View style={styles.bottomRightContainer}>
+ <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>
+ )}
</View>
);
};
diff --git a/src/utils/camera.ts b/src/utils/camera.ts
index ec2615de..6edc2b4f 100644
--- a/src/utils/camera.ts
+++ b/src/utils/camera.ts
@@ -24,15 +24,20 @@ 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);
- });
+ cameraRef.current
+ ?.takePictureAsync(options)
+ .then((pic) => {
+ callback(pic);
+ })
+ .catch((error) => {
+ console.log(error);
+ });
}
};
@@ -46,9 +51,14 @@ export const takeVideo = (
maxDuration: MAX_VIDEO_RECORDING_DURATION,
quality: '1080p',
};
- cameraRef.current?.recordAsync(options).then((vid) => {
- callback(vid);
- });
+ cameraRef.current
+ ?.recordAsync(options)
+ .then((vid) => {
+ callback(vid);
+ })
+ .catch((error) => {
+ console.log(error);
+ });
}
};