Share the same Animated.Value amongst transitions that happen in the same commit#326
Merged
Merged
Conversation
…same commit Right now, updating state which affects transitioning properties accross multiple components results in each component creating its own Animated.Value and starting the animation in an effect. This results in animations that are not in sync as they should be. In this PR, transitions with the same delay, duration, timing function share the same Animated.Value as long as they're part of the same commit. useLayoutEffect is used to either create the Animated.Value or find an existing suitable one to use. Since all layout effects run before effects, we can assume that by the time any component's effect runs, all Animated.Values have been created or shared. One of the component's effects will then kick off the animation and empty the shared animation config map so that future commits don't reuse any of the Animated.Values that were created. The other component's effects will be no-ops. Finally, reference counting is used to ensure only the last component that unmounts would stop the animation if it was still running since now they are shared it would be disruptive to stop the animation unless the component was the last one relying on it
workflow: benchmarks/sizeComparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.
|
workflow: benchmarks/perf (native)Comparison of performance test results, measured in operations per second. Larger is better.
|
necolas
approved these changes
Jul 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Right now, updating state which affects transitioning properties accross multiple components results in each component creating its own Animated.Value and starting the animation in an effect.
This results in animations that are not in sync as they should be.
In this PR, transitions with the same delay, duration, timing function share the same Animated.Value as long as they're part of the same commit.
useLayoutEffect is used to either create the Animated.Value or find an existing suitable one to use.
Since all layout effects run before effects, we can assume that by the time any component's effect runs, all Animated.Values have been created or shared.
One of the component's effects will then kick off the animation and empty the shared animation config map so that future commits don't reuse any of the Animated.Values that were created. The other component's effects will be no-ops.
Finally, reference counting is used to ensure only the last component that unmounts would stop the animation if it was still running since now they are shared it would be disruptive to stop the animation unless the component was the last one relying on it