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

@relab/react-native-modals

v1.0.6

Published

Utility package to handle modals in React Native

Downloads

5

Readme

@relab/react-native-modals

Utility package to handle modals in React Native.

It provides show() function - once it called, modal component automatically mounts.

There are params and result for every modal should be defined when creating new modal component. It allows to have type inference when call show() - Typescript checks and intellisense benefits are in place.

It supports native OS modal as well as bottom sheet modal based on @gorhom/bottom-sheet.

Dependencies

Usage

  1. npm install --save @relab/react-native-modals
  2. Create @modals folder

config.ts

export * from '@/components/modal1'
export * from '@/components/modal2'
export * from '@/components/modal3'

index.ts

import { build } from '@relab/react-native-modals'

import * as Modules from './config'

export const { ModalContainer, registry, show } = build(Modules)
  1. Update _layout.tsx
import { FC } from 'react'
import { Slot } from 'expo-router'
import Animated from 'react-native-reanimated'

import { useModalContainerPosition } from '@relab/react-native-modals'

const RootLayout: FC = () => {
    const [, ref, modalStyles, nativeModuleShownRef] = useModalContainerPosition()

    return (
        <View style={{ flex: 1, backgroundColor: '#000' }}>
            <Animated.View style={[{ flex: 1, backgroundColor: '#fff'}, modalStyles]}>
                <Slot />
            </Animated.View>
            <ModalContainer positionRef={ref} nativeModalShownRef={nativeModuleShownRef} />
        </View>
    )
}

export default RootLayout
  1. Create Modal component
  2. Display modal - once show() is called, it will automatically mount new modal component and display it

Create Modal Component (bottom sheet)

components/modal1/index.ts

export * from './modal1'

components/modal1/modal1.tsx

import { FC } from 'react'
import { ModalProps } from '@relab/react-modals'
import { Modal } from '@relab/react-modals/bottom-sheet'

type Modal1Params = {
    accountId: number
}

type Modal1Result = boolean | undefined

const Modal1: FC<ModalProps<Modal1Params, Modal1Result>> = ({ params: { message, count }, onCloseRequest }) => {
    return (
        <Modal onCloseRequest={() => onCloseRequest(false)}>
            <View>
                <Text>Test Alert Modal: {accountId}</Text>
            </View>
        </Modal>
    )
}

export { Modal1 }

Create Modal Component (native)

components/modal2/index.ts

export * from './modal2'

components/modal2/modal2.tsx

import { FC } from 'react'
import { ModalProps } from '@relab/react-modals'
import { Modal } from '@relab/react-modals/native'

type Modal2Params = {
    accountId: number
}

type Modal2Result = boolean | undefined

const Modal2: FC<ModalProps<Modal2Params, Modal2Result>> = ({ params: { message, count }, onCloseRequest }) => {
    return (
        <Modal onCloseRequest={() => onCloseRequest(false)}>
            <View>
                <Text>Test Alert Modal: {accountId}</Text>
            </View>
        </Modal>
    )
}

export { Modal2 }

Show dialog

import { FC } from 'react'
import { show } from '@/modals'

const Page: FC = () => {
    return <div>
        <button onClick={async () => {
            const result = await show('Modal1', {
                accountId: 1,
            })
        }}>Show</button>
    </div>
}

export { Component1 }

License

Released under MIT by Sergey Zwezdin.