A <Modal>
component for react-native. This is still very much a work
in progress and only handles the simplest of cases, ideas and
contributions are very welcome.
- Run
npm install react-native-modal --save
var Modal = require('react-native-modal');
- At the bottom of your app, add the
<Modal>
element and use itsisVisible
prop to toggle visibility. It needs to be at the bottom so that it appears above all other components when it is visible. - Do not forget to include
RCTAnimation
library fromnode_modules/react-native/Libraries/Animation
into your XCodeLibraries
folder (more on linking libraries)
'use strict';
var React = require('react-native');
var Modal = require('react-native-modal');
var { AppRegistry, StyleSheet, View, Text } = React;
class App extends React.Component {
constructor() {
this.state = {
isModalOpen: false
};
}
openModal() {
this.setState({isModalOpen: true});
}
closeModal() {
this.setState({isModalOpen: false});
}
render() {
return (
<View style={styles.page}>
<Text onPress={() => this.openModal()}>
Open Modal.
</Text>
<Modal isVisible={this.state.isModalOpen} onClose={() => this.closeModal()}>
<Text>Hello world!</Text>
</Modal>
</View>
);
}
}
var styles = StyleSheet.create({
page: {
flex: 1,
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
top: 0
}
});
AppRegistry.registerComponent('App', () => App);
Also take a look on react-native-login for an example usage.
Component accepts several self-descriptive properties:
hideCloseButton
(Bool)isVisible
(Bool)onClose
(Function)customCloseButton
(React Component)customShowHandler
(Function) - use React's Animation API in order to show the modal.
MIT Licensed