-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
149 lines (100 loc) · 3.05 KB
/
App.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import React, {useState, useEffect, useRef } from 'react';
import { StyleSheet, Text, SafeAreaView, View, TouchableOpacity, Image, Modal } from 'react-native';
import { Camera } from 'expo-camera';
import { FontAwesome } from '@expo/vector-icons';
export default function App() {
const camera = useRef(null);
const [ type, setType ] = useState(Camera.Constants.Type.back);
const [hasPermission, setHaspermission] =useState(null);
const [picture, setPicture] = useState(null);
const [isVisibleModal, setIsVisibleModal] = useState(false);
useEffect(()=>{
(async()=>{
const {status} = await Camera.requestPermissionsAsync();
setHaspermission(status === 'granted');
})();
},[]);
if(hasPermission === null){
return <View/>;
}
if(hasPermission === false){
return (
<View style={{flex: 1, justifyContent: "center", alignItems: 'center'}}>
<Text >Acesso à câmera foi negado</Text>
</View>
);
}
async function takePicture(){
if(camera){
const data = await camera.current.takePictureAsync();
setPicture(data.uri);
setIsVisibleModal(true);
}
}
return (
<SafeAreaView style={styles.container}>
<Camera
ref={camera}
style={
{ flex: 1}
}
type={type}
ratio="16:9"
>
<View style={{flex: 1, backgroundColor: 'transparent', flexDirection: 'row'}}>
<TouchableOpacity
style={{position: "absolute", bottom: 20, left: 20, backgroundColor: '#fff', borderRadius: 50}}
onPress={()=>{
setType(
type === Camera.Constants.Type.back
? Camera.Constants.Type.front:
Camera.Constants.Type.back
);
}}
>
<Image source={require('./assets/change.png')} style={{width: 50, height: 50}}/>
</TouchableOpacity>
</View>
</Camera>
<TouchableOpacity style={styles.button} onPress={takePicture}>
<FontAwesome name="camera" size={25} color="#fff"/>
</TouchableOpacity>
{
picture &&
(<Modal
animationType="slide"
transparent={false}
visible={isVisibleModal}
>
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<TouchableOpacity
onPress={()=>setIsVisibleModal(false)}
>
<FontAwesome name="window-close" size={50} color="#FF0000"/>
</TouchableOpacity>
<Image
style={{
width: '100%', height: '90%', borderRadius: 20
}}
source={{uri: picture}}
/>
</View>
</Modal>)
}
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
button:{
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#121212',
margin: 20,
borderRadius: 10,
height: 50,
}
});