Commit a6cb112
authored
Update AnimatedColor-test.js
## Summary:
Fixed an issue in `AnimatedColor.js` where `_listenerCount` could become negative during component unmount, leading to native subscription memory leaks.
When `AnimatedColor.__detach()` is called, it invokes `removeAllListeners()` on its channel nodes (r, g, b, a), resetting their `_listenerCount` to 0. If infrastructure cleanup then calls `removeListener(id)` on those same nodes, the count drops to -1, permanently bypassing the cleanup condition `if (this._listenerCount === 0)` — so `this._updateSubscription?.remove()` never fires.
Fix: Added a `_listeners` map to `AnimatedColor` with overrides for `addListener`, `removeListener`, and `removeAllListeners`. `removeListener` now returns early if the id is not found (already cleaned up by `__detach`), mirroring the pattern used by `AnimatedValueXY`.
## Changelog:
[GENERAL] [FIXED] - Prevent negative listener count in AnimatedColor causing native subscription memory leaks after `__detach()`
## Test Plan:
Added regression tests in `Libraries/Animated/tests/AnimatedColor-test.js`:
- `_listenerCount` does not go negative after `__detach()` + `removeListener()`
- `removeListener` after `removeAllListeners` is a safe no-op
- Native subscription starts correctly for all 4 channels (r/g/b/a)
- Native subscription cleans up correctly when count reaches 0
- No native subscription leak after re-attach cycle1 parent 4b8e904 commit a6cb112
0 file changed
0 commit comments