Convert Figma logo to code with AI

maxs15 logoreact-native-modalbox

A <Modal/> component for react-native

2,894
505
2,894
160

Top Related Projects

An enhanced, animated, customizable Modal for React Native.

A react native modals library. Swipeable. Highly customizable. Support multi modals & Support custom animation. For IOS & Android.

Standard set of easy to use animations and declarative transitions for React Native

React Native Cross-Platform WebView

Quick Overview

React Native Modalbox is a customizable modal component for React Native applications. It provides a flexible and easy-to-use solution for creating modals with various animations and styles, enhancing the user interface of mobile apps.

Pros

  • Highly customizable with numerous props for styling and behavior
  • Supports multiple animation types for opening and closing
  • Compatible with both iOS and Android platforms
  • Lightweight and easy to integrate into existing projects

Cons

  • Limited documentation and examples for advanced use cases
  • Some reported issues with performance on older devices
  • Lack of recent updates and maintenance (as of the last check)
  • May require additional customization for complex modal layouts

Code Examples

  1. Basic Modal Usage:
import Modal from 'react-native-modalbox';

<Modal isOpen={this.state.isOpen} onClosed={() => this.setState({isOpen: false})}>
  <Text>Basic Modal</Text>
</Modal>
  1. Customized Modal with Animation:
<Modal
  style={styles.modal}
  position={"center"}
  backdrop={true}
  entry={"slide"}
  swipeToClose={false}
  backdropPressToClose={true}
  onClosed={() => this.setState({isOpen: false})}
>
  <Text>Customized Modal</Text>
</Modal>
  1. Modal with Custom Styles:
<Modal
  style={[styles.modal, styles.modal3]}
  position={"center"}
  backdrop={false}
  coverScreen={true}
>
  <Text style={styles.text}>Modal with custom styles</Text>
</Modal>

Getting Started

  1. Install the package:

    npm install react-native-modalbox
    
  2. Import the Modal component in your React Native file:

    import Modal from 'react-native-modalbox';
    
  3. Use the Modal component in your render method:

    render() {
      return (
        <View>
          <Modal isOpen={this.state.isModalOpen} onClosed={() => this.setState({isModalOpen: false})}>
            <Text>Your modal content here</Text>
          </Modal>
        </View>
      );
    }
    
  4. Open the modal by setting the isOpen prop to true:

    this.setState({isModalOpen: true});
    

Competitor Comparisons

An enhanced, animated, customizable Modal for React Native.

Pros of react-native-modal

  • More actively maintained with frequent updates
  • Extensive customization options and props
  • Better TypeScript support

Cons of react-native-modal

  • Slightly more complex API
  • Larger package size

Code Comparison

react-native-modal:

import Modal from "react-native-modal";

<Modal isVisible={isModalVisible} onBackdropPress={toggleModal}>
  <View style={styles.modalContent}>
    <Text>Hello!</Text>
  </View>
</Modal>

react-native-modalbox:

import Modal from 'react-native-modalbox';

<Modal isOpen={isModalVisible} onClosed={toggleModal}>
  <View style={styles.modalContent}>
    <Text>Hello!</Text>
  </View>
</Modal>

Both libraries offer similar basic functionality, but react-native-modal provides more advanced features and customization options. It has better community support and documentation, making it easier to implement complex modal behaviors. However, react-native-modalbox is simpler to use for basic modal needs and has a smaller footprint.

The choice between the two depends on the project requirements. For more advanced modal functionality and ongoing support, react-native-modal is recommended. For simpler use cases or projects with size constraints, react-native-modalbox might be sufficient.

A react native modals library. Swipeable. Highly customizable. Support multi modals & Support custom animation. For IOS & Android.

Pros of react-native-modals

  • More comprehensive set of modal types (e.g., bottom modal, slide animation)
  • Better TypeScript support and type definitions
  • More active development and maintenance

Cons of react-native-modals

  • Slightly more complex API due to additional features
  • Larger package size due to more components and animations

Code Comparison

react-native-modals:

import Modal from 'react-native-modals';

<Modal
  visible={this.state.visible}
  onTouchOutside={() => this.setState({ visible: false })}
>
  <ModalContent>
    <Text>Hello World!</Text>
  </ModalContent>
</Modal>

react-native-modalbox:

import Modal from 'react-native-modalbox';

<Modal isOpen={this.state.isOpen} onClosed={() => this.setState({isOpen: false})}>
  <Text>Hello World!</Text>
</Modal>

Both libraries offer similar basic functionality, but react-native-modals provides more customization options and a wider range of modal types. react-native-modalbox has a simpler API and smaller package size, which may be preferable for projects with basic modal requirements. The choice between the two depends on the specific needs of your project, such as the variety of modal styles required and the importance of TypeScript support.

Standard set of easy to use animations and declarative transitions for React Native

Pros of react-native-animatable

  • More versatile, offering a wide range of animations for various UI elements
  • Supports custom animations and easing functions
  • Larger community and more frequent updates

Cons of react-native-animatable

  • Steeper learning curve due to more complex API
  • May require more code for simple animations
  • Not specifically designed for modal components

Code Comparison

react-native-animatable:

import * as Animatable from 'react-native-animatable';

<Animatable.View animation="fadeIn" duration={1000}>
  <Text>Animated content</Text>
</Animatable.View>

react-native-modalbox:

import Modal from 'react-native-modalbox';

<Modal isOpen={this.state.isOpen} onClosed={() => this.setState({isOpen: false})}>
  <Text>Modal content</Text>
</Modal>

react-native-animatable provides a more general-purpose animation solution, allowing developers to animate various components with different effects. It offers greater flexibility but may require more setup for specific use cases like modals.

react-native-modalbox, on the other hand, is specifically designed for creating modal components. It provides a simpler API for implementing modals but lacks the extensive animation capabilities of react-native-animatable.

Choose react-native-animatable for diverse animation needs across your app, or opt for react-native-modalbox if you primarily need a straightforward modal solution with basic animations.

React Native Cross-Platform WebView

Pros of react-native-webview

  • Specifically designed for rendering web content within React Native apps
  • Offers more advanced web-related features like JavaScript injection and navigation control
  • Actively maintained with regular updates and a large community

Cons of react-native-webview

  • Limited to web content display, not suitable for creating custom modal interfaces
  • May have performance overhead when used for simple content display
  • Requires additional setup and configuration for basic modal-like functionality

Code Comparison

react-native-webview:

import { WebView } from 'react-native-webview';

<WebView
  source={{ uri: 'https://example.com' }}
  onLoad={() => console.log('Loaded')}
/>

react-native-modalbox:

import Modal from 'react-native-modalbox';

<Modal isOpen={this.state.isOpen} onClosed={() => this.setState({isOpen: false})}>
  <Text>Modal content</Text>
</Modal>

react-native-webview is focused on rendering web content within React Native apps, offering advanced web-related features. It's ideal for displaying web pages or HTML content but may be overkill for simple modal interfaces. react-native-modalbox, on the other hand, is specifically designed for creating customizable modal dialogs with native performance. It's more suitable for creating app-specific modal interfaces but lacks web content rendering capabilities.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

react-native-modalbox

npm npm

A react native component, easy, fully customizable, implementing the 'swipe down to close' feature.

Wanna implement IAP in your beautiful modal? 👇

IAPHUB

Preview

Install

npm install react-native-modalbox@latest --save

Example

Check index.js in the Example folder.

Version note

react-nativereact-native-modalbox
<= 0.57<= 1.6.0
>= 0.58>= 1.6.1

Properties

PropDefaultTypeDescription
isOpenfalseboolOpen/close the modal, optional, you can use the open/close methods instead
isDisabledfalseboolDisable any action on the modal (open, close, swipe)
backdropPressToClosetrueboolClose the the modal by pressing on the backdrop
swipeToClosetrueboolSet to true to enable the swipe down to close feature
swipeThreshold50numberThe threshold to reach in pixels to close the modal
swipeArea-numberThe height in pixels of the swipeable area, window height by default
positioncenterstringControl the modal position using top or center or bottom
entrybottomstringControl the modal entry position top or bottom
backdroptrueboolDisplay a backdrop behind the modal
backdropOpacity0.5numberOpacity of the backdrop
backdropColorblackstringbackgroundColor of the backdrop
backdropContentnullReactElementAdd an element in the backdrop (a close button for example)
animationDuration400numberDuration of the animation
easingEasing.elastic(0.8)functionEasing function applied to opening modal animation
backButtonClosefalsebool(Android only) Close modal when receiving back button event
startOpenfalseboolAllow modal to appear open without animation upon first mount
coverScreenfalseboolWill use RN Modal component to cover the entire screen wherever the modal is mounted in the component hierarchy
keyboardTopOffsetios:22, android:0numberThis property prevent the modal to cover the ios status bar when the modal is scrolling up because the keyboard is opening
useNativeDrivertrueboolEnables the hardware acceleration to animate the modal. Please note that enabling this can cause some flashes in a weird way when animating

Events

PropParamsDescription
onClosed-When the modal is close and the animation is done
onOpened-When the modal is open and the animation is done
onClosingStatestate boolWhen the state of the swipe to close feature has changed (usefull to change the content of the modal, display a message for example)

Methods

These methods are optional, you can use the isOpen property instead

PropParamsDescription
open-Open the modal
close-Close the modal

NPM DownloadsLast 30 Days