1.3.1 • Published 7 years ago

react-native-modal-overlay v1.3.1

Weekly downloads
1,094
License
MIT
Repository
github
Last release
7 years ago

react-native-modal-overlay alt text

An overlay component built using native Modal which can be invoked from anywhere in the component hierarchy.

https://nodei.co/npm/react-native-modal-overlay.png?downloads=true&downloadRank=true&stars=true

NPM URL- https://www.npmjs.com/package/react-native-modal-overlay

Features

  • Unlike other modal/overlay components, it can be triggered from anywhere in the component hierarchy since it is using react-native Modal.
  • Used react-native components. So no linking is required.
  • Works out of the box for both Android and IOS.
  • Can be customised by passing style props.
  • Supports closeOnTouchOutside.

GIFs

Full GIF

Props

This module accepts the following props:

PropExplanationDefault ValueType
animationTypeAnimation Type for modal/overlay. Can be any of the animations provided by react-native-animatable. Example: fadeInUp zoomIn, bounceIn, flipInX, lightSpeedIn, etc.'fadeIn'string
easingTiming function for the animation provided by react-native-animatable'ease'string
visibleSets modal visibilityfalseBoolean
closeOnTouchOutsideIf modal should close on touching outside the child componentfalseBoolean
onCloseFunction to be called on close.noopFunction
containerStyleStyle for the Overlay container.{}Object
childrenWrapperStyleStyle for children container.{}Object
accessibleWhether internal components should be declared as accessible. Useful for iOS XCUITest.trueBoolean

Installation

npm install react-native-modal-overlay --save or if you are using Yarn, yarn add react-native-modal-overlay

Examples:

Simple usage with default props

import React, { Component} from 'react';
import Overlay from 'react-native-modal-overlay';

export default class OverlayExample extends Component {
  state = {
    modalVisible: true, 
  }
  
  onClose = () => this.setState({ modalVisible: false});
  
  render() {
    return (
        <Overlay visible={this.state.modalVisible} onClose={this.onClose} closeOnTouchOutside>
          <Text>Some Modal Content</Text>
        </Overlay>
    );
  }
}

Complex usage with render props

Use case: For Example you have a cross button inside your modal and you want to close the modal when the button is pressed. This can be done by calling hideModal argument in the render props instead of calling onClose. Refer to the example below:

import React, { Component, Fragment} from 'react';
import Overlay from 'react-native-modal-overlay';

export default class OverlayExample extends Component {
  state = {
    modalVisible: true, 
  }
  
  onClose = () => this.setState({ modalVisible: false});
  
  render() {
    return (
      <Overlay visible={this.state.modalVisible} onClose={this.onClose} closeOnTouchOutside
        animationType="zoomIn" containerStyle={{backgroundColor: 'rgba(37, 8, 10, 0.78)'}}
        childrenWrapperStyle={{backgroundColor: '#eee'}}
        animationDuration={500}>
        {
          (hideModal, overlayState) => (
            <Fragment>
              <Text>Some Modal Content</Text>
              <Text onPress={hideModal}>Close</Text>
            </Fragment>
          )
        }
      </Overlay>
    );
  }
}

Note that the whole hideModal and internal state of the component is being passed as arguments to the render prop.

Example Project URL: https://github.com/rgabs/react-native-modal-overlay-example

Don’t forget to hit star if you like my work :)

1.3.1

7 years ago

1.3.0

7 years ago

1.2.3

7 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago