Skip to content

Commit 2f58e52

Browse files
javachefacebook-github-bot
authored andcommitted
Apply Animated initialProps handling to Fabric only (#34927)
Summary: Pull Request resolved: #34927 The changes made in D36902220 (a041951) and D36958882 (d8c25ca) attempted to reduce flickering and consistency issues when using Animated. In the old renderer, we explicitly reset all animated props, and wait for the subsequent React commit to set the props to the right state, but if `initialProps` are used, the React reconciliation may not be able to identify the prop-update is required and will leave out the value. This behaviour is different in the new renderer, where we do not explicitly `restoreDefaultValues` on detaching the animated node, and instead rely on the latest state being correct(?). Changelog: [General][Fixed] Stop styles from being reset when detaching Animated.Values in old renderer Fixes #34665 Reviewed By: rshest Differential Revision: D40194072 fbshipit-source-id: 1b3fb1d1f4a39036a501a8a21e57002035dd5659
1 parent f8996f1 commit 2f58e52

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

Libraries/Animated/createAnimatedComponent.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,24 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
199199
});
200200

201201
render(): React.Node {
202+
// When rendering in Fabric and an AnimatedValue is used, we keep track of
203+
// the initial value of that Value, to avoid additional prop updates when
204+
// this component re-renders
205+
const initialPropsIfFabric = this._isFabric()
206+
? this._initialAnimatedProps
207+
: null;
208+
202209
const animatedProps =
203-
this._propsAnimated.__getValue(this._initialAnimatedProps) || {};
210+
this._propsAnimated.__getValue(initialPropsIfFabric) || {};
211+
if (!this._initialAnimatedProps) {
212+
this._initialAnimatedProps = animatedProps;
213+
}
214+
204215
const {style = {}, ...props} = animatedProps;
205216
const {style: passthruStyle = {}, ...passthruProps} =
206217
this.props.passthroughAnimatedPropExplicitValues || {};
207218
const mergedStyle = {...style, ...passthruStyle};
208219

209-
if (!this._initialAnimatedProps) {
210-
this._initialAnimatedProps = animatedProps;
211-
}
212-
213220
// Force `collapsable` to be false so that native view is not flattened.
214221
// Flattened views cannot be accurately referenced by a native driver.
215222
return (

Libraries/Animated/nodes/AnimatedProps.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ export default class AnimatedProps extends AnimatedNode {
4646
// as they may not be up to date, so we use the initial value to ensure that values of
4747
// native animated nodes do not impact rerenders.
4848
if (value instanceof AnimatedStyle) {
49-
props[key] = value.__getValue(
50-
initialProps ? initialProps.style : null,
51-
);
49+
props[key] = value.__getValue(initialProps?.style);
5250
} else if (!initialProps || !value.__isNative) {
5351
props[key] = value.__getValue();
5452
} else if (initialProps.hasOwnProperty(key)) {

ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ public void disconnectAnimatedNodeFromView(
871871
if (ANIMATED_MODULE_DEBUG) {
872872
FLog.d(
873873
NAME,
874-
"queue: disconnectAnimatedNodeFromView: " + animatedNodeTag + " viewTag: " + viewTag);
874+
"queue disconnectAnimatedNodeFromView: " + animatedNodeTag + " viewTag: " + viewTag);
875875
}
876876

877877
decrementInFlightAnimationsForViewTag(viewTag);
@@ -883,7 +883,7 @@ public void execute(NativeAnimatedNodesManager animatedNodesManager) {
883883
if (ANIMATED_MODULE_DEBUG) {
884884
FLog.d(
885885
NAME,
886-
"execute: disconnectAnimatedNodeFromView: "
886+
"execute disconnectAnimatedNodeFromView: "
887887
+ animatedNodeTag
888888
+ " viewTag: "
889889
+ viewTag);
@@ -897,19 +897,15 @@ public void execute(NativeAnimatedNodesManager animatedNodesManager) {
897897
public void restoreDefaultValues(final double animatedNodeTagDouble) {
898898
final int animatedNodeTag = (int) animatedNodeTagDouble;
899899
if (ANIMATED_MODULE_DEBUG) {
900-
FLog.d(
901-
NAME, "queue restoreDefaultValues: disconnectAnimatedNodeFromView: " + animatedNodeTag);
900+
FLog.d(NAME, "queue restoreDefaultValues: " + animatedNodeTag);
902901
}
903902

904903
addPreOperation(
905904
new UIThreadOperation() {
906905
@Override
907906
public void execute(NativeAnimatedNodesManager animatedNodesManager) {
908907
if (ANIMATED_MODULE_DEBUG) {
909-
FLog.d(
910-
NAME,
911-
"execute restoreDefaultValues: disconnectAnimatedNodeFromView: "
912-
+ animatedNodeTag);
908+
FLog.d(NAME, "execute restoreDefaultValues: " + animatedNodeTag);
913909
}
914910
animatedNodesManager.restoreDefaultValues(animatedNodeTag);
915911
}

0 commit comments

Comments
 (0)