This repository has been archived by the owner on May 15, 2019. It is now read-only.
forked from react-native-camera/react-native-camera
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.android.js
112 lines (104 loc) · 2.86 KB
/
index.android.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
var React = require('react-native');
var { requireNativeComponent, PropTypes, NativeModules, View } = React;
var ReactNativeCameraModule = NativeModules.ReactCameraModule;
var ReactCameraView = requireNativeComponent('ReactCameraView', {
name: 'ReactCameraView',
propTypes: {
...View.propTypes,
scaleX: PropTypes.number,
scaleY: PropTypes.number,
translateX: PropTypes.number,
translateY: PropTypes.number,
rotation: PropTypes.number,
type: PropTypes.oneOf(['back', 'front'])
}
});
var constants = {
'Aspect': {
'stretch': 'stretch',
'fit': 'fit',
'fill': 'fill'
},
'BarCodeType': {
'upca': 'upca',
'upce': 'upce',
'ean8': 'ean8',
'ean13': 'ean13',
'code39': 'code39',
'code93': 'code93',
'codabar': 'codabar',
'itf': 'itf',
'rss14': 'rss14',
'rssexpanded': 'rssexpanded',
'qr': 'qr',
'datamatrix': 'datamatrix',
'aztec': 'aztec',
'pdf417': 'pdf417'
},
'Type': {
'front': 'front',
'back': 'back'
},
'CaptureMode': {
'still': 'still',
'video': 'video'
},
'CaptureTarget': {
'memory': 'base64',
'disk': 'disk',
'temp': 'temp',
'cameraRoll': 'gallery'
},
'Orientation': {
'auto': 'auto',
'landscapeLeft': 'landscapeLeft',
'landscapeRight': 'landscapeRight',
'portrait': 'portrait',
'portraitUpsideDown': 'portraitUpsideDown'
},
'FlashMode': {
'off': 'off',
'on': 'on',
'auto': 'auto'
},
'TorchMode': {
'off': 'off',
'on': 'on',
'auto': 'auto'
}
};
var ReactCameraViewWrapper = React.createClass({
getDefaultProps() {
return ({
type: constants.Type.back,
captureTarget: constants.CaptureTarget.temp
});
},
render () {
return (
<ReactCameraView {...this.props}></ReactCameraView>
);
},
capture (options, callback) {
var component = this;
var defaultOptions = {
type: component.props.type,
target: component.props.captureTarget,
sampleSize: 0,
title: '',
description: ''
};
return new Promise(function(resolve, reject) {
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
ReactNativeCameraModule.capture(Object.assign(defaultOptions, options || {}), function(err, data) {
if (typeof callback === 'function') callback(err, data);
err ? reject(err) : resolve(data);
});
});
}
});
ReactCameraViewWrapper.constants = constants;
module.exports = ReactCameraViewWrapper;