aboutsummaryrefslogtreecommitdiff
path: root/src/utils/camera.ts
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-07-02 19:26:28 -0400
committerGitHub <noreply@github.com>2021-07-02 19:26:28 -0400
commitf88193340ef5110080732d37c6a6ab69013f7b36 (patch)
tree3de0e277727ef27f23386043c26f1d3f46ba064c /src/utils/camera.ts
parentcef9d8e9908936a10a9aa0069e364ebf5970da4c (diff)
parentc772d0491529b795cc2cb3d87f6dd2ecd1775116 (diff)
Merge pull request #489 from IvanIFChen/tma953-camera-screen-video
[TMA-953] Camera Screen Video
Diffstat (limited to 'src/utils/camera.ts')
-rw-r--r--src/utils/camera.ts32
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') {