React Native Swipeable Modal
react-native-swipeable-modal is a JavaScript library for react-native allowing you to display modals which can be swiped away in any direction
It uses the great react-native-gesture-handler
to handle the pan events. This module needs to be installed within your application for react-native-swipeable-modal
to work.
For details please check React Native Gesture Handler.
Installation
React Native Swipeable Modal is available as react-native-swipeable-modal
package on npm
With npm
$ npm install react-native-swipeable-modal --save
If using yarn
$ yarn add react-native-swipeable-modal
Examples
react-native-swipeable-modal
exports a SwipeableModal
component which displays its children in a fullscreen mode and can then be swiped away.
You can use SwipeableModal
in any direction:
Use as a simple modal
import React Component from 'react';import Text View Button from 'react-native';import SwipeableModal from 'react-native-swipeable-modal'; state = showModal: false ; this; { return <View => <View => <Button ="Show Modal" = /> </View> thisstateshowModal && <SwipeableModal = = > <Button ="Close" = /> </SwipeableModal> </View> ; }
React Native Navigation v2 showModal
Or with registerScreen.js
import Navigation from 'react-native-navigation';import gestureHandlerRootHOC from 'react-native-gesture-handler';import ContainerScreen from './ContainerScreen';import ModalScreen from './ModalScreen'; Navigation;Navigation;
ContainerScreen.js
import React Component from 'react';import Text View Button from 'react-native';import Navigation from 'react-native-navigation'; { Navigation; }; { return <View => <Button ="Show Modal" = /> </View> ; }
ModalScreen.js
import React Component from 'react';import Text Button from 'react-native';import Navigation from 'react-native-navigation';import SwipeableModal from 'react-native-swipeable-modal'; { Navigation ); }; { return <SwipeableModal = = > <Button ="Close" = /> </SwipeableModal> ; }
API
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
direction | string | ✘ | "bottom" | One of "bottom" , "top" , "left" , "right" |
closeModal | Function | ✓ | - | The function to call when the modal has been swiped away beyond it's limit |
style | Object | ✘ | - | A style to overload the default style of the modal container. Note that you cannot overload the translate properties |
panClose | number | ✘ | 0.6 | A number between 0 and 1 used to select the breakpoint at which closeModal will be called |
minOffset | number | ✘ | 20 | See react-native-gesture-handler minOffset |
maxOffset | number | ✘ | 80 | See react-native-gesture-handler maxOffset |