-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathConfirmScreen.js
91 lines (76 loc) · 2.07 KB
/
ConfirmScreen.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
import React from 'react';
import {decode as atob, encode as btoa} from 'base-64';
import { StyleSheet, Text, View, TouchableOpacity, Dimensions, Image, Button } from 'react-native';
function arrayBufferToBase64(buffer) {
var binary = '';
var bytes = [].slice.call(new Uint8Array(buffer));
bytes.forEach((b) => binary += String.fromCharCode(b));
return window.btoa(binary);
};
class ConfirmScreen extends React.PureComponent {
static navigationOptions = {
title: 'Select Region to Scan',
headerStyle: {
backgroundColor: '#0003C7',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
};
constructor(props) {
super(props);
this.state = {
grayscale: null
}
}
processImage = (photo) => {
fetch('https://tranquil-atoll-18580.herokuapp.com/scan', {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: 'POST',
body: JSON.stringify({
'image': photo.base64
})
})
.then(response => response.json())
.then((response) => {
console.log(response);
const image = response.image;
this.props.navigation.navigate('Result', {image});
})
.catch(error => console.log(error));
}
render() {
const { navigation } = this.props;
const photo = navigation.getParam('photo', {});
const { uri } = photo;
return (
<View style={styles.container}>
<Image
style={{
width: Dimensions.get('window').width,
height: Dimensions.get('window').width * 4 / 3
}}
source={{uri}} />
<TouchableOpacity style={styles.confirmBtn}>
<Button style={{padding: "2.5 5"}} title="Confirm Selection" onPress={this.processImage(photo)} />
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
justifyContent: "center",
},
confirmBtn: {
display: "flex",
justifyContent: "center",
alignItems: "center",
paddingTop: 5,
}
});
export default ConfirmScreen