1 |
|
2 |
|
3 | import React from 'react';
|
4 | import Camera from './Camera';
|
5 |
|
6 | type Data = {
|
7 | data: string,
|
8 | type: string,
|
9 | };
|
10 |
|
11 | type Props = {
|
12 | torchMode?: string | number,
|
13 | type?: string | number,
|
14 | onBarCodeRead: Data => void,
|
15 | barCodeTypes: string[],
|
16 | };
|
17 |
|
18 | export default class BarCodeScanner extends React.Component<Props> {
|
19 | static Constants = {
|
20 | ...Camera.Constants,
|
21 | TorchMode: {
|
22 | on: Camera.Constants.FlashMode.torch,
|
23 | off: Camera.Constants.FlashMode.off,
|
24 | },
|
25 | };
|
26 |
|
27 | render() {
|
28 | const props = { ...this.props };
|
29 | if (props.torchMode !== undefined) {
|
30 | if (typeof props.torchMode === 'string') {
|
31 | props.flashMode = BarCodeScanner.Constants.TorchMode[props.torchMode];
|
32 | } else {
|
33 | props.flashMode = props.torchMode;
|
34 | }
|
35 | delete props.torchMode;
|
36 | }
|
37 | return <Camera {...props} />;
|
38 | }
|
39 | }
|
40 |
|
41 | export const Constants = BarCodeScanner.Constants;
|
42 |
|
\ | No newline at end of file |