-
Notifications
You must be signed in to change notification settings - Fork 2
/
QRCodeScanner.js
70 lines (58 loc) · 1.18 KB
/
QRCodeScanner.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
'use strict';
import React{
View,
Text,
Component
} from 'react-native';
import Camera from 'react-native-camera';
const SCREEN_HEIGHT = Dimensions.get('window').height;
const SCREEN_WIDTH = Dimensions.get('window').width;
class QRcodeScanner extends Component({
constructor(props) {
super(props);
this.readed = false
this.state = {
torchMode:0
};
}
render(){
return (
<View style={{ flex:1 }}>
<Camera style={{ height:Layout.SCREEN_HEIGHT - 20, width:Layout.SCREEN_WIDTH }}
torchMode = { this.state.torchMode }
onBarCodeRead = { this.barcodeHandler.bind(this) }
/>
<View onTouchEnd = {
() => {
if( this.state.torchMode == 0 ){
this.trunOnTorch.bind(this)
} else {
this.turnOffTorch()
}
}
}>
<Text>{ () => {
return this.state.torchMode == 0 ? 'on' : 'off' }
}Hello</Text>
</View>
</View>
)
}
barcodeHandler( str ){
if( !this.readed ){
console.log( JSON.stringify( str ) );
this.readed = true;
}
}
trunOnTorch(){
this.setState({
torchMode:1
})
}
turnOffTorch(){
this.setState({
torchMode:0
})
}
})
module.exports = QRcodeScanner;