Commit 45de710
Fix crash in tracking spring animations when toValue node is detached (#55734)
Summary:
This PR fixes an Android Native Animated crash in tracking + spring animations when the tracked `toValue` node is detached.
In `TrackingAnimatedNode.update`, if the tracked node could not be resolved, we used to write `toValue = null` into `animationConfig`. `SpringAnimation.resetConfig` expects `toValue` to be a number, so this could crash with `NullPointerException: null cannot be cast to non-null type kotlin.Number`
This can happen in real apps during graph teardown (for example unmount/re-render/navigation transitions), where tracking may still update for a transient frame after the tracked node has been detached.
Fix:
- Do not propagate null `toValue` from `TrackingAnimatedNode`.
- If the tracked node is missing, fallback to the driven value node’s current value.
- If both nodes are unavailable, return safely.
This PR also adds a regression test.
## Changelog:
[ANDROID] [FIXED] - Prevent Native Animated tracking spring crash when tracked `toValue` node is detached.
Pull Request resolved: #55734
Test Plan:
Added regression test `NativeAnimatedNodeTraversalTest.testTrackingSpringDoesNotCrashWhenToValueNodeIsDetached`
- On a test-only commit (without the fix), the new test fails with: `NullPointerException: null cannot be cast to non-null type kotlin.Number`
- On this PR (with the fix), test pass.
Reviewed By: christophpurrer
Differential Revision: D94697059
Pulled By: zeyap
fbshipit-source-id: c8f1f619c34ce7887d6f9bfb42a035d41d6a063a1 parent ee5b089 commit 45de710
File tree
2 files changed
+43
-1
lines changed- packages/react-native/ReactAndroid/src
- main/java/com/facebook/react/animated
- test/java/com/facebook/react/animated
2 files changed
+43
-1
lines changedLines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| |||
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1370 | 1370 | | |
1371 | 1371 | | |
1372 | 1372 | | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
1373 | 1411 | | |
1374 | 1412 | | |
1375 | 1413 | | |
| |||
0 commit comments