Commit 721b1cf
Drive shared animation backend from Fabric frame callback (#57400)
Summary:
Pull Request resolved: #57400
In this diff we drop the custom choreographer for the backend on Android and instead plug into the one in `FabricUIManager`. This reduces the area for possible mistakes, makes it clearer how Fabric interacts with animation on a per-frame basis, and simplifies the flow around invalidation and cleanup of the React instance.
The crash this is meant to avoid comes from having two separate frame callback lifecycles. The old `AnimationBackendChoreographer` owned a self-reposting callback that could keep driving `FabricUIManagerBinding.driveAnimationBackend` independently from Fabric's own lifecycle. During React instance teardown, `FabricUIManager.invalidate()` pauses Fabric's frame callback and then unregisters the native binding. If a separate backend callback survives that sequence, it can invoke the binding after the native side has been uninstalled.
The shared animation backend is now driven from Fabric's existing `DISPATCH_UI` frame callback after mount items are dispatched. The Android `AnimationChoreographer` implementation only owns backend pause/resume state and conditionally forwards active frames to the shared backend.
Threading-wise:
- If invalidation happens before a frame starts, `mDestroyed` makes the frame no-op.
- If invalidation races with an already-running frame, `ReactChoreographer.removeFrameCallback` is serialized with callback execution via the `callbackQueues` monitor, so `onHostPause()` waits for the current `DISPATCH_UI` callback to finish before `unregister()` tears down the native binding.
- If the frame reposts itself in `schedule()`, the blocked removal observes and removes that callback before teardown continues.
Changelog:
[Android][Fixed] - Drive the shared animation backend from Fabric's frame callback during React instance teardown
Reviewed By: javache, zeyap
Differential Revision: D110321362
fbshipit-source-id: 77c462ee30aeec2d3af0dcd48b8eed15846ae5da1 parent 923e7dd commit 721b1cf
13 files changed
Lines changed: 31 additions & 213 deletions
File tree
- packages/react-native/ReactAndroid/src/main
- java/com/facebook/react
- fabric
- runtime
- jni/react/fabric
- scripts/cxx-api/api-snapshots
Lines changed: 0 additions & 87 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1628 | 1628 | | |
1629 | 1629 | | |
1630 | 1630 | | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
1631 | 1635 | | |
1632 | 1636 | | |
1633 | 1637 | | |
| |||
Lines changed: 1 addition & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | 88 | | |
93 | 89 | | |
94 | 90 | | |
| |||
97 | 93 | | |
98 | 94 | | |
99 | 95 | | |
100 | | - | |
101 | 96 | | |
102 | 97 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | 98 | | |
108 | 99 | | |
109 | 100 | | |
| |||
Lines changed: 0 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | | - | |
63 | 61 | | |
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
67 | 65 | | |
68 | 66 | | |
69 | 67 | | |
70 | | - | |
71 | 68 | | |
72 | 69 | | |
73 | 70 | | |
| |||
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | 47 | | |
49 | 48 | | |
50 | 49 | | |
| |||
259 | 258 | | |
260 | 259 | | |
261 | 260 | | |
262 | | - | |
263 | | - | |
264 | 261 | | |
265 | 262 | | |
266 | 263 | | |
267 | 264 | | |
268 | 265 | | |
269 | 266 | | |
270 | 267 | | |
271 | | - | |
272 | 268 | | |
273 | 269 | | |
274 | 270 | | |
| |||
Lines changed: 10 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | | - | |
13 | | - | |
| 11 | + | |
14 | 12 | | |
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
19 | | - | |
20 | | - | |
| 17 | + | |
21 | 18 | | |
| 19 | + | |
22 | 20 | | |
23 | 21 | | |
24 | | - | |
| 22 | + | |
25 | 23 | | |
26 | | - | |
| 24 | + | |
27 | 25 | | |
28 | 26 | | |
29 | | - | |
| 27 | + | |
30 | 28 | | |
31 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
Lines changed: 12 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
66 | 73 | | |
67 | 74 | | |
68 | 75 | | |
| |||
572 | 579 | | |
573 | 580 | | |
574 | 581 | | |
| 582 | + | |
| 583 | + | |
575 | 584 | | |
576 | 585 | | |
577 | 586 | | |
| |||
583 | 592 | | |
584 | 593 | | |
585 | 594 | | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | 595 | | |
590 | 596 | | |
591 | 597 | | |
| |||
604 | 610 | | |
605 | 611 | | |
606 | 612 | | |
| 613 | + | |
607 | 614 | | |
608 | 615 | | |
609 | 616 | | |
| |||
875 | 882 | | |
876 | 883 | | |
877 | 884 | | |
878 | | - | |
879 | | - | |
880 | | - | |
881 | 885 | | |
882 | 886 | | |
883 | 887 | | |
884 | 888 | | |
885 | 889 | | |
886 | | - | |
887 | | - | |
888 | | - | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | 890 | | |
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
172 | | - | |
173 | 171 | | |
174 | 172 | | |
175 | 173 | | |
Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 0 additions & 37 deletions
This file was deleted.
0 commit comments