colorfy-software / react-native-modalfy

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

How to configure the option to close automatically (e.g. after 3000 ms) and not to close when clicking on the background? #133

Closed clin211 closed 6 months ago

clin211 commented 9 months ago

How to configure the option to close automatically (e.g. after 3000 ms) and not to close when clicking on the background?

clin211 commented 9 months ago

I want to set the modal not to close when clicking on the background when calling openModal, and also how to set it to close automatically when calling openModal (e.g.: automatically close after 3000ms)

CharlesMangwa commented 6 months ago

hey @clin211! thank you for your patience. in case you haven't figure out how to make this happen yet:

  1. you can prevent the backdrop/back button from closing the modal by setting the modal option backBehavior: 'none'.
  2. a regular useEffect inside the modal component that's being opened should do the trick:
    
    // ./modals/AlertModal.tsx

// ...

useEffect(() => { const timeout = setTimeout(closeAllModals, 3000) return () => clearTimeout(timeout) }, [closeAllModals])

// ...