-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageUploadComponent.jsx
More file actions
57 lines (51 loc) · 1.85 KB
/
ImageUploadComponent.jsx
File metadata and controls
57 lines (51 loc) · 1.85 KB
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
53
54
55
56
57
import { View, Text, TouchableOpacity, Image } from 'react-native';
import React, { useState } from 'react';
import Colors from '../../constants/Colors';
import * as ImagePicker from 'expo-image-picker';
export default function ImageUploadComponent({ uploadedImage }) {
const [image, setImage] = useState();
const pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ['images','videos'], // Fixed mediaTypes option
allowsEditing: false,
aspect: [4, 3],
quality: 1,
});
console.log(result);
if(!result.canceled) {
uploadedImage(result.assets[0].uri);
setImage(result.assets[0].uri);
}
};
return (
<View>
<Text style={{ marginVertical: 5 }}>Upload your image</Text>
<TouchableOpacity
onPress={pickImage}
style={{
padding: 50,
backgroundColor: Colors.LIGHT_GRAY,
borderRadius: 15,
marginVertical: 10,
width: '100%',
display: 'flex',
alignItems: 'center'
}}>
{image ? (
<Image source={{ uri: image }}
style={{
width: '100%',
height: 300,
borderRadius: 15
}} />
) : (
<Image source={require('./../../assets/images/upload.png')}
style={{
width: 70,
height: 70
}} />
)}
</TouchableOpacity>
</View>
);
}