React-native-modal: Can't immediatly open a new modal after closing one

Created on 30 Jul 2018  路  4Comments  路  Source: react-native-modal/react-native-modal

I have two modals and closing the first one leads to opening the second one:

this.setState({
    isFirstModalVisible: false,
    isSecondModalVisible: true,
})

This works fine with react-native's modal, but with react-native-modal, the second one won't show up.

I have tried to use a callback function:

this.setState({isFirstModalVisible: false}, () => {
isSecondModalVisible: true,
})

But it's still not working with react-native-modal

My current solution is to have a timeout function with 0.5s delay to open the second modal, but this introduced an unwanted delay. Are there any other better workarounds without delays?

on hold question

Most helpful comment

This is happening because you can't have two modal on screen at the same time and while the modal is transitioning out it is still considered "on screen", which is the reason why your timeout workaround works correctly.

A cleaner and more robust solution is showing the second modal when onModalHide of the first modal is triggered.

Let me know if it fixes your issues.

All 4 comments

I have same issues........

This is happening because you can't have two modal on screen at the same time and while the modal is transitioning out it is still considered "on screen", which is the reason why your timeout workaround works correctly.

A cleaner and more robust solution is showing the second modal when onModalHide of the first modal is triggered.

Let me know if it fixes your issues.

@mmazzarolo Thanks it worked! I did not know about that. I try to use modal as the way i use it in React.js

this.setState({loadingModal : false});
setTimeout(function(){this.setState({loadModalConfirm : true})}, 500);

giving a delay to next modal worked for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JuniusAng picture JuniusAng  路  4Comments

ShaikhKabeer picture ShaikhKabeer  路  3Comments

onfuns picture onfuns  路  3Comments

HoaiHuynh picture HoaiHuynh  路  3Comments

rodrigowpl picture rodrigowpl  路  3Comments