react-native-global-modal icon indicating copy to clipboard operation
react-native-global-modal copied to clipboard

support closing nested modals

Open NorseGaud opened this issue 1 year ago • 5 comments

This is needed when there are nested modals and therefore multiple props so we can close the nested one

NorseGaud avatar Jan 28 '24 02:01 NorseGaud

@NorseGaud Can you please explain the use case? I'm having a hard time figuring it out. I would really appreciate some sort of video.

susonthapa avatar Jan 28 '24 10:01 susonthapa

Yeah, nested modals don't close using the hideGlobalModal function

NorseGaud avatar Jan 28 '24 12:01 NorseGaud

Sorry, can't share anything about my code due to IP, but I can say that the hideSub > oldProps shows:

 LOG  [{"Component": [Function Component], "hideClose": true, "modalKey": "1706408512865"}, {"Component": [Function Component], "hideClose": false, "modalKey": "1706408514142"}]

This prevents if (oldProps.length === 1) { from doing setIsVisible(false).

NorseGaud avatar Jan 28 '24 22:01 NorseGaud

Hi @susonthapa, any updates?

NorseGaud avatar Feb 14 '24 03:02 NorseGaud

Hi @susonthapa, any updates?

Sorry, I didn't get a chance to look into it. I will try to get back to you on weekends.

susonthapa avatar Feb 14 '24 04:02 susonthapa

Hey @susonthapa , just FYI I use this in production successfully.

NorseGaud avatar May 31 '24 13:05 NorseGaud

@NorseGaud Sorry for the late reply, I tested your changes and found some issue. Notice when you click the cancel button in one of the modal it dismisses the entire stack which is obivious from the code changes but I wanted to verify it anyway. Here is a demo video.

Original behavior

https://github.com/susonthapa/react-native-global-modal/assets/33973551/500012dd-fc45-4350-89b7-74539af3122c

With PR changes

https://github.com/susonthapa/react-native-global-modal/assets/33973551/1e9576bd-1b30-4406-a429-85d91104ef51

I won't be merging this PR so feel free to close it or I can close it later.

susonthapa avatar Jun 16 '24 06:06 susonthapa

Thanks @susonthapa, but it has been too long since I've looked at this and I have forgotten even what I did. Regardless, closing the whole stack is not an entirely useless feature. There are some situations I would want this. But there are also situations I would not. Seems like we need to add a way to toggle it and then add the code to not close the stack on nested close, right? Why do you want to block merging the PR and close this instead of fixing it?

NorseGaud avatar Jun 16 '24 13:06 NorseGaud

Thanks @susonthapa, but it has been too long since I've looked at this and I have forgotten even what I did. Regardless, closing the whole stack is not an entirely useless feature. There are some situations I would want this. But there are also situations I would not. Seems like we need to add a way to toggle it and then add the code to not close the stack on nested close, right? Why do you want to block merging the PR and close this instead of fixing it?

I haven't been able to wrap my head around your use case for nested modals. The whole point of Global Modal is to remove the need for nested modals.

Why do you want to block merging the PR and close this instead of fixing it?

Without more information on the use case, I won't have any idea on what I'm fixing.

susonthapa avatar Jun 17 '24 02:06 susonthapa

Super super confused. Your examples have Nested Modals. When you say "The whole point of Global Modal is to remove the need for nested modals.", then why is there an example for it? It's a valid usecase too. Sometimes I need to generate a yes or no confirmation for an existing modal.

The issue should be fairly clear and you even mentioned it in your reply: "Notice when you click the cancel button in one of the modal it dismisses the entire stack". It should be fairly simple to fix this, but I worry it will be rejected now even if a solution is created.

NorseGaud avatar Jun 17 '24 14:06 NorseGaud

Sorry if I sound rude, but I agree the example is confusing. The "Nested Modal" in the example shows how you can open a Modal from within the Modal but those are not nested when rendered. The idea is pretty simple, the app renders a single Modal and switches the content to mimic nested Modals.

If you want to close any Modal you can just use "hideGlobalModal" with the key of the modal you want to close. There is also skipQueue flag that you can set which will dismiss the current modal when you want to show another one.

Let me know if this fixes your issue. If you have a valid use case, then feel free to add an example in the sample app and I can take a look into it.

susonthapa avatar Jun 19 '24 13:06 susonthapa