diff options
author | Michael <michael.foiani@gmail.com> | 2021-07-06 14:20:26 -0400 |
---|---|---|
committer | Michael <michael.foiani@gmail.com> | 2021-07-06 14:20:26 -0400 |
commit | 843a9d39b99815bc232b4a105e5900f1d29535b5 (patch) | |
tree | 0270d77156d977d47a386a9b9017de33eaae5fa4 /src/utils/camera.ts | |
parent | d41ecbf7e16757c0cfe8738c93b79f2ada5baa98 (diff) | |
parent | f88193340ef5110080732d37c6a6ab69013f7b36 (diff) |
Merge with new master
Diffstat (limited to 'src/utils/camera.ts')
-rw-r--r-- | src/utils/camera.ts | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/utils/camera.ts b/src/utils/camera.ts index 52f29f97..85bf8d73 100644 --- a/src/utils/camera.ts +++ b/src/utils/camera.ts @@ -2,12 +2,18 @@ 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'; +<<<<<<< HEAD import {ProcessingManager} from 'react-native-video-processing'; import ImagePicker, {Image, Video} from 'react-native-image-crop-picker'; +======= +import ImagePicker, {ImageOrVideo, Video} from 'react-native-image-crop-picker'; +>>>>>>> master import {ERROR_UPLOAD} from '../constants/strings'; /* @@ -18,11 +24,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); @@ -30,13 +36,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', @@ -45,15 +69,12 @@ export const navigateToImagePicker = (callback: (pic: Image) => void) => { 'Screenshots', 'UserLibrary', ], - mediaType: 'photo', + mediaType: 'any', }) - .then((pic) => { - console.log(ProcessingManager.compress); - console.log('here'); - ProcessingManager.compress(pic, options.compress) // like VideoPlayer compress options - .then((data: any) => console.log(data)); - console.log('over'); - callback(pic); + .then((media) => { + ProcessingManager.compress(media, options.compress) // like VideoPlayer compress options + .then((data: any) => console.log(data)); + callback(media); }) .catch((err) => { if (err.code && err.code !== 'E_PICKER_CANCELLED') { |