Open elliottkember opened 8 months ago
Hi @elliottkember, thank you for the repro! It seems that this is the same issue we are experiencing after upgrading from react native 0.71.x.
To verify that the issue was introduced in 0.72, I created a fresh react native project with v0.71.19 and added your App.js code here. The animation value is still updated correctly after pressing the remount button.
I then upgraded the repo to react native 0.72.0 (see here) and ran the test again, which resulted in the same issue you are describing above.
Description
If an animated value is attached to an animated view as a transform, and the view is unmounted, all listeners on the animated value are removed and cease to fire. The animation continues to be active, and new listeners can be added, but the original listeners are all removed. This does not happen in react-native-web, and expo snack cannot replicate the problem.
Steps to reproduce
Remount animation
button to unmount, and re-mount the animation (changingkey
)The animated value listener attached to the animated value has stopped listening now, and won't fire any more.
Findings
In
Libraries/Animated/useAnimatedProps.js#167
:This line seems to be detaching the animated props node, which calls
removeAllListeners
on the AnimatedNode and kills the listener. However, an animated value can have a lifespan longer than any component that uses it and may have other listeners that are doing important things, so I think this is a bug – especially because it doesn't happen in react-native-web.I suspect the fix may involve tracking which listeners are added specifically by the node and removing those specifically (instead of calling
removeAllListeners
). I don't know what level of effort is involved here but I would be more than happy to help test or prototype a fix for this.React Native Version
0.73.6
Affected Platforms
Runtime - Android, Runtime - iOS
Output of
npx react-native info
Reproducer
https://github.com/elliottkember/animation-listener-bug
Screenshots and Videos
In this video, the
Remount animation
button simply changes the key on the Animated.View element that keeps changing size.https://github.com/facebook/react-native/assets/42827/eab17e92-edd1-404a-963a-0a003d14c1ef