react-native-modal is an enhanced and highly customizable modal component for React Native, extending the capabilities of the built-in `<Modal>` component. It offers smooth enter/exit animations, flexible APIs, and features such as a customizable backdrop (opacity, color, timing), listeners for animation completion, automatic resizing on device rotation, and swipe-to-close functionality. The current development focus is on version 14.x, with `14.0.0-rc.1` being the latest release candidate, introducing support for React Native 0.78 and above. Historically, releases have been somewhat irregular, often aligning with major React Native version updates. This library differentiates itself by providing a richer user experience with built-in animations and gestures, which the native `<Modal>` component lacks by default.
npm install react-native-modalVerified import paths — ran on the pinned version, not inferred.
This example demonstrates a basic animated modal. It uses `useState` to control the modal's visibility via the `isVisible` prop and includes buttons to toggle its state.
Upgrade your React Native project to version 0.78.0 or newer, or use `react-native-modal` version `13.x` for React Native versions `>=0.70.0`.
Ensure your project is using `react-native` version `0.65` or higher. Update `react-native-modal` and potentially `react-native`.
Review TypeScript definitions for components consuming `react-native-modal` to account for optional `defaultProps`.
Exercise caution when using v14.x in production or Expo environments. Consider using the latest stable `13.x` release for greater stability on Expo.
Monitor the GitHub discussions and issues for updates on project maintenance and development. Consider contributing if you rely heavily on the library.
As a workaround, try conditionally hiding conflicting components (e.g., `Carousel`) when the modal is open. Ensure your root component is wrapped in `GestureHandlerRootView` if using `react-native-gesture-handler`.
Adjust `keyboardVerticalOffset` prop for `KeyboardAvoidingView` based on platform (`Platform.OS === 'ios' ? 0 : 0`). For iOS modals with native headers, manual calculation involving `useSafeAreaInsets` might be needed. Alternatively, consider third-party keyboard-aware solutions.
Ensure `isVisible` is always controlled by a state variable (`useState`) and update it reliably. Avoid `&&` for conditional rendering; instead, always render the `<Modal>` component and control its visibility solely via `isVisible`.
Ensure `react-native-gesture-handler` is correctly linked and the root component is wrapped in `GestureHandlerRootView`. If using `useNativeDriver`, verify that the animation properties are compatible (prefer `transform` properties). Disable `useNativeDriver` if visual animations are crucial and it causes issues.
Implement a delay or use animation end listeners (`onModalHide`, `onModalWillHide`) to ensure one modal is fully dismissed before attempting to open another. Avoid imperative modal patterns that do not respect the component lifecycle.