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

Apply Animated initialProps handling to Fabric only #34927

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions Libraries/Animated/createAnimatedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,24 @@ 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(this._initialAnimatedProps) || {};
this._propsAnimated.__getValue(initialPropsIfFabric) || {};
if (!this._initialAnimatedProps) {
this._initialAnimatedProps = animatedProps;
}

const {style = {}, ...props} = animatedProps;
const {style: passthruStyle = {}, ...passthruProps} =
this.props.passthroughAnimatedPropExplicitValues || {};
const mergedStyle = {...style, ...passthruStyle};

if (!this._initialAnimatedProps) {
this._initialAnimatedProps = animatedProps;
}

// Force `collapsable` to be false so that native view is not flattened.
// Flattened views cannot be accurately referenced by a native driver.
return (
Expand Down
4 changes: 1 addition & 3 deletions Libraries/Animated/nodes/AnimatedProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export default class AnimatedProps extends AnimatedNode {
// 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 ? initialProps.style : null,
);
props[key] = value.__getValue(initialProps?.style);
} else if (!initialProps || !value.__isNative) {
props[key] = value.__getValue();
} else if (initialProps.hasOwnProperty(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ public void disconnectAnimatedNodeFromView(
if (ANIMATED_MODULE_DEBUG) {
FLog.d(
NAME,
"queue: disconnectAnimatedNodeFromView: " + animatedNodeTag + " viewTag: " + viewTag);
"queue disconnectAnimatedNodeFromView: " + animatedNodeTag + " viewTag: " + viewTag);
}

decrementInFlightAnimationsForViewTag(viewTag);
Expand All @@ -883,7 +883,7 @@ public void execute(NativeAnimatedNodesManager animatedNodesManager) {
if (ANIMATED_MODULE_DEBUG) {
FLog.d(
NAME,
"execute: disconnectAnimatedNodeFromView: "
"execute disconnectAnimatedNodeFromView: "
+ animatedNodeTag
+ " viewTag: "
+ viewTag);
Expand All @@ -897,19 +897,15 @@ public void execute(NativeAnimatedNodesManager animatedNodesManager) {
public void restoreDefaultValues(final double animatedNodeTagDouble) {
final int animatedNodeTag = (int) animatedNodeTagDouble;
if (ANIMATED_MODULE_DEBUG) {
FLog.d(
NAME, "queue restoreDefaultValues: disconnectAnimatedNodeFromView: " + animatedNodeTag);
FLog.d(NAME, "queue restoreDefaultValues: " + animatedNodeTag);
}

addPreOperation(
new UIThreadOperation() {
@Override
public void execute(NativeAnimatedNodesManager animatedNodesManager) {
if (ANIMATED_MODULE_DEBUG) {
FLog.d(
NAME,
"execute restoreDefaultValues: disconnectAnimatedNodeFromView: "
+ animatedNodeTag);
FLog.d(NAME, "execute restoreDefaultValues: " + animatedNodeTag);
}
animatedNodesManager.restoreDefaultValues(animatedNodeTag);
}
Expand Down