-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarcodeScreen.js
More file actions
77 lines (66 loc) · 1.79 KB
/
Copy pathBarcodeScreen.js
File metadata and controls
77 lines (66 loc) · 1.79 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
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Dimensions, AsyncStorage} from 'react-native';
import Camera from 'react-native-camera';
class BarcodeScreen extends Component {
static navigationOptions =
{
title: 'Select Store',
};
constructor(props) {
super(props);
this.state = {
}
}
async saveKey (key, value) {
try {
await AsyncStorage.setItem(key, JSON.stringify(value));
} catch (error) {
// Error saving data
}
}
async getKey (key) {
try {
const value = await AsyncStorage.getItem(key);
if (value !== null) {
console.log(value);
}
} catch (error) {
// Error retrieving data
}
}
saveAndGoToReviewScreen = (data) => {
this.saveKey('product_sku', data);
this.props.navigation.navigate('ReviewScreen');
}
onBarCodeRead = (e) => {
this.saveAndGoToReviewScreen(e.data);
}
render() {
return (
<View style={styles.container}>
<Camera
style={styles.preview}
onBarCodeRead={this.onBarCodeRead}
ref={cam => this.camera = cam}
aspect={Camera.constants.Aspect.fill}
>
<Text style={{
backgroundColor: 'white'
}}>{this.state.qrcode}</Text>
</Camera>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center'
}
});
export default BarcodeScreen;