-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
84 lines (79 loc) · 2.08 KB
/
App.js
File metadata and controls
84 lines (79 loc) · 2.08 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
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
import React, { Component } from "react";
import { StyleSheet, Text, TouchableOpacity, View, Alert } from "react-native";
import { handleUpload } from './api/ocr';
import { RNCamera } from "react-native-camera";
import Spinner from 'react-native-loading-spinner-overlay';
export default class App extends Component {
state = {
spinner: false
};
takePicture = async () => {
if (this.camera) {
this.setState({ spinner: true });
const options = { quality: 0.5, base64: true };
const data = await this.camera.takePictureAsync(options);
const text = await handleUpload(data);
this.setState({ spinner: false });
Alert.alert("Texto Extraído", text.data.trim());
}
};
render() {
const { visible } = this.state;
return (
<View style={styles.container}>
<Spinner
visible={this.state.spinner}
textContent={'Processando Imagem... 😉'}
textStyle={styles.spinnerTextStyle}
/>
<RNCamera
ref={camera => {
this.camera = camera;
}}
style={styles.preview}
type={RNCamera.Constants.Type.back}
autoFocus={RNCamera.Constants.AutoFocus.on}
flashMode={RNCamera.Constants.FlashMode.off}
captureAudio={false}
/>
<View style={styles.buttonContainer}>
<TouchableOpacity onPress={this.takePicture} style={styles.capture}>
<Text style={styles.buttonText}> Foto </Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: "column",
backgroundColor: "black"
},
preview: {
flex: 1,
justifyContent: "flex-end",
alignItems: "center"
},
buttonContainer: {
flex: 0,
flexDirection: "row",
justifyContent: "center"
},
spinnerTextStyle: {
color: '#FFF'
},
capture: {
flex: 0,
backgroundColor: "#fff",
borderRadius: 5,
padding: 15,
paddingHorizontal: 20,
alignSelf: "center",
margin: 20
},
buttonText: {
fontSize: 14
},
});