-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathImageManager.js
52 lines (43 loc) · 1.39 KB
/
ImageManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// import React, { useState } from 'react';
import { Alert } from 'react-native';
import * as ImagePicker from 'expo-image-picker';
const requestCameraPermission = async () => {
const { status } = await ImagePicker.requestCameraPermissionsAsync();
if (status !== 'granted') {
Alert.alert('Permission Denied', 'Camera access is required to take a photo.');
return false;
}
return true;
};
const requestLibraryPermission = async () => {
const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (status !== 'granted') {
Alert.alert('Permission Denied', 'Media library access is required to select a photo.');
return false;
}
return true;
};
export const handleSelectImage = async () => {
const hasPermission = await requestLibraryPermission();
if (!hasPermission) return;
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsMultipleSelection: true,
selectionLimit: 10,
quality: 1,
});
if (!result.canceled) {
const uriList = result.assets.map((asset) => asset.uri);
return uriList;
}
};
export const handleTakePhoto = async () => {
const hasPermission = await requestCameraPermission();
if (!hasPermission) return;
const result = await ImagePicker.launchCameraAsync({
quality: 1,
});
if (!result.canceled) {
return result.assets[0].uri;
}
};