-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
101 lines (84 loc) · 2.62 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
import React from 'react';
import { StyleSheet, TouchableHighlight, Image } from 'react-native';
import Camera from 'react-native-camera';
import Inputs from './screens/Inputs.js';
export default class App extends React.Component {
constructor() {
super();
this.state = {
currentPic: '',
currentScreen: "camera"
}
}
takePicture() {
this.camera.capture()
.then((data) => this.setState({currentPic: data, currentScreen: "inputText"}))
.catch(err => console.error(err));
}
gotoCamera() {
this.setState({currentScreen: "camera"});
}
sendPicToServer() {
// fetch(uriBase, {
//
// method: "POST",
// body: JSON.stringify({"url": this.state.imageURL})
// })
// .then(data => data.json()) //waits for the ~promise!~
// .then(data => {
//
// alert("No! :( Your image is not contained!");
// })
// .catch((error) => alert(error));
}
render() {
if(this.state.currentScreen === "camera" || this.props.isCam){
return (
<Camera
ref={(cam) => {
this.camera = cam;
}}
captureTarget={Camera.constants.CaptureTarget.memory}
style={styles.preview}
aspect={Camera.constants.Aspect.fill}>
<TouchableHighlight style={styles.capture} onPress={this.takePicture.bind(this)}
accessibilityLabel={"Take Image"}>
<Image
source={require('./cam.png')} style={{width: 130, height: 100}}
/>
</TouchableHighlight>
</Camera>
);
} else if(this.state.currentScreen === "inputText"){
//alert(JSON.stringify(this.state.currentPic.data));
return <Inputs returnToParent={this.gotoCamera} photo={this.state.currentPic.data}/>;
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
height: 400,
width: 500
},
capture: {
flex: 0,
justifyContent: 'flex-end',
alignItems: 'center',
alignContent: 'center',
backgroundColor: 'transparent',
borderRadius: 5,
padding: 10,
paddingRight: 120,
margin: 40,
height: 100,
width: 150
}
});