-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Detach old animated styles and props #2600
Detach old animated styles and props #2600
Conversation
src/createAnimatedComponent.tsx
Outdated
@@ -412,32 +422,51 @@ export default function createAnimatedComponent( | |||
// update UI props whitelist for this view | |||
if ( | |||
hostInstance && | |||
this._hasReanimated2Props(styles) && | |||
(this.props.animatedProps?.viewDescriptors || styles.length) && |
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.
I'd extract this to a variable defined before the if statement to make it clear what this part of the condition means:
const hasReanimated2Props = this.props.animatedProps?.viewDescriptors || styles.length;
if (hasReanimated2Props && hostInstance?.viewConfig) {
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.
Done in f6b8560
src/createAnimatedComponent.tsx
Outdated
const hasOneSameStyle = | ||
styles.length === 1 && | ||
prevStyles.length === 1 && | ||
styles[0] === prevStyles[0]; // optimization |
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.
document that in most of the cases views have only a single animated style and it remains unchanged (it is what useAnimatedStyle returns)
Also it'd be worth checking if we can actually use equality checks to compare useAnimatedStyle outputs
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.
Also it'd be worth checking if we can actually use equality checks to compare useAnimatedStyle outputs
Indeed, equality check didn't work as expected. Fixed in 21f456f. For now, comparing style.viewsRef
should be enough, as this prop is assigned only once (so the reference is the same). In the future, we may introduce some auto-incremented ID field to useAnimatedStyle
output.
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.
🚀
It looks like this PR has introduced performance issues, especially noticeable on older iPhones when animating a lot of values (e.g. in a Graph). |
@mrousavy Thanks for letting us know. It seems like |
Yes, I'm investigating it! How do you guys profile performance in REA? systrace isn't very helpful on Android. Do you use the Xcode instruments on iOS? |
I can definitely feel a regression in performance after upgrading from beta 3 to beta 4, not sure if this PR is the cause of that. @tomekzaw What's your discord #? I can send you the file in DM. |
@mrousavy I don't think we have any particular setup for profiling. We use Reanimated heavily in numerous apps that we develop here at Software Mansion so we constantly keep an eye on its performance in real-world production apps. Other than that, there are some heavy-duty examples (see https://twitter.com/kzzzf/status/1421104290085576710).
Can you please undo the changes from this PR locally and check if you can still feel the regression? |
Description
This pull request fixes a bug appearing when using animated styles (or props) conditionally. The root cause is that animated styles (or props) are not properly detached.
animated_styles_before.mp4
animated_styles_after.mp4
animated_props_before.mp4
animated_props_after.mp4
Changes
Test code and steps to reproduce
AnimatedStylesExample.tsx
AnimatedPropsExample.tsx
Checklist