Skip to content

Instantly share code, notes, and snippets.

@wvengen wvengen/Modal.android.js
Last active Jan 13, 2016

Embed
What would you like to do?
Basic Modal for react-native on Android
// Basic Android-implementation of Modal
//
// based on https://github.com/niftylettuce/react-native-loading-spinner-overlay
import React, {StyleSheet, View} from 'react-native';
const Portal = require('react-native/Libraries/Portal/Portal.js');
export default React.createClass({
propTypes: {
animated: React.PropTypes.bool, // @todo support this
onDismiss: React.PropTypes.func,
transparent: React.PropTypes.bool, // @todo support this
visible: React.PropTypes.bool
},
componentWillMount: function() {
this.tag = Portal.allocateTag();
},
componentWillUnmount: function() {
this.tag = null;
},
componentDidUpdate: function(prevProps) {
if (!prevProps.visible && this.props.visible) {
return Portal.showModal(this.tag, this.render());
} else {
Portal.closeModal(this.tag);
if (this.props.onDismiss) {
this.props.onDismiss();
}
}
},
render: function() {
return (
this.props.visible ?
<View style={styles.container}>
{this.props.children}
</View>
:
null
);
}
});
const styles = StyleSheet.create({
container: {
backgroundColor: 'transparent',
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0
}
});
import {Modal} from 'react-native';
export default Modal;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.