-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.android.js
More file actions
94 lines (85 loc) · 2.54 KB
/
Copy pathindex.android.js
File metadata and controls
94 lines (85 loc) · 2.54 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
85
86
87
88
89
90
91
92
93
94
'use strict';
import React, {Component} from 'react';
import {AppRegistry, StyleSheet, Text, View, Image} from 'react-native';
import SwipeCards from 'react-native-swipe-cards';
import _ from 'lodash';
import BarcodeScanner from 'react-native-barcodescanner';
let Card = React.createClass({
render() {
return (
<View style={[styles.card]}>
<Text>{this.props.text}</Text>
<Image style={styles.thumbnail} source={{uri: this.props.imgSource}} />
</View>
)
}
})
export default class FirstApp extends Component {
constructor(props) {
super(props);
this.state = {
cart: [],
cards: []
}
}
barcodeReceived(e) {
if (e.data === '7290000688077') {
this.setState({
cards: [{
text: 'water',
imgSource: 'http://www.lautman.co.il/ProductsImages/G861123.jpg',
backgroundColor: 'blue'
}]
})
} else if (e.data = '7290008909846') {
this.setState({
cards: [{
text: 'cola zero',
imgSource: 'http://www.overcaffeinated.org/sites/default/files/styles/large/public/products/coca_cola_zero_12oz_can.jpg?itok=IhvS0KXB',
backgroundColor: 'black'
}]
})
}
console.log('Barcode: ' + e.data);
console.log('Type: ' + e.type);
}
handleYup(card) {
this.setState({cart: _.concat(this.state.cart, card.text), cards: []});
}
handleNope() {
this.setState({cards: []})
}
render() {
if (_.isEmpty(this.state.cards)) {
return (
<BarcodeScanner
onBarCodeRead={(e) => this.barcodeReceived(e)}
style={{ flex: 1 }}
/> )
} else {
return (
<SwipeCards
cards={this.state.cards}
renderCard={(cardData) => <Card {...cardData} />}
handleYup={(card) => this.handleYup(card)}
handleNope={() => this.handleNope()}
/>
)
}
}
}
const styles = StyleSheet.create({
card: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
width: 300,
height: 300,
},
thumbnail: {
flex: 1,
width: 300,
height: 300,
},
})
AppRegistry.registerComponent('FirstApp', () => FirstApp);