iosScan.js
2.6 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
/**
* Created by xiniu on 2018/5/11.
*/
import React, { Component } from 'react';
import {
AppRegistry,
Dimensions,
StyleSheet,
Text,
ActivityIndicator,
TouchableHighlight,
View,
Modal,
TouchableOpacity,
Image,
Alert,
Keyboard,
} from 'react-native';
import Camera from 'react-native-camera';
import { width, height, zoomW, zoomH } from '../../utils/getSize';
const zoom = 750 / parseInt(Dimensions.get('window').width);
export default class IOSScan extends Component {
static navigationOptions = ({ navigation, screenProps }) => ({
title: '扫描',
headerLeft: (
<TouchableOpacity style={styles.backWrap} onPress={() => navigation.goBack()}>
<Image source={require('../../img/back_gray.png')} resizeMode="contain" />
</TouchableOpacity>
),
headerRight: (
<View />
),
});
constructor(props) {
super(props);
this.state = {
};
}
componentWillMount() {
Keyboard.dismiss();
}
onBarCodeRead(e) {
this.props.navigation.state.params.callBack(e.data);
this.props.navigation.goBack();
}
render() {
return (
<View style={styles.container}>
<Camera
ref={(cam) => {
this.camera = cam;
}}
captureQuality={Camera.constants.CaptureQuality['720p']}
captureTarget={Camera.constants.CaptureTarget.memory}
onBarCodeRead={this.onBarCodeRead.bind(this)}
style={styles.preview}
aspect={Camera.constants.Aspect.fill}
>
<View>
<View style={{ flexDirection: 'row', marginBottom: 291.5 / zoom }}>
<View style={{ width: 30, height: 30, borderTopWidth: 2, borderColor: '#fff', borderLeftWidth: 2, marginRight: 291.5 / zoom }} />
<View style={{ width: 30, height: 30, borderTopWidth: 2, borderColor: '#fff', borderRightWidth: 2 }} />
</View>
<View style={{ flexDirection: 'row' }}>
<View style={{ width: 30, height: 30, borderBottomWidth: 2, borderColor: '#fff', borderLeftWidth: 2, marginRight: 291.5 / zoom }} />
<View style={{ width: 30, height: 30, borderBottomWidth: 2, borderColor: '#fff', borderRightWidth: 2 }} />
</View>
</View>
</Camera>
</View>
);
}
}
const styles = StyleSheet.create({
backWrap: {
justifyContent: 'center',
paddingLeft: 18.5 / zoomW,
paddingRight: 18.5 / zoomW,
height: 44 / zoomH,
},
container: {
flex: 1,
flexDirection: 'row',
},
preview: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});