Skip to content

Commit

Permalink
Remove initialProps handling for legacy createAnimatedComponent
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal] Remove additional Animated logic under Fabric that's no longer required

Reviewed By: jehartzog

Differential Revision: D40513977

fbshipit-source-id: 1e96366377ca4c3bf032d830b5641ab658462ce8
  • Loading branch information
javache authored and facebook-github-bot committed Oct 24, 2022
1 parent 880e889 commit 9a87db2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 41 deletions.
14 changes: 1 addition & 13 deletions Libraries/Animated/createAnimatedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
_prevComponent: any;
_propsAnimated: AnimatedProps;
_eventDetachers: Array<Function> = [];
_initialAnimatedProps: Object;

// Only to be used in this file, and only in Fabric.
_animatedComponentId: string = `${animatedComponentNextId++}:animatedComponent`;
Expand Down Expand Up @@ -199,18 +198,7 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
});

render(): React.Node {
// When rendering in Fabric and an AnimatedValue is used, we keep track of
// the initial value of that Value, to avoid additional prop updates when
// this component re-renders
const initialPropsIfFabric = this._isFabric()
? this._initialAnimatedProps
: null;

const animatedProps =
this._propsAnimated.__getValue(initialPropsIfFabric) || {};
if (!this._initialAnimatedProps) {
this._initialAnimatedProps = animatedProps;
}
const animatedProps = this._propsAnimated.__getValue() || {};

const {style = {}, ...props} = animatedProps;
const {style: passthruStyle = {}, ...passthruProps} =
Expand Down
14 changes: 2 additions & 12 deletions Libraries/Animated/nodes/AnimatedProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,12 @@ export default class AnimatedProps extends AnimatedNode {
this._callback = callback;
}

__getValue(initialProps: ?Object): Object {
__getValue(): Object {
const props: {[string]: any | ((...args: any) => void)} = {};
for (const key in this._props) {
const value = this._props[key];
if (value instanceof AnimatedNode) {
// During initial render we want to use the initial value of both natively and non-natively
// driven nodes. On subsequent renders, we cannot use the value of natively driven nodes
// as they may not be up to date, so we use the initial value to ensure that values of
// native animated nodes do not impact rerenders.
if (value instanceof AnimatedStyle) {
props[key] = value.__getValue(initialProps?.style);
} else if (!initialProps || !value.__isNative) {
props[key] = value.__getValue();
} else if (initialProps.hasOwnProperty(key)) {
props[key] = initialProps[key];
}
props[key] = value.__getValue();
} else if (value instanceof AnimatedEvent) {
props[key] = value.__getHandler();
} else {
Expand Down
21 changes: 5 additions & 16 deletions Libraries/Animated/nodes/AnimatedStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,24 @@ export default class AnimatedStyle extends AnimatedWithChildren {
}

// Recursively get values for nested styles (like iOS's shadowOffset)
_walkStyleAndGetValues(
style: any,
initialStyle: ?Object,
): {[string]: any | {...}} {
_walkStyleAndGetValues(style: any): {[string]: any | {...}} {
const updatedStyle: {[string]: any | {...}} = {};
for (const key in style) {
const value = style[key];
if (value instanceof AnimatedNode) {
// During initial render we want to use the initial value of both natively and non-natively
// driven nodes. On subsequent renders, we cannot use the value of natively driven nodes
// as they may not be up to date, so we use the initial value to ensure that values of
// native animated nodes do not impact rerenders.
if (!initialStyle || !value.__isNative) {
updatedStyle[key] = value.__getValue();
} else if (initialStyle.hasOwnProperty(key)) {
updatedStyle[key] = initialStyle[key];
}
updatedStyle[key] = value.__getValue();
} else if (value && !Array.isArray(value) && typeof value === 'object') {
// Support animating nested values (for example: shadowOffset.height)
updatedStyle[key] = this._walkStyleAndGetValues(value, initialStyle);
updatedStyle[key] = this._walkStyleAndGetValues(value);
} else {
updatedStyle[key] = value;
}
}
return updatedStyle;
}

__getValue(initialStyle: ?Object): Object {
return this._walkStyleAndGetValues(this._style, initialStyle);
__getValue(): Object {
return this._walkStyleAndGetValues(this._style);
}

// Recursively get animated values for nested styles (like iOS's shadowOffset)
Expand Down

0 comments on commit 9a87db2

Please sign in to comment.