aboutsummaryrefslogtreecommitdiff
path: root/src/utils/camera.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/camera.ts')
-rw-r--r--src/utils/camera.ts41
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') {