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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-queued-modals

v0.0.4

Published

An enhanced React Native modal

Downloads

4

Readme

react-native-queued-modals

Manage your React Native modals with ease using a queue system.

Introduction

react-native-queued-modals was developed to address a challenge with react-native-modal: managing multiple modals. When displaying several modals, developers had to rely on the onModalHide callback. This becomes particularly cumbersome if there are multiple modals with various display combinations. With our queue system, you can effortlessly add and manage multiple modals.

Installation

npm install react-native-queued-modals --save

or if you use Yarn:

yarn add react-native-queued-modals

Usage

Basic Usage

  1. Wrap your App with ModalQueueProvider:

This provider gives access to the modal queue context to the rest of your app.

import { ModalQueueProvider } from 'react-native-queued-modals';

function App() {
  return (
    <ModalQueueProvider>
      {/* Rest of your app components */}
    </ModalQueueProvider>
  );
}
  1. Use the useModalQueue hook in your components:

This hook provides two functions: addModal and closeModal.

import { useModalQueue } from 'react-native-queued-modals';

function SomeComponent() {
  const { addModal, closeModal } = useModalQueue();

  const handleButtonClick = () => {
    addModal({
      children: <YourModalContentComponent />,
      // Other react-native-modal props (optional)
    });
  };

  return <Button onPress={handleButtonClick} title="Show Modal" />;
}
  1. Close the modal:

Once you've shown a modal using addModal, you can close it by invoking the closeModal function.

function YourModalContentComponent() {
  const { closeModal } = useModalQueue();

  return (
    <>
      <Text>Hello from modal!</Text>
      <Button onPress={closeModal} title="Close" />
    </>
  );
}

Handling Multiple Modals

In more complex scenarios, you might want to display another modal from an already open modal. Here's how you can seamlessly achieve this with react-native-queued-modals.

  1. Open the initial modal:
function SomeComponent() {
  const { addModal } = useModalQueue();

  const handleClickTestModal = () => {
    addModal({
      children: (
        <Box flex={1} bgColor="white" p={2}>
          <VStack space={2}>
            <Button onPress={handleShowAnotherModal}>
              Show Another Modal
            </Button>
            <Button onPress={closeModal}>
              Close Modal
            </Button>
          </VStack>
        </Box>
      ),
    });
  };

  return <Button onPress={handleClickTestModal} title="Show Test Modal" />;
}
  1. Display a second modal from the open modal:
function handleShowAnotherModal() {
  closeModal();
  addModal({
    children: (
      <Box flex={1} bgColor="white" p={2}>
        <Button onPress={closeModal}>
          Close This Modal
        </Button>
      </Box>
    ),
  });
}

By utilizing the queue system, this flow ensures that modals are presented in the order they were added, providing an intuitive user experience.

Features

  • Queue system: If multiple modals are added before the previous ones are closed, they will be presented in the order they were added.
  • Extends react-native-modal: All the props and behaviors you love from react-native-modal can be passed through the addModal function.

Notes

  • useModalQueue must be used within a component that's a child of ModalQueueProvider. If not, it will throw an error.
  • Modals are automatically removed from the queue when they're closed.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.