react-native-magic-modal
TypeScript icon, indicating that this package has built-in type declarations

0.3.8Β β€’Β PublicΒ β€’Β Published

React Native Magic Modal πŸ¦„

React Native Magic Modal Banner

Docs | GitHub | FAQ | Article

[!NOTE]
Simplify your modal management in React Native with the React Native Magic Modal library. Effortlessly control modals, streamline complex flows, and create a seamless user experience.

Features

Highlights

React Native Magic Modal offers a superior experience compared to traditional modal implementations:

Table of Contents

Installation

Add peer dependencies to your project, if you haven't already:

yarn add react-native-reanimated
yarn add react-native-gesture-handler

Install the package:

yarn add react-native-magic-modal

Quickstart

Insert a MagicModalPortal at the top of your application structure, and a GestureHandlerRootView if you haven't already:

import { MagicModalPortal } from "react-native-magic-modal";
import { GestureHandlerRootView } from "react-native-gesture-handler";

export default function App() {
  return (
    <GestureHandlerRootView>
      <MagicModalPortal /> {/** At the top of your app component hierarchy */}
      <YourAppContent />
    </GestureHandlerRootView>
  );
}

Tip: the root _layout.tsx is usually the best place to put it in a project using expo-router.

Examples

Showcasing modal management on iOS and Android platforms:

iOS Android

Usage

import React from "react";
import { View, Text, TouchableOpacity } from "react-native";
import { MagicModalPortal, magicModal } from "react-native-magic-modal";
import { GestureHandlerRootView } from "react-native-gesture-handler";

const ConfirmationModal = () => (
  <View>
    <TouchableOpacity onPress={() => magicModal.hide({ success: true })}>
      <Text>Click here to confirm</Text>
    </TouchableOpacity>
  </View>
);

const ResponseModal = ({ text }) => (
  <View>
    <Text>{text}</Text>
    <TouchableOpacity onPress={() => magicModal.hide()}>
      <Text>Close</Text>
    </TouchableOpacity>
  </View>
);

const handleConfirmationFlow = async () => {
  // You can call `show` with or without props, depending on the requirements of the modal.
  const result = await magicModal.show(ConfirmationModal);

  if (result.success) {
    return magicModal.show(() => <ResponseModal text="Success!" />);
  }

  return magicModal.show(() => <ResponseModal text="Failure :(" />);
};

export const MainScreen = () => {
  return (
    <GestureHandlerRootView>
      <TouchableOpacity onPress={handleConfirmationFlow}>
        <Text>Start the modal flow!</Text>
      </TouchableOpacity>
      <MagicModalPortal />
    </GestureHandlerRootView>
  );
};

Refer to the example for detailed usage scenarios.

Documentation

Access the complete documentation here.

FAQ

Q: Can I have two modals showing up at the same time?

A: No, we only allow one modal to be shown at a time. If you try to show a modal while another is already visible, the previous modal will be hidden.

Contributors

Special thanks to everyone who contributed to making React Native Magic Modal a robust and user-friendly library. See the full list.

See the contributing guide to learn how to contribute to the repository.

License

React Native Magic Modal is licensed under the MIT License.

Package Sidebar

Install

npm i react-native-magic-modal

Weekly Downloads

566

Version

0.3.8

License

MIT

Unpacked Size

40 kB

Total Files

6

Last publish

Collaborators

  • gabrieltaveira