colorfy-software / react-native-modalfy

🥞 Modal citizen of React Native.
https://colorfy-software.gitbook.io/react-native-modalfy
MIT License
1.06k stars 41 forks source link

Is it possible to check which modals are currently open before opening a modal? #115

Closed tunztunztunz closed 1 year ago

tunztunztunz commented 1 year ago

I stumbled upon some old information that suggested I use isModalOpen, but that appears to be deprecated. I see currentModal, but I'm not sure how I can use that in the same effect as isModalOpen. I don't see any examples.

CharlesMangwa commented 1 year ago

hi @tunztunztunz! i'm not sure where you find that old info as currentModal has always been the way to go since pretty much the very first version of the library:

https://github.com/colorfy-software/react-native-modalfy/blob/8037363e85f4aa1ab41c84d5bc3a8677ac7cafab/types.js#L51-L57

but in case the way to use it wasn't super clear: let's say you're writing some code inside a LoginModal.tsx file. if we had isModalOpen, you could have just been able to access props.modal.isModalOpen and check if that was the case. however, if you were to switch to, let's say, your RegistrationModal.tsx file: you would have not be able to know if LoginModal was open, you'd only know if RegistrationModal was (limitation due to the nature of isModalOpen).

that's why we went for currentModal as it returns the modal name you've provided when adding your modal to createModalStack() (1st) object. thanks to that, now even if you're inside RegistrationModal, you can check if props.modal.currentModal === 'RegistrationModal' or even props.modal.currentModal === 'LoginModal'.

and if no modal is opened, currentModal will simply be null. hope that helped, let me know if not!