Fix: Crash index out of bounds when open multiple modal the second time #340
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is going on?
We got crash when having a multiple modal, then open the top modal a second time.
The crash error:
Level: {crash}
How to reproduce?
Condition
Step
open the top modal, close it, and open it again
Caused by
when the modal is not visible, the library will only return
View
without zIndex props, and when it's visible, it'll return a view with a zIndex style props.I'm not sure about the cause, but because the js side and native side is asynchronously connected, then maybe when the modal is about to be opened, the native side is trying to reOrder the view with zIndex (at com.facebook.react.uimanager.ViewGroupDrawingOrderHelper.getChildDrawingOrder) while the View with zIndex props is not ready yet. That's why we got
java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
Resolved by
We return a
View
with the same zIndex (use styles.transparent) when the modal is not visible, in this way, the view group will have the same number of view with a zIndex props to prevent anot ready
view whether it's visible or not.