From 80f52fa900817d614680a60f0c35592cf48310b0 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 2 Jul 2021 15:59:07 -0400 Subject: Add long press to take video --- src/utils/camera.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/utils') diff --git a/src/utils/camera.ts b/src/utils/camera.ts index 3937129a..7fa18b7c 100644 --- a/src/utils/camera.ts +++ b/src/utils/camera.ts @@ -2,6 +2,8 @@ import CameraRoll from '@react-native-community/cameraroll'; import {RefObject} from 'react'; import {Alert} from 'react-native'; import { + RecordOptions, + RecordResponse, RNCamera, TakePictureOptions, TakePictureResponse, @@ -29,6 +31,21 @@ export const takePicture = ( } }; +export const takeVideo = ( + cameraRef: RefObject, + callback: (vid: RecordResponse) => void, +) => { + if (cameraRef !== null) { + const options: RecordOptions = { + orientation: 'portrait', + maxDuration: 10, + }; + cameraRef.current?.recordAsync(options).then((vid) => { + callback(vid); + }); + } +}; + export const saveImageToGallery = (capturedImageURI: string) => { CameraRoll.save(capturedImageURI, {album: 'Recents', type: 'photo'}) .then((_res) => Alert.alert('Saved to device!')) -- cgit v1.2.3-70-g09d2 From f62eaec4f70ffaf1c5bf82a831acff542eec4957 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 2 Jul 2021 16:14:30 -0400 Subject: Support picking video from gallery --- src/components/camera/GalleryIcon.tsx | 4 ++-- src/screens/moments/CameraScreen.tsx | 14 +++++++++----- src/utils/camera.ts | 16 +++++++++++----- 3 files changed, 22 insertions(+), 12 deletions(-) (limited to 'src/utils') diff --git a/src/components/camera/GalleryIcon.tsx b/src/components/camera/GalleryIcon.tsx index 8d396550..ca2d2559 100644 --- a/src/components/camera/GalleryIcon.tsx +++ b/src/components/camera/GalleryIcon.tsx @@ -1,12 +1,12 @@ import React from 'react'; import {Image, Text, TouchableOpacity, View} from 'react-native'; import {navigateToImagePicker} from '../../utils/camera'; -import {Image as ImageType} from 'react-native-image-crop-picker'; +import {ImageOrVideo} from 'react-native-image-crop-picker'; import {styles} from './styles'; interface GalleryIconProps { mostRecentPhotoUri: string; - callback: (pic: ImageType) => void; + callback: (media: ImageOrVideo) => void; } /* diff --git a/src/screens/moments/CameraScreen.tsx b/src/screens/moments/CameraScreen.tsx index 0f2e3b5d..c759e5db 100644 --- a/src/screens/moments/CameraScreen.tsx +++ b/src/screens/moments/CameraScreen.tsx @@ -129,7 +129,6 @@ const CameraScreen: React.FC = ({route, navigation}) => { onPressOut={async () => { if (await cameraRef.current?.isRecording()) { cameraRef.current?.stopRecording(); - } else { } }} onPress={() => { @@ -155,15 +154,20 @@ const CameraScreen: React.FC = ({route, navigation}) => { ) : ( { - const filename = pic.filename; + callback={(media) => { + const filename = media.filename; if ( filename && (filename.endsWith('gif') || filename.endsWith('GIF')) ) { - showGIFFailureAlert(() => navigateToCropper(pic.path)); + showGIFFailureAlert(() => navigateToCropper(media.path)); } else { - navigateToCropper(pic.path); + // is this a video? + if (media.duration !== null) { + navigateToCaptionScreen(true, media.path); + } else { + navigateToCropper(media.path); + } } }} /> diff --git a/src/utils/camera.ts b/src/utils/camera.ts index 7fa18b7c..d178fe94 100644 --- a/src/utils/camera.ts +++ b/src/utils/camera.ts @@ -8,7 +8,11 @@ import { TakePictureOptions, TakePictureResponse, } from 'react-native-camera'; -import ImagePicker, {Image, Video} from 'react-native-image-crop-picker'; +import ImagePicker, { + Image, + ImageOrVideo, + Video, +} from 'react-native-image-crop-picker'; import {ERROR_UPLOAD} from '../constants/strings'; /* @@ -52,7 +56,9 @@ export const saveImageToGallery = (capturedImageURI: string) => { .catch((_err) => Alert.alert('Failed to save to device!')); }; -export const navigateToImagePicker = (callback: (pic: Image) => void) => { +export const navigateToImagePicker = ( + callback: (media: ImageOrVideo) => void, +) => { ImagePicker.openPicker({ smartAlbums: [ 'Favorites', @@ -61,10 +67,10 @@ export const navigateToImagePicker = (callback: (pic: Image) => void) => { 'Screenshots', 'UserLibrary', ], - mediaType: 'photo', + mediaType: 'any', }) - .then((pic) => { - callback(pic); + .then((media) => { + callback(media); }) .catch((err) => { if (err.code && err.code !== 'E_PICKER_CANCELLED') { -- cgit v1.2.3-70-g09d2 From c7d3ddbc2c4713c3948908862215277bdb49a33d Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 2 Jul 2021 18:26:20 -0400 Subject: Lint --- src/utils/camera.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/utils') diff --git a/src/utils/camera.ts b/src/utils/camera.ts index d178fe94..283b63e0 100644 --- a/src/utils/camera.ts +++ b/src/utils/camera.ts @@ -8,11 +8,7 @@ import { TakePictureOptions, TakePictureResponse, } from 'react-native-camera'; -import ImagePicker, { - Image, - ImageOrVideo, - Video, -} from 'react-native-image-crop-picker'; +import ImagePicker, {ImageOrVideo, Video} from 'react-native-image-crop-picker'; import {ERROR_UPLOAD} from '../constants/strings'; /* -- cgit v1.2.3-70-g09d2 From db542dce029f0925781a1e15d9c652d252b9a8d2 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 2 Jul 2021 18:35:05 -0400 Subject: Cleanup code --- src/utils/camera.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/utils') diff --git a/src/utils/camera.ts b/src/utils/camera.ts index 283b63e0..c997e8b8 100644 --- a/src/utils/camera.ts +++ b/src/utils/camera.ts @@ -19,11 +19,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); @@ -39,6 +39,7 @@ export const takeVideo = ( const options: RecordOptions = { orientation: 'portrait', maxDuration: 10, + quality: '1080p', }; cameraRef.current?.recordAsync(options).then((vid) => { callback(vid); -- cgit v1.2.3-70-g09d2 From 6b57e63dd0e81c167710649ec7778fedf8118a23 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 2 Jul 2021 18:42:05 -0400 Subject: Change max duration to 60 --- src/utils/camera.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils') diff --git a/src/utils/camera.ts b/src/utils/camera.ts index c997e8b8..4f933b0c 100644 --- a/src/utils/camera.ts +++ b/src/utils/camera.ts @@ -38,7 +38,7 @@ export const takeVideo = ( if (cameraRef !== null) { const options: RecordOptions = { orientation: 'portrait', - maxDuration: 10, + maxDuration: 60, quality: '1080p', }; cameraRef.current?.recordAsync(options).then((vid) => { -- cgit v1.2.3-70-g09d2