This repository was archived by the owner on Mar 21, 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 0
Expand file tree
/
Copy pathCamera.ios.js
More file actions
92 lines (76 loc) · 2.52 KB
/
Camera.ios.js
File metadata and controls
92 lines (76 loc) · 2.52 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
var React = require('React');
var DeviceEventEmitter = require('RCTDeviceEventEmitter');
var NativeModules = require('NativeModules');
var ReactIOSViewAttributes = require('ReactIOSViewAttributes');
var StyleSheet = require('StyleSheet');
var createReactIOSNativeComponentClass = require('createReactIOSNativeComponentClass');
var PropTypes = require('ReactPropTypes');
var StyleSheetPropType = require('StyleSheetPropType');
var NativeMethodsMixin = require('NativeMethodsMixin');
var flattenStyle = require('flattenStyle');
var merge = require('merge');
var Camera = React.createClass({
propTypes: {
aspect: PropTypes.string,
type: PropTypes.string,
orientation: PropTypes.string,
},
mixins: [NativeMethodsMixin],
viewConfig: {
uiViewClassName: 'UIView',
validAttributes: ReactIOSViewAttributes.UIView
},
getInitialState: function() {
return {
isAuthorized: false,
aspect: this.props.aspect || 'Fill',
type: this.props.type || 'Back',
orientation: this.props.orientation || 'Portrait'
};
},
componentWillMount: function() {
NativeModules.CameraManager.checkDeviceAuthorizationStatus((function(err, isAuthorized) {
this.state.isAuthorized = isAuthorized;
this.setState(this.state);
}).bind(this));
this.cameraBarCodeReadListener = DeviceEventEmitter.addListener('CameraBarCodeRead', this._onBarCodeRead);
},
componentWillUnmount: function() {
this.cameraBarCodeReadListener.remove();
},
render: function() {
var style = flattenStyle([styles.base, this.props.style]);
aspect = NativeModules.CameraManager.aspects[this.state.aspect];
type = NativeModules.CameraManager.cameras[this.state.type];
orientation = NativeModules.CameraManager.orientations[this.state.orientation];
var nativeProps = merge(this.props, {
style,
aspect: aspect,
type: type,
orientation: orientation
});
return <RCTCamera {... nativeProps} />
},
_onBarCodeRead(e) {
this.props.onBarCodeRead && this.props.onBarCodeRead(e);
},
switch: function() {
this.state.type = this.state.type == 'Back' ? 'Front' : 'Back';
this.setState(this.state);
},
takePicture: function(cb) {
NativeModules.CameraManager.takePicture(cb);
}
});
var RCTCamera = createReactIOSNativeComponentClass({
validAttributes: merge(ReactIOSViewAttributes.UIView, {
aspect: true,
type: true,
orientation: true
}),
uiViewClassName: 'RCTCamera',
});
var styles = StyleSheet.create({
base: { },
});
module.exports = Camera;