-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
38 lines (33 loc) · 1021 Bytes
/
App.tsx
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
import React, { useEffect } from 'react';
import { Button, View, Alert } from 'react-native';
import * as ImagePicker from 'expo-image-picker';
const App: React.FC = () => {
useEffect(() => {
(async () => {
const { status } = await ImagePicker.requestCameraPermissionsAsync();
if (status !== 'granted') {
Alert.alert('Permission Required', 'Sorry, we need camera permissions to make this work!');
}
})();
}, []);
const pickImage = async () => {
try {
const result = await ImagePicker.launchCameraAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
quality: 1,
});
if (!result.canceled) {
console.log(result.uri);
}
} catch (error) {
console.error("Error while picking image: ", error);
}
};
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Button title="Pick Image" onPress={pickImage} />
</View>
);
};
export default App;