# react-native-ls-modals-controller

> A React Native library to control multiple modals as a queue or a stack and avois some errors, specially on iOS

Latest version **1.1.4** (published 2022-06-26) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install react-native-ls-modals-controller
pnpm add react-native-ls-modals-controller
yarn add react-native-ls-modals-controller
bun add react-native-ls-modals-controller
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2022-06-26 |
| First published | 2021-11-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Leandro Simões |
| Maintainers | leandrosimoes |
| Keywords | react-native, modals, queue, library |

## Links

- npm: https://www.npmjs.com/package/react-native-ls-modals-controller
- Repository: https://github.com/leandrosimoes/react-native-ls-modals-controller
- npm.io page: https://npm.io/package/react-native-ls-modals-controller

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 1.1.4 (latest) — 2022-06-26
- 1.1.3 — 2022-06-26
- 1.1.2 — 2021-11-04
- 1.1.1 — 2021-11-04
- 1.0.3 — 2021-11-04
- 1.0.2 — 2021-11-04
- 1.0.1 — 2021-11-04
- 1.0.0 — 2021-11-04

## README

# react-native-ls-modals-controller

[![Codacy Badge](https://app.codacy.com/project/badge/Grade/b3d75dc0717a476198c95eea568847d4)](https://www.codacy.com/gh/leandrosimoes/react-native-ls-modals-controller/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=leandrosimoes/react-native-ls-modals-controller&amp;utm_campaign=Badge_Grade)
[![npm version](https://badge.fury.io/js/react-native-ls-modals-controller.svg)](https://badge.fury.io/js/react-native-ls-modals-controller)
![Node.js Package](https://github.com/leandrosimoes/react-native-ls-modals-controller/workflows/Node%2Ejs%20Package/badge.svg)

A React Native library to control multiple modals as a queue or a stack and avois some errors, specially on iOS

## Install

`npm i react-native-ls-modals-controller` 

or 

`yarn add react-native-ls-modals-controller`

## Usage

1) Wrap your app content with the `ModalQueueProvider` or `ModalStackProvider`

```jsx
import { ModalQueueProvider, ModalStackProvider } from 'react-native-ls-modals-controller'

export default App = () => {
    return (
        <ModalQueueProvider>
            <ModalStackProvider>
                ...
            </ModalStackProvider>
        </ModalQueueProvider>
    )
}
```

* PS: We strongly recomend using just one controller, `ModalQueueProvider` or `ModalStackProvider`. Since the state of both are not shared between each other, just use in case you really know how you'll control between the modals in each provider. We are planing to create a better way to manage that in the future.

2) Create a `ModalQueue` or a `ModalStack` and add some `ModalQueueItem` or `ModalStackItem` childs as you want

```jsx
const defaultModalProps = { animationType: 'slide' }

<ModalQueue>
    <ModalQueueItem id={1} component={...} {...defaultModalProps} />
    <ModalQueueItem id={2} component={...} {...defaultModalProps} />
    <ModalQueueItem id={3} component={...} {...defaultModalProps} />
    ...
</ModalQueue>

<ModalStack>
    <ModalStackItem id={1} component={...} {...defaultModalProps} />
    <ModalStackItem id={2} component={...} {...defaultModalProps} />
    <ModalStackItem id={3} component={...} {...defaultModalProps} />
    ...
</ModalStack>
```

3) Use the `useModalQueue` or `useModalStack` hooks to have access for state and methods

```jsx
    const { state, currentId, enqueue, dequeue, clear } = useModalQueue()
    ...
    
    const { state, currentId, add, remove, clear } = useModalStack()
    ...
```

## Types

```typescript
type ModalControllerState = {
    queue: Array<number | string>
}

type ModalControllerContextProps = {
    state: ModalControllerState
    setState: React.Dispatch<React.SetStateAction<ModalControllerState>>
}

type ModalQueueItemProps = ModalProps & {
    id: number | string
    component: React.ReactNode
    timeoutThreshold?: number
}

type ModalStackItemProps = ModalProps & {
    id: number | string
    component: React.ReactNode
    timeoutThreshold?: number
}

type ModalQueueProps = {
    timeoutThreshold?: number
    children:
        | React.ReactElement<ModalQueueItemProps>[]
        | React.ReactElement<ModalQueueItemProps>
}

type ModalStackProps = {
    timeoutThreshold?: number
    children:
        | React.ReactElement<ModalStackItemProps>[]
        | React.ReactElement<ModalStackItemProps>
}
```

---
_Source: https://npm.io/package/react-native-ls-modals-controller · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
