2015-07-28 14:31:26 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
* @providesModule Modal
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-03-26 17:23:41 +00:00
|
|
|
var Platform = require('Platform');
|
2015-08-13 16:09:10 +00:00
|
|
|
var PropTypes = require('ReactPropTypes');
|
2015-07-28 14:31:26 +00:00
|
|
|
var React = require('React');
|
|
|
|
var StyleSheet = require('StyleSheet');
|
|
|
|
var View = require('View');
|
|
|
|
|
|
|
|
var requireNativeComponent = require('requireNativeComponent');
|
|
|
|
var RCTModalHostView = requireNativeComponent('RCTModalHostView', null);
|
|
|
|
|
2015-09-28 06:46:00 +00:00
|
|
|
/**
|
|
|
|
* A Modal component covers the native view (e.g. UIViewController, Activity)
|
|
|
|
* that contains the React Native root.
|
|
|
|
*
|
|
|
|
* Use Modal in hybrid apps that embed React Native; Modal allows the portion of
|
|
|
|
* your app written in React Native to present content above the enclosing
|
|
|
|
* native view hierarchy.
|
|
|
|
*
|
|
|
|
* In apps written with React Native from the root view down, you should use
|
|
|
|
* Navigator instead of Modal. With a top-level Navigator, you have more control
|
2015-10-21 13:58:28 +00:00
|
|
|
* over how to present the modal scene over the rest of your app by using the
|
|
|
|
* configureScene property.
|
2015-09-28 06:46:00 +00:00
|
|
|
*/
|
2015-07-28 14:31:26 +00:00
|
|
|
class Modal extends React.Component {
|
|
|
|
render(): ?ReactElement {
|
|
|
|
if (this.props.visible === false) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-08-13 16:09:10 +00:00
|
|
|
if (this.props.transparent) {
|
|
|
|
var containerBackgroundColor = {backgroundColor: 'transparent'};
|
|
|
|
}
|
|
|
|
|
2015-07-28 14:31:26 +00:00
|
|
|
return (
|
2015-08-13 16:09:10 +00:00
|
|
|
<RCTModalHostView
|
|
|
|
animated={this.props.animated}
|
|
|
|
transparent={this.props.transparent}
|
2016-03-17 15:51:58 +00:00
|
|
|
onRequestClose={this.props.onRequestClose}
|
2016-03-03 20:42:41 +00:00
|
|
|
onShow={this.props.onShow}
|
2015-08-13 16:09:10 +00:00
|
|
|
style={styles.modal}>
|
|
|
|
<View style={[styles.container, containerBackgroundColor]}>
|
2015-07-28 14:31:26 +00:00
|
|
|
{this.props.children}
|
|
|
|
</View>
|
|
|
|
</RCTModalHostView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-13 16:09:10 +00:00
|
|
|
Modal.propTypes = {
|
|
|
|
animated: PropTypes.bool,
|
|
|
|
transparent: PropTypes.bool,
|
2015-10-31 00:03:23 +00:00
|
|
|
visible: PropTypes.bool,
|
2016-03-26 17:23:41 +00:00
|
|
|
onRequestClose: Platform.OS === 'android' ? PropTypes.func.isRequired : PropTypes.func,
|
2016-03-03 20:42:41 +00:00
|
|
|
onShow: PropTypes.func,
|
2015-08-13 16:09:10 +00:00
|
|
|
};
|
|
|
|
|
2015-10-31 00:03:23 +00:00
|
|
|
Modal.defaultProps = {
|
|
|
|
visible: true,
|
|
|
|
};
|
|
|
|
|
2015-07-28 14:31:26 +00:00
|
|
|
var styles = StyleSheet.create({
|
|
|
|
modal: {
|
|
|
|
position: 'absolute',
|
|
|
|
},
|
|
|
|
container: {
|
|
|
|
position: 'absolute',
|
2016-03-17 15:51:58 +00:00
|
|
|
left: 0,
|
2015-07-28 14:31:26 +00:00
|
|
|
top: 0,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Modal;
|