implements method pickImageFromCamera
This commit is contained in:
parent
17be449d4e
commit
70e6ae40cf
|
@ -0,0 +1,80 @@
|
|||
import * as FileSystem from 'expo-file-system';
|
||||
import * as ImagePicker from 'expo-image-picker';
|
||||
import { PermissionsAndroid } from 'react-native';
|
||||
|
||||
import { isAndroid } from './helpers';
|
||||
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 (allowsEditing = false): Promise<ImagePicker.ImagePickerResult | null> => {
|
||||
try {
|
||||
if (isAndroid) {
|
||||
const permissions = await PermissionsAndroid.requestMultiple([
|
||||
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
|
||||
PermissionsAndroid.PERMISSIONS.CAMERA
|
||||
]);
|
||||
if (permissions['android.permission.CAMERA'] !== 'granted') {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
const permission = await ImagePicker.requestCameraPermissionsAsync();
|
||||
if (!permission.granted) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const permission = await ImagePicker.getCameraPermissionsAsync();
|
||||
if (!permission.granted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const result = await ImagePicker.launchCameraAsync({
|
||||
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
||||
quality: 1,
|
||||
allowsEditing
|
||||
});
|
||||
|
||||
if (!result.cancelled) {
|
||||
const file = await FileSystem.getInfoAsync(result.uri);
|
||||
const data = {
|
||||
...result,
|
||||
path: result.uri,
|
||||
filename: `${file.uri.substring(file.uri.lastIndexOf('/') + 1)}`,
|
||||
size: file.size,
|
||||
mime: 'image/jpeg'
|
||||
};
|
||||
return data;
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
log(error);
|
||||
return null;
|
||||
}
|
||||
};
|
|
@ -11,12 +11,17 @@ PODS:
|
|||
- ReactCommon
|
||||
- EXFileSystem (14.0.0):
|
||||
- ExpoModulesCore
|
||||
- EXImageLoader (3.2.0):
|
||||
- ExpoModulesCore
|
||||
- React-Core
|
||||
- EXLocalAuthentication (12.2.0):
|
||||
- ExpoModulesCore
|
||||
- Expo (45.0.5):
|
||||
- ExpoModulesCore
|
||||
- ExpoHaptics (11.2.0):
|
||||
- ExpoModulesCore
|
||||
- ExpoImagePicker (13.1.1):
|
||||
- ExpoModulesCore
|
||||
- ExpoKeepAwake (10.1.1):
|
||||
- ExpoModulesCore
|
||||
- ExpoModulesCore (0.9.2):
|
||||
|
@ -591,9 +596,11 @@ DEPENDENCIES:
|
|||
- EXAppleAuthentication (from `../node_modules/expo-apple-authentication/ios`)
|
||||
- EXAV (from `../node_modules/expo-av/ios`)
|
||||
- EXFileSystem (from `../node_modules/expo-file-system/ios`)
|
||||
- EXImageLoader (from `../node_modules/expo-image-loader/ios`)
|
||||
- EXLocalAuthentication (from `../node_modules/expo-local-authentication/ios`)
|
||||
- Expo (from `../node_modules/expo/ios`)
|
||||
- ExpoHaptics (from `../node_modules/expo-haptics/ios`)
|
||||
- ExpoImagePicker (from `../node_modules/expo-image-picker/ios`)
|
||||
- ExpoKeepAwake (from `../node_modules/expo-keep-awake/ios`)
|
||||
- ExpoModulesCore (from `../node_modules/expo-modules-core/ios`)
|
||||
- ExpoWebBrowser (from `../node_modules/expo-web-browser/ios`)
|
||||
|
@ -716,12 +723,16 @@ EXTERNAL SOURCES:
|
|||
:path: "../node_modules/expo-av/ios"
|
||||
EXFileSystem:
|
||||
:path: "../node_modules/expo-file-system/ios"
|
||||
EXImageLoader:
|
||||
:path: "../node_modules/expo-image-loader/ios"
|
||||
EXLocalAuthentication:
|
||||
:path: "../node_modules/expo-local-authentication/ios"
|
||||
Expo:
|
||||
:path: "../node_modules/expo/ios"
|
||||
ExpoHaptics:
|
||||
:path: "../node_modules/expo-haptics/ios"
|
||||
ExpoImagePicker:
|
||||
:path: "../node_modules/expo-image-picker/ios"
|
||||
ExpoKeepAwake:
|
||||
:path: "../node_modules/expo-keep-awake/ios"
|
||||
ExpoModulesCore:
|
||||
|
@ -893,9 +904,11 @@ SPEC CHECKSUMS:
|
|||
EXAppleAuthentication: 709a807fe7f48ac6986a2ceed206ee6a8baf28df
|
||||
EXAV: 88f61c5af8415715b7ee51f084c1020235b85c56
|
||||
EXFileSystem: 2aa2d9289f84bca9532b9ccbd81504fa31eb1ded
|
||||
EXImageLoader: b88e053d760f85a82405b1db2de4abf11978fc9f
|
||||
EXLocalAuthentication: 7f37b242eae73f9acf111d39bdee3f1379e68902
|
||||
Expo: b9fff0a1eac0f424fc68ea49b4347fb308e52e17
|
||||
ExpoHaptics: ad58ec96a25e57579c14a47c7d71f0de0de8656a
|
||||
ExpoImagePicker: d9d6b4f29db437fc7796f13cee5f133f5b4b5f7c
|
||||
ExpoKeepAwake: c0c494b442ecd8122974c13b93ccfb57bd408e88
|
||||
ExpoModulesCore: e4278a668e8c13c0269ed8b8a4200989deea2973
|
||||
ExpoWebBrowser: 4b5f9633e5f169dc948587cb6d26d2d1d1406187
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
index 3e84862..f683796 100644
|
||||
--- a/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/ImagePickerModule.kt
|
||||
+++ b/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/ImagePickerModule.kt
|
||||
@@ -140,17 +140,7 @@ class ImagePickerModule(
|
||||
return
|
||||
}
|
||||
|
||||
- val permissionsResponseHandler = PermissionsResponseListener { permissionsResponse: Map<String, PermissionsResponse> ->
|
||||
- if (permissionsResponse[Manifest.permission.WRITE_EXTERNAL_STORAGE]?.status == PermissionsStatus.GRANTED &&
|
||||
- permissionsResponse[Manifest.permission.CAMERA]?.status == PermissionsStatus.GRANTED
|
||||
- ) {
|
||||
- launchCameraWithPermissionsGranted(promise, cameraIntent, pickerOptions)
|
||||
- } else {
|
||||
- promise.reject(SecurityException("User rejected permissions"))
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- mPermissions.askForPermissions(permissionsResponseHandler, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
|
||||
+ return launchCameraWithPermissionsGranted(promise, cameraIntent, pickerOptions)
|
||||
}
|
||||
|
||||
// NOTE: Currently not reentrant / doesn't support concurrent requests
|
19
yarn.lock
19
yarn.lock
|
@ -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, 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"
|
||||
|
|
Loading…
Reference in New Issue