-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
55 lines (49 loc) · 1.34 KB
/
Copy pathApp.js
File metadata and controls
55 lines (49 loc) · 1.34 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
import React, { useState } from 'react';
import { View, Button, Image, StyleSheet } from 'react-native';
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
const App = () => {
const [imageUrl, setImageUrl] = useState(null);
const pressCamera = async () => {
try {
const result = await launchCamera({ mediaType: 'photo' });
if (!result.didCancel) {
setImageUrl(result.assets[0].uri);
console.log(result);
}
} catch (error) {
console.error('Kamera hatası:', error);
}
};
const pressGallery = async () => {
try {
const result = await launchImageLibrary({ mediaType: 'photo' });
if (!result.didCancel) {
setImageUrl(result.assets[0].uri);
console.log(result);
}
} catch (error) {
console.error('Galeri hatası:', error);
}
};
return (
<View style={styles.container}>
<Button onPress={pressCamera} title="Kamera" />
<Button onPress={pressGallery} title="Galeri" />
{imageUrl && <Image style={styles.image} source={{ uri: imageUrl }} />}
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'space-evenly',
alignItems: 'center',
},
image: {
width: 200,
height: 200,
resizeMode: 'cover',
marginVertical: 20,
},
});
export default App;