Modal prop
Every modal component you added in your modal stack (see createModalStack) receives the modal prop automatically:
this.props.modalcurrentModal: name of the current displayed modal if there's oneopenModal: open a specific modalcloseModal: close a modalcloseModals: close every instance of a given modalcloseAllModals: close all opened modalsaddListener: subscribe to updates to modal lifecycleremoveAllListeners: remove all modal listenersparams: current modal's paramsgetParams: get current's modal params with fallback
Be aware that only components in you modal stack do receive this prop. If you're looking for how to access the modal prop from any component, head to withModal/useModal sections.
API reference
currentModal - Get the currently displayed modal's name
currentModal - Get the currently displayed modal's name// type CurrentModal = ?ModalName
const { currentModal } = this.props.modalReturns the name of the current modal, null if none is currently displayed or if you're displaying several modals, the name of the one on top of the stack (currently shown to the user).
openModal - Open a modal
openModal - Open a modalUse this to open any modal you've setup.
closeModal - close a modal
closeModal - close a modalThis function closes a modal. Depending on your modal stack configuration it will either: close the first modal in your stack or clear the whole stack (see createModalStack).
closeModals - close every instance of a given modal
closeModals - close every instance of a given modalReact Native Modalfy workflow allows you to use the same modal component several times. Moreover, it also let you call and display the same modal several times.
Let's say that for some reason you have to display several error modals to your user, if they perform the action needed to fix everything: you don't want them to have to close all the modals one by one. Similarly, it'd be nice if you didn't have to programmatically close all of them: that's what closeModals is here for.
You'll just have to pass as an argument the name of the modal you'd like to close and all its instances will be deleted.
closeAllModals - close all opened modals
closeAllModals - close all opened modalsThis function will close every single opened modal, clearing the whole stack.
addListener - subscribe to updates to modal lifecycle
addListener - subscribe to updates to modal lifecycleAs the name suggest, addListener allows you to hook listeners to your current modal. For now, only onAnimate is supported as a valid EventName. If you need to perform any animation at the same time as your modal, this function is what you'll need.
Note: addListener returns an EventSubscription object, in which you'll find a remove() method to use as soon as you'll no longer to listen to your modal updates.
removeAllListeners - remove all modal listeners
removeAllListeners - remove all modal listenersAs seen in the previous section, addListener returns an object with a remove() function in it. However if you have a lot of listeners subscribed to the same modal component, calling listenerA.remove(), listernerB.remove(), listernerC.remove() isn't ideal. That's what removeAllListeners is here for: just call it once and all the modal listeners will be removed.
params - current modal's params
params - current modal's paramsThis is the other way to access a modal's params. Here you'll directly have access to the data you passed.
Note: If you're outside a modal component (aka you used withModal/useModal) you won't have any params key in this.props.modal.
getParams - get current modal's params with fallback
getParams - get current modal's params with fallbackLast updated
Was this helpful?