-
Notifications
You must be signed in to change notification settings - Fork 12
Fix Animation lag in JSON animation #11
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe changes introduce an optional Changes
Sequence Diagram(s)sequenceDiagram
participant ReactComponent
participant BaseAnimationWrapper
participant JsonAnimationWrapper
ReactComponent->>BaseAnimationWrapper: shouldComponentUpdate(nextProps)
alt animationConfig changed
BaseAnimationWrapper->>JsonAnimationWrapper: updateCompositeAnimation(nextProps)
JsonAnimationWrapper->>JsonAnimationWrapper: Use nextProps or this.props for updates
end
BaseAnimationWrapper-->>ReactComponent: return shouldUpdate
Poem
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/core/components/wrapper/BaseAnimationWrapper.tsx(1 hunks)src/core/components/wrapper/JsonAnimationWrapper.tsx(1 hunks)
🔇 Additional comments (2)
src/core/components/wrapper/BaseAnimationWrapper.tsx (2)
10-10: Good API enhancement for animation optimizationThe abstract method signature has been updated to accept optional next props, which will allow for animation preparation based on upcoming props rather than current ones.
15-19: Effective optimization for reducing animation lagThis change preemptively updates the animation when props change, rather than waiting for the component to re-render. By moving the animation update to the
shouldComponentUpdatephase, the animation system can prepare for the upcoming state, reducing perceived lag.While side effects in
shouldComponentUpdateare generally discouraged, this is a reasonable exception for performance optimization in animation systems.
| protected updateCompositeAnimation(newProps?: JsonAnimationProps): void { | ||
| this._updateAnimatedArray(newProps ?? this.props); | ||
| this._updateCompositeAnimation(newProps ?? this.props); | ||
| this._updateTransformsArray(newProps ?? this.props); | ||
| } |
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.
💡 Verification agent
🧩 Analysis chain
Good implementation of animation optimization
The method now accepts an optional newProps parameter and uses the nullish coalescing operator to fall back to current props when needed. This implementation properly supports the optimization introduced in the base class and ensures that animations can be prepared with upcoming props.
One minor recommendation - consider enabling the native driver for better performance:
- useNativeDriver: false
+ useNativeDriver: trueHowever, only do this if all animated properties are compatible with the native driver (opacity and transform properties). Style properties like width, height, etc. aren't compatible with the native driver.
To verify which properties in your animations might not be compatible with the native driver:
🏁 Script executed:
#!/bin/bash
# Find all animation properties that might not be compatible with native driver
grep -n "case \"" src/core/components/wrapper/JsonAnimationWrapper.tsx | grep -v "translate\|rotate\|scale\|opacity" | sortLength of output: 245
Updated Recommendation: Verify Animated Properties for Native Driver Compatibility
The refactored implementation using an optional newProps parameter and fallback to current props is well done. However, our recent verification shows that the component animates properties such as "skewX", "skewY", "width", and "height"—which are not compatible with the native driver.
- If you plan to enable the native driver (i.e., using
useNativeDriver: true), please first ensure that all animated properties are natively supported (typically only opacity and transform properties are safe). - Otherwise, continue using
useNativeDriver: falseor consider refactoring the component to animate only the supported properties.
Committable suggestion skipped: line range outside the PR's diff.
|
👀 |
|
@swapnil1104 Can you please review this |
Before
Converted.Video.mp4
After
Converted.Video.1.mp4
Summary by CodeRabbit