Repository navigation
Commit 6a62c9e
Fix addViewAt crash when reparenting a view that is being animated out
Summary:
When a view is moved to a new parent (for example because an intermediate
view is flattened or unflattened), Fabric emits a Remove from the previous
parent followed by an Insert into the new one. If the view is being
animated out of its previous parent at that moment (it is in that parent's
transitioning views, e.g. via LayoutTransition or startViewTransition),
ViewGroup removes it from its children but keeps its parent pointer until
the transition ends.
addViewAt already detects that the view still has a parent and calls
removeView() on it, but removeView() looks the view up in the children
array, finds nothing, and silently returns. The following addView() then
throws "The specified child already has a parent", which is rethrown as
"addViewAt: failed to insert view [...]" and crashes the app.
If the view is still attached to the same parent after removeView(), end
the view transition on that parent, which clears the parent pointer, so the
view can be inserted into its new parent.
Changelog:
[Android] [Fixed] - Fix `addViewAt: failed to insert view` crash when a view is reparented while being animated out of its previous parent
Test Plan:
Added SurfaceMountingManagerTest.addViewAt_reparentsViewThatIsTransitioningOutOfPreviousParent,
which starts a view transition on the previous parent, removes the child,
and inserts it into another parent. Without this change it fails with the
same exception seen in production; with it, it passes.
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.fabric.*'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent cd500a7 commit 6a62c9e
2 files changed
Lines changed: 35 additions & 0 deletions
File tree
- packages/react-native/ReactAndroid/src
- main/java/com/facebook/react/fabric/mounting
- test/java/com/facebook/react/fabric
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
364 | 370 | | |
365 | 371 | | |
366 | 372 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
195 | 224 | | |
0 commit comments