react-native-camera/Camera.ios.js

68 lines
1.8 KiB
JavaScript

var React = require('React');
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,
orientation: PropTypes.string,
},
mixins: [NativeMethodsMixin],
viewConfig: {
uiViewClassName: 'UIView',
validAttributes: ReactIOSViewAttributes.UIView
},
getInitialState: function() {
return {
isAuthorized: false
};
},
componentWillMount: function() {
NativeModules.CameraManager.checkDeviceAuthorizationStatus((function(err, isAuthorized) {
this.state.isAuthorized = isAuthorized;
this.setState(this.state);
}).bind(this));
},
render: function() {
var style = flattenStyle([styles.base, this.props.style]);
var aspect = this.props.aspect || 'Fill';
var orientation = this.props.orientation || 'Portrait';
aspect = NativeModules.CameraManager.aspects[aspect];
orientation = NativeModules.CameraManager.orientations[orientation];
var nativeProps = merge(this.props, {
style,
aspect: aspect,
orientation: orientation,
});
return <RCTCamera {... nativeProps} />
},
});
var RCTCamera = createReactIOSNativeComponentClass({
validAttributes: merge(ReactIOSViewAttributes.UIView, { aspect: true, orientation: true }),
uiViewClassName: 'RCTCamera',
});
var styles = StyleSheet.create({
base: {
overflow: 'hidden'
},
});
module.exports = Camera;