react-native-modal 0,1,0 editorconfig flowtype npm

A <Modal /> component for react-native

react-native-modal

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.

Warning: A Modal component is now built into React Native as of v0.10-rc, so this library is no longer necessary. Check out this commit on facebook/react-native for more information!

Demo

Add it to your project

  1. Run npm install react-native-modal --save
  2. Open your project in XCode, right click on Libraries and click Add Files to "Your Project Name" (Screenshot) then choose the RNModal.xcodeproj (Screenshot) .
  3. Add libRNModal.a to Build Phases -> Link Binary With Libraries (Screenshot).
  4. var Modal = require('react-native-modal');
  5. At the bottom of your app, add the <Modal> element and use its isVisible prop to toggle visibility. It needs to be at the bottom so that it appears above all other components when it is visible. If you use the forceToFront prop, then the position in the component tree does not matter at all - put it wherever you like.

Usage

'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);

If you would prefer to not have to implement openModal() and closeModal(), then you can use Modal.Mixin, then you can replace the definition of App above with:

var App = React.createClass({
  mixins: [Modal.Mixin],

  render() {
    return (
      <View style={styles.page}>
        <Text onPress={() => this.openModal()}>
          Open Modal.
        </Text>
        <Modal backdropType="blur" isVisible={this.state.isModalOpen} onClose={() => this.closeModal()}>
          <Text>Hello world!</Text>
        </Modal>
      </View>
    );
  }
}

Also take a look on react-native-login for an example usage.

Props

Component accepts several self-descriptive properties:

  • forceToFront (Bool) - if true, the modal will use a new UIWindow that will appear above NavigatorIOS and the status bar, but not alerts. Demo here.
  • hideCloseButton (Bool)
  • backdropType (String) plain, none, or blur. Default is plain.
  • backdropBlur (String) If backdropType is blur, this can be either dark, light, or extra-light. Default is light. (thanks @kureev for react-native-blur!) Demo here.
  • containerPointerEvents (String) box-none, none, box-only, auto. Default is auto. Set to box-none to trigger the onPressBackdrop callback when the modal body is touched. See pointerEvents.
  • isVisible (Bool)
  • onClose (Function)
  • onPressBackdrop (Function) - callback to be fired when the user taps on the backdrop
  • customCloseButton (React Component)
  • customShowHandler (Function) - uses a react-tween-state wrapper API in order to show the modal. See example
  • customHideHandler (Function) - uses a react-tween-state wrapper API in order to hide the modal. See example

MIT Licensed

Related Repositories

react-native-card-modal

react-native-card-modal

A pure javascript card modal for React Native framework. ...

react-native-modalbox

react-native-modalbox

A <Modal/> component for react-native ...

react-native-modal

react-native-modal

A <Modal /> component for react-native ...

react-native-modal

react-native-modal

An enhanced, animated and customizable react-native modal ...

react-native-country-picker-modal

react-native-country-picker-modal

Country picker provides a modal allowing a user to select a country from a list. It display a flag next to each country name. ...


Top Contributors

brentvatne voronianski rpastorelle MarcoPolo ReadingSteiner booxood lwansbrough auser mbrgm grabbou premasagar almost yorkie pgmemk

Releases

-   0.4.0 zip tar
-   0.3.10 zip tar
-   0.3.8 zip tar
-   0.3.7 zip tar
-   0.3.6 zip tar
-   0.3.5 zip tar
-   0.3.4 zip tar
-   0.3.3 zip tar
-   0.3.2 zip tar
-   0.3.1 zip tar
-   0.3.0 zip tar
-   0.2.15 zip tar
-   0.2.14 zip tar
-   0.2.13 zip tar
-   0.2.12 zip tar
-   0.2.11 zip tar
-   0.2.10 zip tar
-   0.2.9 zip tar
-   0.2.8 zip tar
-   0.2.7 zip tar
-   0.2.6 zip tar
-   0.2.5 zip tar
-   0.2.4 zip tar
-   0.2.3 zip tar
-   0.2.2 zip tar
-   0.2.1 zip tar
-   0.2.0 zip tar
-   0.1.2 zip tar
-   0.1.0 zip tar
-   0.0.9 zip tar