diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/camera.ts | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/utils/camera.ts b/src/utils/camera.ts index 3937129a..4f933b0c 100644 --- a/src/utils/camera.ts +++ b/src/utils/camera.ts @@ -2,11 +2,13 @@ import CameraRoll from '@react-native-community/cameraroll'; import {RefObject} from 'react'; import {Alert} from 'react-native'; import { + RecordOptions, + RecordResponse, RNCamera, TakePictureOptions, TakePictureResponse, } from 'react-native-camera'; -import ImagePicker, {Image, Video} from 'react-native-image-crop-picker'; +import ImagePicker, {ImageOrVideo, Video} from 'react-native-image-crop-picker'; import {ERROR_UPLOAD} from '../constants/strings'; /* @@ -17,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); @@ -29,13 +31,31 @@ export const takePicture = ( } }; +export const takeVideo = ( + cameraRef: RefObject<RNCamera>, + callback: (vid: RecordResponse) => void, +) => { + if (cameraRef !== null) { + const options: RecordOptions = { + orientation: 'portrait', + maxDuration: 60, + quality: '1080p', + }; + 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!')) .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', @@ -44,10 +64,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') { |