-
Notifications
You must be signed in to change notification settings - Fork 1
/
App_old.js
86 lines (78 loc) · 2.34 KB
/
App_old.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React, { useRef, useState, useEffect } from 'react';
import { Image, Text, View, TouchableOpacity } from 'react-native';
import { Camera } from 'expo-camera';
/**
* App que implementa una Camera
* @version 1.0 05.04.2020
* @author sergi.grau@fje.edu
*/
export default function App() {
const [tePermisos, permisosAssignats] = useState(null);
//let ruta = useState(null);
const [type, setType] = useState(Camera.Constants.Type.back);
const camera = useRef(null);
async function ferFoto() {
console.log('fer foto');
if (camera.current) {
const options = { quality: 0.5, base64: true };
const data = await camera.current.takePictureAsync(options);
console.log(data.uri);
}
}
useEffect(() => {
(async () => {
const { status } = await Camera.requestPermissionsAsync();
permisosAssignats(status === 'granted');
})();
}, []);
if (tePermisos === null) {
return <View />;
}
if (tePermisos === false) {
return <Text>No accés a la càmera</Text>;
}
return (
<View style={{ flex: 1 }}>
<Image
style={{
width: 50,
height: 50,
}}
source={{ uri: 'https://reactnative.dev/img/tiny_logo.png'}}
/>
<Camera style={{ flex: 1 }} type={type} ref={camera}>
<View
style={{
flex: 1,
backgroundColor: 'transparent',
flexDirection: 'row',
}}>
<TouchableOpacity
style={{
flex: 0.1,
alignSelf: 'flex-end',
alignItems: 'center',
}}
onPress={() => ferFoto()} >
<Text style={{ fontSize: 18, marginBottom: 10, color: 'white' }}> fer foto</Text>
</TouchableOpacity>
<TouchableOpacity
style={{
flex: 0.1,
alignSelf: 'flex-end',
alignItems: 'center',
}}
onPress={() => {
setType(
type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back
);
}}>
<Text style={{ fontSize: 18, marginBottom: 10, color: 'white' }}> canviar càmera </Text>
</TouchableOpacity>
</View>
</Camera>
</View>
);
}