Skip to content

Commit fe8f0fb

Browse files
javachekelset
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 # Conflicts: # Libraries/Animated/createAnimatedComponent.js
1 parent 37790e4 commit fe8f0fb

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

Libraries/Animated/createAnimatedComponent.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,25 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
200200
},
201201
});
202202

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

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

Libraries/Animated/nodes/AnimatedProps.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ 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)