Nekshay commited on
Commit
d9f5705
·
1 Parent(s): 9c8790e

Update mobileapp.txt

Browse files
Files changed (1) hide show
  1. mobileapp.txt +20 -8
mobileapp.txt CHANGED
@@ -1,18 +1,30 @@
1
- import React, { useState } from 'react';
2
  import { View, Image, TouchableOpacity, Text } from 'react-native';
3
- import ImagePicker from 'react-native-image-picker';
4
  import { ImageEditor } from 'react-native';
5
 
6
  const CropImage = () => {
7
  const [croppedImage, setCroppedImage] = useState(null); // State to store the cropped image URI
8
 
9
- const handleSelectImage = () => {
10
- ImagePicker.showImagePicker({ mediaType: 'photo' }, (response) => {
11
- if (!response.didCancel) {
12
- const { uri } = response;
13
- cropImage(uri);
14
- }
 
 
 
 
 
 
 
 
15
  });
 
 
 
 
16
  };
17
 
18
  const cropImage = (imageUri) => {
 
1
+ import React, { useState, useEffect } from 'react';
2
  import { View, Image, TouchableOpacity, Text } from 'react-native';
3
+ import * as ImagePicker from 'expo-image-picker';
4
  import { ImageEditor } from 'react-native';
5
 
6
  const CropImage = () => {
7
  const [croppedImage, setCroppedImage] = useState(null); // State to store the cropped image URI
8
 
9
+ useEffect(() => {
10
+ getPermission();
11
+ }, []);
12
+
13
+ const getPermission = async () => {
14
+ const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
15
+ if (status !== 'granted') {
16
+ alert('Permission denied!');
17
+ }
18
+ };
19
+
20
+ const handleSelectImage = async () => {
21
+ let result = await ImagePicker.launchImageLibraryAsync({
22
+ mediaTypes: ImagePicker.MediaTypeOptions.Images,
23
  });
24
+
25
+ if (!result.cancelled) {
26
+ cropImage(result.uri);
27
+ }
28
  };
29
 
30
  const cropImage = (imageUri) => {