-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
chore: Make CSS interpolators stateless #6993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
2429ada
to
d49b6e1
Compare
MatiPl01
commented
Feb 10, 2025
packages/react-native-reanimated/Common/cpp/reanimated/CSS/common/values/CSSColor.cpp
Show resolved
Hide resolved
MatiPl01
commented
Feb 10, 2025
packages/react-native-reanimated/Common/cpp/reanimated/CSS/core/CSSTransition.cpp
Outdated
Show resolved
Hide resolved
MatiPl01
commented
Feb 10, 2025
...ve-reanimated/Common/cpp/reanimated/CSS/interpolation/groups/ArrayPropertiesInterpolator.cpp
Outdated
Show resolved
Hide resolved
MatiPl01
commented
Feb 10, 2025
...eanimated/Common/cpp/reanimated/CSS/interpolation/transforms/TransformsStyleInterpolator.cpp
Show resolved
Hide resolved
MatiPl01
commented
Feb 10, 2025
...eanimated/Common/cpp/reanimated/CSS/interpolation/transforms/TransformsStyleInterpolator.cpp
Show resolved
Hide resolved
MatiPl01
commented
Feb 10, 2025
...eanimated/Common/cpp/reanimated/CSS/interpolation/transforms/TransformsStyleInterpolator.cpp
Show resolved
Hide resolved
de7d7eb
to
672f435
Compare
piaskowyk
approved these changes
Feb 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍 I've just left a few small comments, but nothing really important. I'm glad that these changes have significantly improved the readability of the codebase.
...e-reanimated/Common/cpp/reanimated/CSS/interpolation/groups/RecordPropertiesInterpolator.cpp
Outdated
Show resolved
Hide resolved
...e-reanimated/Common/cpp/reanimated/CSS/interpolation/groups/RecordPropertiesInterpolator.cpp
Outdated
Show resolved
Hide resolved
...ve-reanimated/Common/cpp/reanimated/CSS/interpolation/styles/TransitionStyleInterpolator.cpp
Outdated
Show resolved
Hide resolved
packages/react-native-reanimated/Common/cpp/reanimated/CSS/registry/CSSTransitionsRegistry.cpp
Outdated
Show resolved
Hide resolved
5a3f873
to
c5c593f
Compare
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.
Summary
This PR removes, probably unnecessary, premature optimizations which added code complexity to interpolators implementation. Interpolators kept state of the current keyframe and last interpolated value. They also were tightly coupled with progress providers which must have been passed in the constructor.
Even though the previous implementation worked fine, it was impossible to optimize creation of the animation (we had to create interpolators for all views separately, even if they used the same animation). This also resulted in higher memory consumption.
Instead of moving left or right on the keyframes sequence, I now use a binary search to find the current keyframe. It may have worse time complexity (
O(log(n))
instead ofO(1)
) but, in fact, may be even faster because of removed logic responsible for storing a previous value, iterating over keyframes, etc. This change shouldn't affect performance as long as somebody doesn't use thousands or keyframes in animations (which is rather impossible).How it was tested?
I just went through examples in the example app (on both, iOS and Android) to make sure that no regression was introduced in this PR.