Last active
January 13, 2016 10:19
-
-
Save wvengen/4ce9537bbc271981afc5 to your computer and use it in GitHub Desktop.
Basic Modal for react-native on Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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