MCPcopy
hub / github.com/react-native-modal/react-native-modal

github.com/react-native-modal/react-native-modal @v13.0.1 sqlite

repository ↗ · DeepWiki ↗ · release v13.0.1 ↗
75 symbols 142 edges 31 files 1 documented · 1%
README

Announcements

  • 📣 We're looking for maintainers and contributors! See #598
  • 💡 We're brainstorming if/how we can make a JavaScript-only version of react-native-modal. See #597
  • 🙏 If you have a question, please start a new discussion instead of opening a new issue.

react-native-modal

npm version styled with prettier

If you're new to the React Native world, please notice that React Native itself offers a component that works out-of-the-box.

An enhanced, animated, customizable React Native modal.

The goal of react-native-modal is expanding the original React Native <Modal> component by adding animations, style customization options, and new features, while still providing a simple API.

Features

  • Smooth enter/exit animations
  • Plain simple and flexible APIs
  • Customizable backdrop opacity, color and timing
  • Listeners for the modal animations ending
  • Resize itself correctly on device rotation
  • Swipeable
  • Scrollable

Setup

This library is available on npm, install it with: npm i react-native-modal or yarn add react-native-modal.

Usage

Since react-native-modal is an extension of the original React Native modal, it works in a similar fashion.

  1. Import react-native-modal:
import Modal from "react-native-modal";
  1. Create a <Modal> component and nest its content inside of it:
function WrapperComponent() {
  return (
    <View>
      <Modal>
        <View style={{ flex: 1 }}>
          <Text>I am the modal content!</Text>
        </View>
      </Modal>
    </View>
  );
}
  1. Then, show the modal by setting the isVisible prop to true:
function WrapperComponent() {
  return (
    <View>
      <Modal isVisible={true}>
        <View style={{ flex: 1 }}>
          <Text>I am the modal content!</Text>
        </View>
      </Modal>
    </View>
  );
}

The isVisible prop is the only prop you'll really need to make the modal work: you should control this prop value by saving it in your wrapper component state and setting it to true or false when needed.

A complete example

The following example consists in a component (ModalTester) with a button and a modal. The modal is controlled by the isModalVisible state variable and it is initially hidden, since its value is false.
Pressing the button sets isModalVisible to true, making the modal visible.
Inside the modal there is another button that, when pressed, sets isModalVisible to false, hiding the modal.

import React, { useState } from "react";
import { Button, Text, View } from "react-native";
import Modal from "react-native-modal";

function ModalTester() {
  const [isModalVisible, setModalVisible] = useState(false);

  const toggleModal = () => {
    setModalVisible(!isModalVisible);
  };

  return (
    <View style={{ flex: 1 }}>
      <Button title="Show modal" onPress={toggleModal} />

      <Modal isVisible={isModalVisible}>
        <View style={{ flex: 1 }}>
          <Text>Hello!</Text>

          <Button title="Hide modal" onPress={toggleModal} />
        </View>
      </Modal>
    </View>
  );
}

export default ModalTester;

For a more complex example take a look at the /example directory.

Available props

Name Type Default Description
animationIn string or object "slideInUp" Modal show animation
animationInTiming number 300 Timing for the modal show animation (in ms)
animationOut string or object "slideOutDown" Modal hide animation
animationOutTiming number 300 Timing for the modal hide animation (in ms)
avoidKeyboard bool false Move the modal up if the keyboard is open
coverScreen bool true Will use RN Modal component to cover the entire screen wherever the modal is mounted in the component hierarchy
hasBackdrop bool true Render the backdrop
backdropColor string "black" The backdrop background color
backdropOpacity number 0.70 The backdrop opacity when the modal is visible
backdropTransitionInTiming number 300 The backdrop show timing (in ms)
backdropTransitionOutTiming number 300 The backdrop hide timing (in ms)
customBackdrop node null The custom backdrop element
children node REQUIRED The modal content
deviceHeight number null Device height (useful on devices that can hide the navigation bar)
deviceWidth number null Device width (useful on devices that can hide the navigation bar)
isVisible bool REQUIRED Show the modal?
onBackButtonPress func () => null Called when the Android back button is pressed
onBackdropPress func () => null Called when the backdrop is pressed
onModalWillHide func () => null Called before the modal hide animation begins
onModalHide func () => null Called when the modal is completely hidden
onModalWillShow func () => null Called before the modal show animation begins
onModalShow func () => null Called when the modal is completely visible
onSwipeStart func () => null Called when the swipe action started
onSwipeMove func (percentageShown) => null Called on each swipe event
onSwipeComplete func ({ swipingDirection }) => null Called when the swipeThreshold has been reached
onSwipeCancel func () => null Called when the swipeThreshold has not been reached
panResponderThreshold number 4 The threshold for when the panResponder should pick up swipe events
scrollOffset number 0 When > 0, disables swipe-to-close, in order to implement scrollable content
scrollOffsetMax number 0 Used to implement overscroll feel when content is scrollable. See /example directory
scrollTo func null Used to implement scrollable modal. See /example directory for reference on how to use it
scrollHorizontal bool false Set to true if your scrollView is horizontal (for a correct scroll handling)
swipeThreshold number 100 Swiping threshold that when reached calls onSwipeComplete
swipeDirection string or array null Defines the direction where the modal can be swiped. Can be 'up', 'down', 'left, or 'right', or a combination of them like ['up','down']
useNativeDriver bool false Defines if animations should use native driver
useNativeDriverForBackdrop bool null Defines if animations for backdrop should use native driver (to avoid flashing on android)
hideModalContentWhileAnimating bool false Enhances the performance by hiding the modal content until the animations complete
propagateSwipe bool or func false Allows swipe events to propagate to children components (eg a ScrollView inside a modal)
style any null Style applied to the modal

Frequently Asked Questions

The component is not working as expected

Under the hood react-native-modal uses react-native original Modal component.
Before reporting a bug, try swapping react-native-modal with react-native original Modal component and, if the issue persists, check if it has already been reported as a react-native issue.

The backdrop is not completely filled/covered on some Android devices (Galaxy, for one)

React-Native has a few issues detecting the correct device width/height of some devices.
If you're experiencing this issue, you'll need to install [`react-nat

Extension points exported contracts — how you extend this code

GestureResponderEvent (Interface)
(no doc)
src/types.ts

Core symbols most depended-on inside this repo

makeScene
called by 12
example/src/Navigator.tsx
makeSlideTranslation
called by 8
src/utils.ts
buildAnimations
called by 2
src/utils.ts
reversePercentage
called by 2
src/utils.ts
makeAnimation
called by 2
src/utils.ts
isObject
called by 2
src/utils.ts
extractAnimationFromProps
called by 2
src/modal.tsx
getMainComponentName
called by 1
example/android/app/src/main/java/com/modalexample/MainActivity.java

Shape

Class 32
Method 29
Function 13
Interface 1

Languages

TypeScript84%
Java16%

Modules by API surface

src/modal.tsx9 symbols
src/utils.ts6 symbols
example/android/app/src/main/java/com/modalexample/MainApplication.java6 symbols
example/src/utils/ModalBaseScene.tsx4 symbols
example/src/modals/ScrollableModal.tsx4 symbols
example/android/app/src/main/java/com/modalexample/MainActivity.java4 symbols
example/src/pages/HomePage.tsx3 symbols
example/src/modals/WithoutCoverScreenModal.tsx3 symbols
example/src/modals/WithoutBackdropModal.tsx3 symbols
example/src/modals/SwipeableModal.tsx3 symbols
example/src/modals/SlowModal.tsx3 symbols
example/src/modals/SlideModal.tsx3 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

@babel/core7.5.5 · 1×
@babel/runtime7.6.3 · 1×
@react-native-community/eslint-config0.0.5 · 1×
@semantic-release/git9.0.0 · 1×
@types/react16.9.9 · 1×
@types/react-native0.60.21 · 1×
@typescript-eslint/eslint-plugin2.4.0 · 1×
@typescript-eslint/parser2.4.0 · 1×
babel6.23.0 · 1×
babel-core7.0.0-bridge.0 · 1×
babel-jest24.9.0 · 1×
babel-plugin-module-resolver3.1.3 · 1×

For agents

$ claude mcp add react-native-modal \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact