forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQRCode.js
More file actions
184 lines (165 loc) · 3.5 KB
/
QRCode.js
File metadata and controls
184 lines (165 loc) · 3.5 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import React, {
StyleSheet,
View,
Text,
Component,
Dimensions,
Platform,
TouchableOpacity,
Vibration
} from 'react-native';
import Camera from 'react-native-camera';
import BarcodeScanner from 'react-native-barcodescanner';
import Icon from 'react-native-vector-icons/Ionicons';
import OverlayButton from '../components/base/OverlayButton';
const {height, width} = Dimensions.get('window');
const cameraSize = 250;
const borderColor = 'rgba(255,255,255,0.6)';
const borderBoxSize = 35;
class QRCode extends Component {
constructor(props) {
super(props);
this.succesed = false;
}
_onBarCodeRead(result) {
const {router, actions} = this.props;
if (this.succesed) return;
this.succesed = true;
Vibration.vibrate();
actions.checkToken(result.data, ()=> {
router.pop();
actions.toast('登陆成功');
});
router.pop();
}
_onClosePress() {
this.props.router.pop()
}
render() {
const closeIcon = (
<OverlayButton
position={{ right: 60, top: 60 }}
onPress={this._onClosePress.bind(this)}>
<View style={styles.iconWrapper}>
<Icon
name='ios-close-empty'
size={35}
color='rgba(255,255,255,0.7)'
style={styles.closeIcon}/>
</View>
</OverlayButton>
);
// for android
if (Platform.OS === 'android') {
return (
<View style={styles.cameraWrapper}>
<BarcodeScanner
onBarCodeRead={this._onBarCodeRead.bind(this)}
style={styles.camera}/>
{ closeIcon }
</View>
)
}
// for ios
return (
<Camera
ref='camera'
style={styles.camera}
aspect={Camera.constants.Aspect.Fill}
onBarCodeRead={this._onBarCodeRead.bind(this)}>
<View style={styles.container}>
<View style={styles.cameraView}>
<View key="1" style={[styles.borderLeftTop,styles.borderBox]}/>
<View key="2" style={[styles.borderRightTop,styles.borderBox]}/>
<View key="3" style={[styles.borderLeftBottom,styles.borderBox]}/>
<View key="4" style={[styles.borderRightBottom,styles.borderBox]}/>
</View>
<Text style={styles.infoText}>
请将二维码放到框内
</Text>
</View>
{ closeIcon }
</Camera>
)
}
}
const styles = StyleSheet.create({
cameraWrapper: {
width,
height
},
camera: {
width: width,
height: height,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center'
},
cameraView: {
height: cameraSize,
width: cameraSize,
},
container: {
height: 350
},
borderBox: {
position: 'absolute',
borderWidth: 2,
height: borderBoxSize,
width: borderBoxSize
},
borderLeftTop: {
borderColor: 'transparent',
borderLeftColor: borderColor,
borderTopColor: borderColor,
left: 0,
top: 0
},
borderRightTop: {
borderColor: 'transparent',
borderRightColor: borderColor,
borderTopColor: borderColor,
right: 0,
top: 0
},
borderLeftBottom: {
borderColor: 'transparent',
borderLeftColor: borderColor,
borderBottomColor: borderColor,
left: 0,
bottom: 0
},
borderRightBottom: {
borderColor: 'transparent',
borderRightColor: borderColor,
borderBottomColor: borderColor,
right: 0,
bottom: 0
},
infoText: {
color: 'rgba(255,255,255,0.7)',
textAlign: 'center',
marginTop: 40,
fontSize: 24
},
iconWrapper: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
height: 45,
width: 45
},
closeIcon: {
flex: 1,
textAlign: 'center'
},
buttonWrapper: {
width: 35,
height: 35,
position: 'absolute',
right: 30,
top: 0
}
});
export const LayoutComponent = QRCode;