npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

magic-modal

v10.2.1

Published

A magic modal that can be used imperatively from anywhere! 🦄

Downloads

588

Readme

How it works

  1. MagicModalPortal owns the modal stack. Mount it once, near the root.
  2. magicModal.show() pushes one entry and returns an awaitable handle.
  3. useMagicModal().hide(data) closes that entry with typed data.
  4. The handle resolves to HideReturn<T>, including the close reason.

The handle is the promise itself, carrying that entry's modalID, update, and hide. The caller resumes with submitted data or the exact dismissal reason.

const result = await magicModal.show<ConfirmationResult>(ConfirmationModal, {
  accessibilityLabel: "Confirm publish",
});

if (result.reason === MagicModalHideReason.INTENTIONAL_HIDE) {
  await publish(result.data);
} else {
  recordCancellation(result.reason);
}

const { promise, modalID, update } = magicModal.show(...) still works; promise is a deprecated alias of the handle itself.

Every stack entry keeps its own component, configuration, ID, and promise. A second show() call can open above the current modal without mixing their results.

Installation

Expo chooses versions compatible with the installed SDK.

Expo Web

pnpm add magic-modal
npx expo install react-native-gesture-handler react-native-reanimated react-native-worklets react-dom react-native-web @expo/metro-runtime

Expo Web bundles through Metro under the react-native condition, so it loads the native entry and takes the same peers as iOS and Android. The browser-only install is the Next.js one below. Read the Expo guide for the portal and web command.

Expo iOS

pnpm add magic-modal
npx expo install react-native-gesture-handler react-native-reanimated react-native-worklets react-native-screens

Expo Android

pnpm add magic-modal
npx expo install react-native-gesture-handler react-native-reanimated react-native-worklets react-native-screens

iOS and Android use the same native dependency set. The native guide covers pods, Android back handling, and iOS overlays.

Next.js and other browser-only React apps

pnpm add magic-modal

That is the whole install. The web entry ships with zero React Native dependencies, so a browser application needs no bundler alias and no gesture or animation peer. The native entries use the full React Native stack, which is why the Expo commands above install more. Copy the Client Component setup from the Next.js guide. A runnable App Router consumer lives in examples/next-web.

For bare React Native, follow the installation guide.

Mount the portal

Expo and native applications mount one portal inside GestureHandlerRootView:

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

export default function App() {
  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <YourApp />
      <MagicModalPortal />
    </GestureHandlerRootView>
  );
}

With Expo Router, put the same structure in the root app/_layout.tsx.

A browser application mounts MagicModalPortal inside a Client Component and nothing else. There is no GestureHandlerRootView, because there is no Gesture Handler in the browser bundle. Copy the shell from the web setup.

Return typed data

Use the same result type in show<T>() and useMagicModal<T>():

import { Pressable, Text, View } from "react-native";
import { MagicModalHideReason, magicModal, useMagicModal } from "magic-modal";

type ConfirmationResult = {
  confirmed: boolean;
};

function ConfirmationModal() {
  const { hide } = useMagicModal<ConfirmationResult>();

  return (
    <View>
      <Text accessibilityRole="header">Publish this release?</Text>
      <Pressable accessibilityRole="button" onPress={() => hide({ confirmed: true })}>
        <Text>Publish</Text>
      </Pressable>
      <Pressable accessibilityRole="button" onPress={() => hide({ confirmed: false })}>
        <Text>Cancel</Text>
      </Pressable>
    </View>
  );
}

export async function confirmRelease() {
  const result = await magicModal.show<ConfirmationResult>(ConfirmationModal, {
    accessibilityLabel: "Publish this release",
  });

  if (result.reason !== MagicModalHideReason.INTENTIONAL_HIDE) {
    return { confirmed: false, reason: result.reason };
  }

  return result.data;
}

That modal is the React Native one. The browser entry renders DOM, so the same modal on the web is a <section> with <h2> and <button> and imports nothing from React Native. The result contract is identical either way.

Backdrop presses, completed swipes, system-dismiss actions, and hideAll() resolve the same promise with distinct reasons. System dismissal includes Android back, web Escape, and the native accessibility escape action. TypeScript exposes data after the caller narrows the result to INTENTIONAL_HIDE.

Documentation

The kitchen-sink Expo app contains runnable native flows. The interactive site runs the package in the browser.

FAQ

Can multiple modals be open?

Yes. Every show() call creates an independent stack entry with its own ID, configuration, and promise.

Can a modal contain a ScrollView?

Yes. Disable swipe dismissal:

magicModal.show(ScrollableModal, {
  swipeDirection: undefined,
});

Magic Modal doesn't implement snap points or nested scrolling.

How do I close a modal from outside its component?

Keep the ID returned by show():

const { modalID } = magicModal.show(StatusModal);
magicModal.hide(undefined, { modalID });

Inside modal content, use useMagicModal().hide().

How do I render below a native picker on iOS?

Temporarily call magicModal.disableFullWindowOverlay(). Restore it in a finally block after the picker closes. The native overlay guide contains the complete pattern.

Contributors

See everyone who has contributed and read the contributing guide.

License

Magic Modal is licensed under the MIT License.