react-native-dialog-component
Version:
React Native Dialog Component for IOS & Android.
1 lines • 4.66 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:true});var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _jsxFileName='src/DialogComponent.js';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _react=require('react');var _react2=_interopRequireDefault(_react);var _reactNative=require('react-native');var _reactNativePopupDialog=require('react-native-popup-dialog');var _reactNativePopupDialog2=_interopRequireDefault(_reactNativePopupDialog);var _DialogTitle=require('./components/DialogTitle');var _DialogTitle2=_interopRequireDefault(_DialogTitle);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}var _Dimensions$get=_reactNative.Dimensions.get('window'),screenWidth=_Dimensions$get.width;var ANIMATION_DURATION=200;var DEFAULT_WIDTH=screenWidth;var DEFAULT_HEIGHT=null;var styles=_reactNative.StyleSheet.create({dialog:{elevation:5,minHeight:96,borderRadius:0,shadowColor:'black',shadowOpacity:0.2,shadowRadius:5,shadowOffset:{width:1,height:2}},dialogContainer:{flex:1}});var DialogComponent=function(_Component){_inherits(DialogComponent,_Component);function DialogComponent(props){_classCallCheck(this,DialogComponent);var _this=_possibleConstructorReturn(this,(DialogComponent.__proto__||Object.getPrototypeOf(DialogComponent)).call(this,props));_this.show=_this.show.bind(_this);_this.dismiss=_this.dismiss.bind(_this);return _this;}_createClass(DialogComponent,[{key:'show',value:function show(onShown){this.popupDialog.show(onShown);}},{key:'dismiss',value:function dismiss(onDismissed){this.popupDialog.dismiss(onDismissed);}},{key:'render',value:function render(){var _this2=this;var _props=this.props,title=_props.title,children=_props.children;if(title&&typeof title==='string'){title=_react2.default.createElement(_DialogTitle2.default,_extends({},this.props,{__source:{fileName:_jsxFileName,lineNumber:63}}));}if(title&&title.type&&title.type.name==='DialogTitle'&&!title.props.haveTitleBar){if(children&&children.type&&children.type.name==='DialogContent'){var props=_extends({},children.props,{contentStyle:[{paddingTop:0},children.props.contentStyle]});var content=children.props.children;children=_react2.default.cloneElement(children,props,content);}}return _react2.default.createElement(_reactNativePopupDialog2.default,{ref:function ref(popupDialog){_this2.popupDialog=popupDialog;},width:this.props.width,height:this.props.height,dialogAnimation:this.props.dialogAnimation,dialogStyle:[styles.dialog,this.props.dialogStyle],animationDuration:this.props.animationDuration,overlayPointerEvents:this.props.overlayPointerEvents,overlayBackgroundColor:this.props.overlayBackgroundColor,overlayOpacity:this.props.overlayOpacity,dismissOnHardwareBackPress:this.props.dismissOnHardwareBackPress,dismissOnTouchOutside:this.props.dismissOnTouchOutside,haveOverlay:this.props.haveOverlay,show:this.props.show,onShown:this.props.onShown,onDismissed:this.props.onDismissed,actions:this.props.actions,__source:{fileName:_jsxFileName,lineNumber:85}},title,children);}}]);return DialogComponent;}(_react.Component);DialogComponent.defaultProps={animationDuration:ANIMATION_DURATION,width:DEFAULT_WIDTH,height:DEFAULT_HEIGHT};exports.default=DialogComponent;