Skip to content
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

Make sure style does not regenerate between renders if it is the same. #3126

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/createAnimatedComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export default function createAnimatedComponent(
_isFirstRender = true;
animatedStyle: { value: StyleProps } = { value: {} };
initialStyle = {};
_lastSentStyle: StyleProps = {};
sv: SharedValue<null | Record<string, unknown>> | null;
_propsAnimated?: PropsAnimated;
_component: ComponentRef | null = null;
Expand Down Expand Up @@ -580,16 +581,33 @@ export default function createAnimatedComponent(

_filterNonAnimatedStyle(inputStyle: StyleProps) {
const style: StyleProps = {};
let changed = false;
for (const key in inputStyle) {
const value = inputStyle[key];
if (!hasAnimatedNodes(value)) {
style[key] = value;
changed = changed || style[key] !== this._lastSentStyle[key];
} else if (value instanceof AnimatedValue) {
// if any style in animated component is set directly to the `Value` we set those styles to the first value of `Value` node in order
// to avoid flash of default styles when `Value` is being asynchrounously sent via bridge and initialized in the native side.
style[key] = value._startingValue;
changed = changed || style[key] !== this._lastSentStyle[key];
}
}
if (!changed) {
const inputKeys = new Set(Object.keys(inputStyle));
let equalKeys = true;
for (const key in this._lastSentStyle) {
if (!inputKeys.has(key)) {
equalKeys = false;
break;
}
}
if (equalKeys) {
return this._lastSentStyle;
}
}
this._lastSentStyle = style;
return style;
}

Expand Down