This commit is contained in:
Gleidson Daniel 2022-08-22 12:07:17 -03:00
parent 17be449d4e
commit 75ae38edfa
4 changed files with 84 additions and 6 deletions

View File

@ -2,7 +2,7 @@ import React, { Component } from 'react';
import { Alert, Keyboard, NativeModules, Text, View } from 'react-native';
import { connect } from 'react-redux';
import { KeyboardAccessoryView } from 'react-native-ui-lib/keyboard';
import ImagePicker, { Image, ImageOrVideo, Options } from 'react-native-image-crop-picker';
import ImagePicker, { ImageOrVideo, Options } from 'react-native-image-crop-picker';
import { dequal } from 'dequal';
import DocumentPicker from 'react-native-document-picker';
import { Q } from '@nozbe/watermelondb';
@ -59,6 +59,7 @@ import { hasPermission, debounce, isAndroid, isIOS, isTablet } from '../../lib/m
import { Services } from '../../lib/services';
import { TSupportedThemes } from '../../theme';
import { ChatsStackParamList } from '../../stacks/types';
import { pickImageFromCamera } from '../../lib/methods/mediaPicker';
require('./EmojiKeyboard');
@ -711,11 +712,14 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
takePhoto = async () => {
logEvent(events.ROOM_BOX_ACTION_PHOTO);
try {
let image = (await ImagePicker.openCamera(this.imagePickerConfig)) as Image;
image = forceJpgExtension(image);
if (this.canUploadFile(image)) {
this.openShareView([image]);
}
const image = await pickImageFromCamera();
console.log(image);
// let image = (await ImagePicker.openCamera(this.imagePickerConfig)) as Image;
// image = forceJpgExtension(image);
// if (this.canUploadFile(image)) {
// this.openShareView([image]);
// }
} catch (e) {
logEvent(events.ROOM_BOX_ACTION_PHOTO_F);
}

View File

@ -0,0 +1,54 @@
import * as ImagePicker from 'expo-image-picker';
import log from './helpers/log';
export const pickImage = async (editImage = true): Promise<ImagePicker.ImagePickerResult | null> => {
try {
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: editImage,
quality: 0
});
return result;
} catch (error) {
log(error);
return null;
}
};
export const pickVideo = async (editImage = true): Promise<ImagePicker.ImagePickerResult | null> => {
try {
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Videos,
allowsEditing: editImage,
quality: 0
});
return result;
} catch (error) {
log(error);
return null;
}
};
export const pickImageFromCamera = async (): Promise<ImagePicker.ImagePickerResult | null> => {
try {
const permissionResult = await ImagePicker.requestCameraPermissionsAsync();
console.log(permissionResult);
if (permissionResult.granted === false) {
return null;
}
const result = await ImagePicker.launchCameraAsync();
console.log(result);
if (!result.cancelled) {
console.log(result);
return result;
}
return null;
} catch (error) {
log(error);
return null;
}
};

View File

@ -65,6 +65,7 @@
"expo-av": "11.2.3",
"expo-file-system": "14.0.0",
"expo-haptics": "11.2.0",
"expo-image-picker": "13.1.1",
"expo-keep-awake": "10.1.1",
"expo-local-authentication": "12.2.0",
"expo-video-thumbnails": "6.3.0",

View File

@ -10628,6 +10628,20 @@ expo-haptics@11.2.0:
resolved "https://registry.yarnpkg.com/expo-haptics/-/expo-haptics-11.2.0.tgz#0ffb9f82395e88f9f66ceebb0f3279739311412c"
integrity sha512-ijuWU2ljLBGjIf7OQCvnBQIu/chezndnWkfi518XxvK0hudA4+fAe98mqHO6hom9GexNRxhQZbXc0hcVnxkaiA==
expo-image-loader@~3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/expo-image-loader/-/expo-image-loader-3.2.0.tgz#d98b021660edef7243f7c5ec011b8d0545626d41"
integrity sha512-LU3Q2prn64/HxdToDmxgMIRXS1ZvD9Q3iCxRVTZn1fPQNNDciIQFE5okaa74Ogx20DFHs90r6WoUd7w9Af1OGQ==
expo-image-picker@13.1.1:
version "13.1.1"
resolved "https://registry.yarnpkg.com/expo-image-picker/-/expo-image-picker-13.1.1.tgz#e039bf9748ccb7b89370ff2969c3ef07cc949192"
integrity sha512-fU8oONRkKg5DvuU+7KvnuOtf1ubzXNU/OsE/T6yB149LbXb+ZN5A49NicvJ+cOG4Oa5NAnILt0aAAkchIr3iRQ==
dependencies:
"@expo/config-plugins" "^4.0.14"
expo-image-loader "~3.2.0"
uuid "7.0.2"
expo-keep-awake@10.1.1, expo-keep-awake@~10.1.1:
version "10.1.1"
resolved "https://registry.yarnpkg.com/expo-keep-awake/-/expo-keep-awake-10.1.1.tgz#03023c130f7e3824b738e3fdd5353b8a2c0c1980"
@ -20162,6 +20176,11 @@ utils-merge@1.0.1:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=
uuid@7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-7.0.2.tgz#7ff5c203467e91f5e0d85cfcbaaf7d2ebbca9be6"
integrity sha512-vy9V/+pKG+5ZTYKf+VcphF5Oc6EFiu3W8Nv3P3zIh0EqVI80ZxOzuPfe9EHjkFNvf8+xuTHVeei4Drydlx4zjw==
uuid@^3.0.1, uuid@^3.3.2, uuid@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"