Opening & closing
As soon as your modal stack is setup, you can start using React Native Modalfy from wherever you want in your code. You'll have 2 different ways to do so, depending on your context: either if you're inside a modal component or anywhere else in the code.
From a modal component
Each component you'll put inside the modalConfig
object you pass to createModalStack
will receive a modal
prop. From there, amongst other things we'll cover later (if you can't wait check out Modal prop section), you'll have access to openModal
and closeModal
functions. That's it!
You'll notice that in order to open a modal, React Native Modalfy uses the keys we put inside modalConfig
. So if our config looks like:
we can call openModal('NoConnection')
, openModal('MessageSent')
, etc.
From anywhere else in the code
This use case is probably more common than the 1st one: you're in a screen component and you want to open a modal from there. To do so, we'll use withModal
higher-order component (or useModal
hook) to access the same modal
we just saw:
Have a look at Modal prop API reference to see all the things you can perform with openModal
and have a complete overview of what does modal
bring with it.
Last updated