百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-native-modals

> 前端框架
开源

React Native 模态库。可滑动。高度可定制。支持多个模态和支持自定义动画。适用于 iOS 和 Android。

2.2K stars0 点赞2 次浏览
访问官网GitHub

工具介绍

React Native 模态库。可滑动。高度可定制。支持多个模态和支持自定义动画。适用于 iOS 和 Android。

React Native Modals

React Native Modals Library for iOS & Android.

How to thank me ?

Just click on ⭐️ button

Try it with Exponent



     

BREAKING CHANGE

A lot of backward incompatible changes in v0.22.0. Please, Read the Docs before upgrading to v0.22.0

Installation

bash
npm install --save react-native-modals
# OR
yarn add react-native-modals

Exposed Modules

  • Modal
  • ButtomModal
  • ModalPortal
  • Backdrop
  • ModalButton
  • ModalContent
  • ModalTitle
  • ModalFooter
  • Animation
  • FadeAnimation
  • ScaleAnimation
  • SlideAnimation
  • DragEvent,
  • SwipeDirection,
  • ModalProps
  • ModalFooterProps
  • ModalButtonProps
  • ModalTitleProps
  • ModalContentProps
  • BackdropProps

Examples

Example

Setup - this is essential step

The Component can not be used until ModalPortal is mounted. You should register in your app root. For example:

javascript
import { ModalPortal } from 'react-native-modals';
import { Provider } from 'react-redux';

const Root = () => {
  return (
    <Provider store={store}>
      <App />
      <ModalPortal />
    </Provider>
  );
}

Basic Usage

javascript
import { Modal, ModalContent } from 'react-native-modals';
import { Button } from 'react-native'

<View style={styles.container}>
  <Button
    title="Show Modal"
    onPress={() => {
      this.setState({ visible: true });
    }}
  />
  <Modal
    visible={this.state.visible}
    onTouchOutside={() => {
      this.setState({ visible: false });
    }}
  >
    <ModalContent>
      {...}
    </ModalContent>
  </Modal>
</View>

Usage - Imperative APIs

show

javascript
import { ModalPortal } from 'react-native-modals';

const id = ModalPortal.show((
  <View>
    {...}
  </View>
));

update

javascript
ModalPortal.update(id, {
  children: (
    <View>
      <Text>Updated</Text>
    </View>
  ),
});

dismiss

javascript
ModalPortal.dismiss(id);

dismissAll

javascript
ModalPortal.dismissAll(id);

Usage - Animation

javascript
import { Modal, SlideAnimation, ModalContent } from 'react-native-modals';

<View style={styles.container}>
  <Modal
    visible={this.state.visible}
    modalAnimation={new SlideAnimation({
      slideFrom: 'bottom',
    })}
  >
    <ModalContent>
      {...}
    </ModalContent>
  </Modal>
</View>

Usage - Swipe

javascript
import { Modal, ModalContent } from 'react-native-modals';
import { Button } from 'react-native'

<View style={styles.container}>
  <Modal
    visible={this.state.visible}
    swipeDirection={['up', 'down']} // can be string or an array
    swipeThreshold={200} // default 100
    onSwipeOut={(event) => {
      this.setState({ visible: false });
    }}
  >
    <ModalContent>
      {...}
    </ModalContent>
  </Modal>
</View>

Usage - Modal Title

javascript
import { Modal, ModalTitle, ModalContent } from 'react-native-modals';

<View style={styles.container}>
  <Modal
    visible={this.state.visible}
    modalTitle={<ModalTitle title="Modal Title" />}
  >
    <ModalContent>
      {...}
    </ModalContent>
  </Modal>
</View>

Usage - Modal Action

javascript
import { Modal, ModalFooter, ModalButton, ModalContent } from 'react-native-modals';

<View style={styles.container}>
  <Modal
    visible={this.state.visible}
    footer={
      <ModalFooter>
        <ModalButton
          text="CANCEL"
          onPress={() => {}}
        />
        <ModalButton
          text="OK"
          onPress={() => {}}
        />
      </ModalFooter>
    }
  >
    <ModalContent>
      {...}
    </ModalContent>
  </Modal>
</View>

Props

Modal

Prop Type Default Note
visible boolean false
rounded boolean true
useNativeDriver boolean true
children any
modalTitle? React Element You can pass a modalTitle component or pass a View for customizing titlebar
width? Number Your device width The Width of modal, you can use fixed width or use percentage. For example 0.5 it means 50%
height? Number 300 The Height of modal, you can use fixed height or use percentage. For example 0.5 it means 50%
modalAnimation? FadeAnimation animation for modal
modalStyle? any
containerStyle? any null For example: { zIndex: 10, elevation: 10 }
animationDuration? Number 200
overlayPointerEvents? String Available option: auto, none
overlayBackgroundColor? String #000
overlayOpacity? Number 0.5
hasOverlay? Boolean true
onShow? Function You can pass shown function as a callback function, will call the function when modal shown
onDismiss? Function You can pass onDismiss function as a callback function, will call the function when modal dismissed
onTouchOutside? Function () => {}
onHardwareBackPress? Function () => true Handle hardware button presses
onMove? Function () => {}
onSwiping? Function () => {}
onSwipeRelease? Function () => {}
onSwipingOut? Function () => {}
onSwipeOut? Function
swipeDirection? string or Array<string> [] Available option: up, down, left, right
swipeThreshold? number 100
footer? React Element null for example: <View><Button text="DISMISS" align="center" onPress={() => {}}/></View>

ModalTitle

Prop Type Default Note
title String
style? any null
textStyle? any null
align? String center Available option: left, center, right
hasTitleBar? Bool true

ModalContent

Prop Type Default Note
children any
style? any null

ModalFooter

Prop Type Default Note
children ModalButton
bordered? Boolean true
style? any null

ModalButton

Prop Type Default Note
text String
onPress Function
align? String center Available option: left, center, right
style? any null
textStyle? any null
activeOpacity? Number 0.6
disabled? Boolean false
bordered? Boolean false

Backdrop

Prop Type Default Note
visible Boolean
opacity Number 0.5
onPress? Function
backgroundColor? string #000
animationDuration? Number 200
pointerEvents? String null Available option: auto, none
useNativeDriver? Boolean true

Animation

Params for (*)Animation

FadeAnimation

Preview:
Example:
javascript
new FadeAnimation({
  initialValue: 0, // optional
  animationDuration: 150, // optional
  useNativeDriver: true, // optional
})
Param Type Default Note
initialValue Number 0
animationDuration? Number 150
useNativeDriver? Boolean true

ScaleAnimation

Preview:
Example:
javascript
new ScaleAnimation({
  initialValue: 0, // optional
  useNativeDriver: true, // optional
})
Param Type Default Note
initialValue Number 0
useNativeDriver Boolean true

SlideAnimation

Preview:
Example:
javascript
new SlideAnimation({
  initialValue: 0, // optional
  slideFrom: 'bottom', // optional
  useNativeDriver: true, // optional
})
Param Type Default Note
initialValue Number 0
slideFrom String bottom Available option: top, bottom, left, right
useNativeDriver Boolean true

Create your custom animation

Example:
…

Development

yarn

yarn run build

yarn test

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptcomponentdialoges6javascript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架