-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.ios.js
164 lines (158 loc) · 3.62 KB
/
index.ios.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
* Sample React Native App
* https://github.com./facebook/react-native
*/
'use strict';
var React = require('react-native');
var BarcodeScanner = require('./BarcodeScanner');
var {
AlertIOS,
AppRegistry,
Component,
NavigatorIOS,
StyleSheet,
Text,
TouchableHighlight,
View,
} = React;
var ReactNativeBarcodeScanner = React.createClass({
getInitialState: function() {
return {
value: ''
};
},
render: function() {
return (
<View style={styles.container}>
<TouchableHighlight onPress={this._switchCamera}>
<View>
<BarcodeScanner
ref="scanner"
aspect="Fill"
type="Back"
orientation="Portrait"
onScanned={this._onScannedResult}
style={styles.barcode}
/>
</View>
</TouchableHighlight>
<TouchableHighlight onPress={this._stopScaning}>
<Text>Stop Scaning</Text>
</TouchableHighlight>
<TouchableHighlight onPress={this._startScaning}>
<Text>Start Scaning</Text>
</TouchableHighlight>
</View>
);
},
_switchCamera: function() {
this.refs.scanner.switch();
},
_stopScaning: function() {
this.refs.scanner.stopScanning();
},
_startScaning: function() {
this.refs.scanner.startScanning();
},
_onScannedResult: function(data) {
console.log(data);
if (this.state.value === '') {
this.setState({value: data});
AlertIOS.alert(this.state.value);
}
//AlertIOS.alert(data);
this.props.navigator.pop();
}
});
class Welcome extends Component {
constructor(props) {
super(props);
this.state = {};
}
onLaunchPressed() {
this.props.navigator.push({
title: "Barcode Scanner",
component: ReactNativeBarcodeScanner,
passProps: {}
});
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+Control+Z for dev menu
</Text>
<TouchableHighlight style={styles.button}
onPress={this.onLaunchPressed.bind(this)}
underlayColor='#99d9f4'>
<Text style={styles.buttonText}>Launch Barcode Scanner</Text>
</TouchableHighlight>
</View>
);
}
}
var ReactNativeBarcodeScannerMain = React.createClass({
render: function() {
return (
<NavigatorIOS
style={styles.navigator}
initialRoute={{
title: 'Welcome Barcode Scanner',
component: Welcome,
}}
/>
)
}
});
var styles = StyleSheet.create({
navigator: {
flex: 1
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
barcode:{
justifyContent: 'center',
alignSelf: 'center',
height: 200,
width: 200,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
buttonText: {
fontSize: 18,
color: 'white',
alignSelf: 'center'
},
button: {
height: 36,
// flex: 1,
flexDirection: 'row',
backgroundColor: '#48BBEC',
borderColor: '#48BBEC',
borderWidth: 1,
borderRadius: 8,
marginBottom: 10,
alignSelf: 'stretch',
justifyContent: 'center'
},
});
AppRegistry.registerComponent('ReactNativeBarcodeScanner', () => ReactNativeBarcodeScannerMain);