
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
react-native-modal-2
Advanced tools
A powerful, customizable modal library for React Native with smooth animations, touchable backdrop, and comprehensive TypeScript support.
A powerful, customizable modal library for React Native with smooth animations, touchable backdrop, and comprehensive TypeScript support.
# npm
npm install react-native-modal-2
# yarn
yarn add react-native-modal-2
# pnpm
pnpm add react-native-modal-2
import React from "react";
import { View, Text, Button, StyleSheet } from "react-native";
import { Modal, useModal } from "react-native-modal-2";
const App = () => {
const { visible, showModal, hideModal } = useModal();
return (
<View style={styles.container}>
<Button title="Show Basic Modal" onPress={showModal} />
<Modal visible={visible} onBackdropPress={hideModal} animationType="fade">
<View style={styles.modalContent}>
<Text style={styles.title}>Hello!</Text>
<Text style={styles.description}>
This is a basic modal with a fade animation.
</Text>
<Button title="Close" onPress={hideModal} />
</View>
</Modal>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
padding: 20,
},
modalContent: {
backgroundColor: "white",
padding: 20,
borderRadius: 10,
maxWidth: "80%",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
title: {
fontSize: 18,
fontWeight: "bold",
marginBottom: 10,
},
description: {
marginBottom: 20,
},
});
export default App;
import React, { useState } from "react";
import { View, Text, Button, StyleSheet } from "react-native";
import { AnimatedModal } from "react-native-modal-2";
const App = () => {
const [slideModalVisible, setSlideModalVisible] = useState(false);
const [bounceModalVisible, setBounceModalVisible] = useState(false);
const [zoomModalVisible, setZoomModalVisible] = useState(false);
return (
<View style={styles.container}>
<Button
title="Slide Up Modal"
onPress={() => setSlideModalVisible(true)}
style={styles.button}
/>
<Button
title="Bounce Modal"
onPress={() => setBounceModalVisible(true)}
style={styles.button}
/>
<Button
title="Zoom Modal"
onPress={() => setZoomModalVisible(true)}
style={styles.button}
/>
{/* Slide Modal */}
<AnimatedModal
visible={slideModalVisible}
onBackdropPress={() => setSlideModalVisible(false)}
animationIn="slide"
animationDirection="up"
backdropOpacity={0.7}
contentContainerStyle={styles.modalContent}
>
<Text style={styles.title}>Slide Up Modal</Text>
<Text style={styles.description}>
This modal slides up from the bottom of the screen.
</Text>
<Button title="Close" onPress={() => setSlideModalVisible(false)} />
</AnimatedModal>
{/* Bounce Modal */}
<AnimatedModal
visible={bounceModalVisible}
onBackdropPress={() => setBounceModalVisible(false)}
animationIn="bounce"
animationDirection="down"
backdropColor="#2c3e50"
contentContainerStyle={styles.modalContent}
>
<Text style={styles.title}>Bounce Modal</Text>
<Text style={styles.description}>
This modal bounces in from the top with a custom backdrop color.
</Text>
<Button title="Close" onPress={() => setBounceModalVisible(false)} />
</AnimatedModal>
{/* Zoom Modal */}
<AnimatedModal
visible={zoomModalVisible}
onBackdropPress={() => setZoomModalVisible(false)}
animationIn="zoom"
animationOut="zoom"
animationDuration={400}
contentContainerStyle={styles.modalContent}
>
<Text style={styles.title}>Zoom Modal</Text>
<Text style={styles.description}>
This modal zooms in and out with a custom animation duration.
</Text>
<Button title="Close" onPress={() => setZoomModalVisible(false)} />
</AnimatedModal>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
padding: 20,
},
button: {
marginVertical: 10,
},
modalContent: {
backgroundColor: "white",
padding: 20,
borderRadius: 10,
maxWidth: "80%",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
title: {
fontSize: 18,
fontWeight: "bold",
marginBottom: 10,
},
description: {
marginBottom: 20,
},
});
export default App;
The Modal component provides a simple modal with basic animation options.
| Prop | Type | Default | Description |
|---|---|---|---|
| visible | boolean | required | Controls the visibility of the modal |
| onBackdropPress | function | required | Callback when backdrop is pressed or modal is closed |
| children | ReactNode | required | Content to render inside the modal |
| animationType | 'none' | 'slide' | 'fade' | 'fade' | Type of animation for the modal |
| backdropOpacity | number | 0.5 | Opacity of the backdrop |
| backdropColor | string | '#000' | Color of the backdrop |
| contentContainerStyle | ViewStyle | {} | Style for the content container |
| style | ViewStyle | {} | Style for the modal container |
| closeOnBackdropPress | boolean | true | Whether to close the modal when backdrop is pressed |
| animationDuration | number | 300 | Duration of the animation in milliseconds |
| statusBarTranslucent | boolean | true | Whether the modal should appear under the status bar |
| ...otherProps | RNModalProps | - | Any other props from React Native's Modal component |
The AnimatedModal component extends the basic Modal with more advanced animation options.
Includes all props from the Modal component, plus:
| Prop | Type | Default | Description |
|---|---|---|---|
| animationIn | 'fade' | 'slide' | 'bounce' | 'zoom' | 'fade' | Type of entrance animation |
| animationOut | 'fade' | 'slide' | 'bounce' | 'zoom' | same as animationIn | Type of exit animation |
| animationDirection | 'up' | 'down' | 'left' | 'right' | 'up' | Direction of the animation |
| avoidKeyboard | boolean | false | Whether the modal should avoid the keyboard |
| ...otherProps | RNModalProps | - | Any other props from React Native's Modal component |
A convenient hook for managing modal visibility state.
const { visible, showModal, hideModal, toggleModal } = useModal(initialState);
| Parameter | Type | Default | Description |
|---|---|---|---|
| initialState | boolean | false | Initial visibility state of the modal |
| Return Value | Type | Description |
|---|---|---|
| visible | boolean | Current visibility state |
| showModal | function | Function to show the modal |
| hideModal | function | Function to hide the modal |
| toggleModal | function | Function to toggle the modal visibility |
The modal fades in and out with a smooth opacity transition.
The modal slides in from the specified direction (up, down, left, right).
The modal bounces in from the specified direction with a spring-like effect.
The modal zooms in and out with a scaling effect.
The library doesn't apply any default styling to your modal content, giving you complete freedom to design it however you want. You need to provide your own styling through the contentContainerStyle prop:
<AnimatedModal
visible={visible}
onBackdropPress={hideModal}
animationIn="slide"
contentContainerStyle={{
backgroundColor: "#f8f9fa",
borderRadius: 15,
padding: 20,
width: "90%",
shadowColor: "#000",
shadowOffset: { width: 0, height: 10 },
shadowOpacity: 0.3,
shadowRadius: 20,
elevation: 10,
}}
backdropColor="#2c3e50"
backdropOpacity={0.8}
>
{/* Modal content */}
</AnimatedModal>
<AnimatedModal
visible={visible}
onBackdropPress={hideModal}
animationIn="bounce"
animationDuration={500} // Slower animation (500ms)
contentContainerStyle={styles.modalContent}
>
{/* Modal content */}
</AnimatedModal>
You can pass any props from React Native's Modal component directly to our Modal components:
<Modal
visible={visible}
onBackdropPress={hideModal}
animationType="fade"
contentContainerStyle={styles.modalContent}
style={styles.modalWrapper} // Style for the modal container
hardwareAccelerated={true} // React Native Modal prop
supportedOrientations={["portrait", "landscape"]} // React Native Modal prop
onShow={() => console.log("Modal shown")} // React Native Modal prop
>
{/* Modal content */}
</Modal>
We're constantly working to improve react-native-modal-2. Here are some features we plan to add in future releases:
animationInDuration) and exit (animationOutDuration) animationshasBackdrop prop to completely disable the backdrop when neededonModalShow and onModalHide callbacks for better control of modal lifecycleKeyboardAvoidingView integration with automatic content adjustment when keyboard appearsHave a feature request? Feel free to open an issue or submit a pull request!
If animations aren't working correctly:
If your modal content isn't displaying correctly:
contentContainerStyleIf you're experiencing performance issues:
useNativeDriver: true for animations (this is enabled by default)Contributions are welcome! Please feel free to submit a Pull Request.
MIT
FAQs
A powerful, customizable modal library for React Native with smooth animations, touchable backdrop, and comprehensive TypeScript support.
We found that react-native-modal-2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.