-
Notifications
You must be signed in to change notification settings - Fork 24k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LayoutAnimation crash on Android #27552
Comments
Thanks for sharing the investigation! Can you edit your post to include the contents of your PDF? That will make it so that people searching for this bug in the future can be more likely to find this. I think we are aware of a couple of long standing crashes with LayoutAnimation on Android but haven't been able to figure out how to repro or track it down. Do you have a small reproducible test case for this bug? That would be very helpful for us to figure out what's happening. |
Hi @TheSavior I updated the issue to include most of the details about the crash, sorry I don't have a reproducible test case to share, I mainly use our own app to reproduce it and am not allowed to share the code to you. |
If you don’t think it’s special to your codebase, would you be willing to spend some time creating a minimal repro case in an app outside of Amazon? Likely by creating a new app with react-native init? This would be important for us to be able to investigate and fix. |
Hi @TheSavior, I would love to create repro case in a brand new app to help investigating this issue, but I am working on a different project now, so I may not be able to work on that very soon. |
Hi, Im getting the exact same error number two with using draggable flatlist from https://github.com/computerjazz/react-native-draggable-flatlist. |
@TheSavior I've built a test app to reproduce the crash, see here https://github.com/ydongzhu/create-react-native-app |
FWIW, in the future it seems like this could be packaged as a snack and would make it easier for us to quickly repro. I was able to copy App.js into a playground locally and repro this crash. Also though, if I just tap the "HACK" button, it doesn't crash. I need to interact with the screen and scroll around. It's generally pretty easy to find a crash, but the repro steps are complex enough that it will take a while to figure out what's wrong. |
@JoshuaGross when you tap the 'HACK' button, what it's doing is actually repro the condition that puts the app into crash-ready state and then perform a regular view manipulation to trigger it. There will be one second delay to trigger the crash, so it doesn't happen immediately. The core part of repro the crash is manipulating views before deletion animation is finished. So you will see in the code that I manually set the duration of delete animation with 15 seconds to give enough time to do following view manipulation. You can modify the code to do whatever test you want as well. Please refer to the pdf attached in this issue, it has detailed explanation about the reason. |
@JoshuaGross is there any update for this issue? or any timeline or version we can expect to fix it? |
@JoshuaGross After reaching out to your team, we're going to move forward to look into this issue ourselves first and try to fix it. We will let you know if any questions we have and when there is a pull request for it as well. |
My team is struggling with issue number 3, react native 61 |
@JoshuaGross Tested the commits and it didn't work. Still receiving an IndexOutOfBoundsException. |
@JoshuaGross Tried my best to reproduce the bug on a snack with a similar code that was on my app but still no success. This bug is really hard to reproduce, it's kinda random. It's just refuse to happen on the snack, I don't know if it's because of expo. I'm going to try patching @ydongzhu repository with the commits to see if it solves. |
@JoshuaGross I've done the test with those three commits last week, sorry for the late response. Here is how I integrated those commits and tested it:
I've also debugged the code a little bit, the reason why IndexOutOfBoundsException happens is that pending deletion animations are not finished before manipulating children in dedf937. This issue will be gone if onAnimationEnd() is executed immediately when invoke Animation.cancel(), however it is posted into main thread's message queue and mess up the order of manipulating children when it's executed in the end. |
Looks like no one is working on this? Meanwhile, is there any good substitute to create a properly animated flat list? |
I guess this issue is not the priority of FB team for now so they just leave it here, I've not had any update for months. |
same problem on android index=15 count=14 |
@ydongzhu did you ever make any progress on this one? I think we're encountering the same or similar issue (although we don't use layoutAnimation, we heavily use animations). |
Unfortunately I haven't been actively working on this issue for a while, I had to move to other projects while I was waiting for the response. I'd like to rely on FB to fix it first since they had some progress on it already, from my opinion probably they just need to find a more robust way to solve the problem so all of cases, including the one that I pointed out in their commits, would be handled properly . |
Every week get crashlytics report with this issue on Android 10(Samsung, Xiaomi, Huawei, LGE). Any news? |
I’m testing my app after upgrading from RN 0.62.2 to 0.63.3 and randomly it crashes with The error seems to be related to this commit, where the "index adjustment fix" was removed. Looking at the code in NativeViewHierarchyManager.java where the crash originates (line 507), is it correct that in the preceding lines (from 491) there is an index “normalization” check only if there are pending deletions? react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java Lines 490 to 507 in 7100756
|
Same issue here. I can reliably reproduce this issue with repeated addition and removal of elements from a list of It doesn't seem to be related to the duration of the animation as I still get errors related to indices even with animation duration (20ms) way lower than the interval of triggering (2s). Update: Didn't want to be stuck with this issue, so I took some time to refactor my code from |
I don't think this is adding anything new to the conversation, but we also started seeing this crash when going from RN 0.61 to 0.63. We had to remove |
This started to happen to us after upgrading to 0.64.0. |
Had to disable layoutanimations on Android due to this. I think @lcarrettin may be right about the underlying cause but I don't have the native android experience to attempt a PR with a fix. |
We are able to reliably reproduce this in our app, though it's a fairly complex one. How can we be helpful? |
Hey peeps, this is still happening for us as well.. Affects thousands of users only on android I think this affect a lot of other people as well, currently this is the only fix working for us: |
Still happening to us as well, we have a pager view and an easeIn/Out layout animation will frequently crash it. |
I came across this issue as well. Right now, I solve it, by using reanimated layout animations in Android. |
Can someone confirm that it works? |
It seems like it is also causing an issue on the LayoutAnimation presets from related to this issue for us: software-mansion/react-native-reanimated#3234 |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
We've addressed 3 crashes so far that are related to LayoutAnimation while we are using RN 59.8 release in our app and each of them is impacting our users a lot.:
com.facebook.react.uimanager.IllegalViewOperationException: Trying to remove a view index above child count 0
at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren
...
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
...
at android.view.ViewGroup.addView
at com.facebook.react.uimanager.ViewGroupManager.addView
at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren
...
java.lang.IndexOutOfBoundsException: index=28 count=27
...
at android.view.ViewGroup.addView
at com.facebook.react.uimanager.ViewGroupManager.addView
at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren
...
We've also noticed there are a couple of commits trying to fix these crashes after 59.8 release and two of them are eventually merged:
which are built in the patch that we are going to apply to our app as well. This patch significantly reduces the chance of the first and third crashes happening, but it's still able to reproduce the second one, 'java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first'.
Since it's not easy to describe all details here, there is a collated document attached to this ticket that includes everything about the crash, e.g. stack trace, customized log and relevant code snippet.
React Native version:
59.8
Steps To Reproduce
We are using FlatList to wrap a list of cards and applying LayoutAnimation to it when state of content changes. Here is how we setup LayoutAnimation in JS code:
From our scenario, the steps to reproduce are:
Describe what you expected to happen:
Everything should be fine, no crash happens at least.
Snack, code example, screenshot, or link to a repository:
Here are some critical logs when the crash happens:
These logs reflect the whole flow of the crash happening. To help understanding, view 4905 is the view container of the list which is ReactHorizontalScrollContainerView on Android, and crash happens at the last line when adds view 5069, which already has a parent, into view 4905 at index 17.
The code run into this situation due to inconsistent view hierarchy state between ReactShadowNode and NativeViewHierarchyManager when there are pending deletion animations.
In UIImplementation, views will be added into the latest view hierarchy without any pending state calculation, but it does consider the pending state if the index of the view to be added is equal to or larger than the starting position of deleting items in NativeViewHierarchyManager.
Relevant code snippet in UIImplementation.manageChildren():
And code snippet in NativeViewHierarchyManager.manageChildren():
To help understanding, there is a picture shows the crash flow in the attached doc.
Issue of applying the patch to fix LayoutAnimation on Android.pdf
The text was updated successfully, but these errors were encountered: