React Native Modalfy
v3.x
v3.x
  • Getting started
  • Installation
  • ๐Ÿค“Guides
    • Creating a stack
    • Opening & closing
    • Passing params
    • Triggering a callback
    • Type checking with TypeScript
    • Subscribing to events
    • Using outside React
    • Upgrading from v2.x
  • ๐Ÿ“šAPI Reference
    • Types
      • ModalStackConfig
      • ModalOptions
      • ModalProp
      • ModalComponentProp
      • ModalProps
      • ModalComponentWithOptions
    • ModalProvider
    • createModalStack
    • useModal
    • withModal
    • modalfy
  • ๐Ÿ“ฐBlog
    • Unveiling Modalfy v3
    • Announcing Modalfy v2
    • Stacks on stacks in React Native
    • Introducing a Modal Citizen
  • ๐Ÿ—ƒ๏ธOthers
    • Help
    • Contributing
    • Changelog
    • GitHub
Powered by GitBook
On this page

Was this helpful?

  1. API Reference

modalfy

Function that exposes Modalfy's API outside of React's context. The object returned by modalfy()is covered in ModalProp.

Note: Do not use if you're inside a React component. Please consider useModal() or withModal() instead.

const modalfy = <
  P extends ModalfyParamsm,
  M extends keyof P
>(): UsableModalProp<P> => {
  const context: UsableModalProp<P> = React.useContext(ModalContext)
  return {
    closeAllModals: (callback?: () => void) => {
      ModalState.queueClosingAction({ action: 'closeAllModals', callback })
    },

    closeModals: (modalName: M, callback?: () => void) =>
      ModalState.queueClosingAction({
        action: 'closeModals',
        modalName,
        callback,
      }),
      
    closeModal: (modalName?: M, callback?: () => void) => {
      ModalState.queueClosingAction({
        action: 'closeModal',
        modalName,
        callback,
      })
    },

    currentModal: ModalState.getState<P>()?.currentModal,

    openModal: (modalName: M, params?: P[M], callback?: () => void) =>
      ModalState.openModal(modalName, params, true, callback),
  }
}

If you're using TypeScript and have your params types, you can get some nice autocomplete by utilizing modalfy()like this:

import { ModalStackParamsList } from 'App'
// ...
const { openModal } = modalfy<ModalStackParamsList>()
PreviouswithModalNextUnveiling Modalfy v3

Last updated 10 months ago

Was this helpful?

๐Ÿ“š
react-native-modalfy/ModalState.ts at main ยท colorfy-software/react-native-modalfyGitHub
Logo