Skip to content

Commit 2eb7bcb

Browse files
dmytrorykunfacebook-github-bot
authored andcommitted
Prepare to using setNativeProps for Fabric native animations (facebook#45387)
Summary: Pull Request resolved: facebook#45387 This diff prepares an experiment to test `setNativeProps` for syncing the final state of native driven animations with Fabric. Changelog: [Internal] Reviewed By: javache Differential Revision: D59634489 fbshipit-source-id: 453c5a2f0edfea695f7564e0c5ead58db21cf61e
1 parent 65a3259 commit 2eb7bcb

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

packages/react-native/Libraries/Animated/useAnimatedProps.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export default function useAnimatedProps<TProps: {...}, TInstance>(
4949
);
5050
const useNativePropsInFabric =
5151
ReactNativeFeatureFlags.shouldUseSetNativePropsInFabric();
52+
const useSetNativePropsInNativeAnimationsInFabric =
53+
ReactNativeFeatureFlags.shouldUseSetNativePropsInNativeAnimationsInFabric();
5254
useAnimatedPropsLifecycle(node);
5355

5456
// TODO: This "effect" does three things:
@@ -87,7 +89,12 @@ export default function useAnimatedProps<TProps: {...}, TInstance>(
8789
if (isFabricNode) {
8890
// Call `scheduleUpdate` to synchronise Fiber and Shadow tree.
8991
// Must not be called in Paper.
90-
scheduleUpdate();
92+
if (useSetNativePropsInNativeAnimationsInFabric) {
93+
// $FlowFixMe[incompatible-use]
94+
instance.setNativeProps(node.__getAnimatedValue());
95+
} else {
96+
scheduleUpdate();
97+
}
9198
}
9299
return;
93100
}
@@ -157,7 +164,12 @@ export default function useAnimatedProps<TProps: {...}, TInstance>(
157164
}
158165
};
159166
},
160-
[props, node, useNativePropsInFabric],
167+
[
168+
node,
169+
useNativePropsInFabric,
170+
useSetNativePropsInNativeAnimationsInFabric,
171+
props,
172+
],
161173
);
162174
const callbackRef = useRefEffect<TInstance>(refEffect);
163175

packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ const definitions: FeatureFlagDefinitions = {
221221
defaultValue: true,
222222
description: 'Enables use of setNativeProps in JS driven animations.',
223223
},
224+
shouldUseSetNativePropsInNativeAnimationsInFabric: {
225+
defaultValue: false,
226+
description:
227+
'Enables use of setNativeProps in Native driven animations in Fabric.',
228+
},
224229
useRefsForTextInputState: {
225230
defaultValue: false,
226231
description:

packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<e309dc08faf6e94d31af64535246ff11>>
7+
* @generated SignedSource<<152472a7f8698f0f45ed2d909532d84d>>
88
* @flow strict-local
99
*/
1010

@@ -34,6 +34,7 @@ export type ReactNativeFeatureFlagsJsOnly = {
3434
shouldUseAnimatedObjectForTransform: Getter<boolean>,
3535
shouldUseRemoveClippedSubviewsAsDefaultOnIOS: Getter<boolean>,
3636
shouldUseSetNativePropsInFabric: Getter<boolean>,
37+
shouldUseSetNativePropsInNativeAnimationsInFabric: Getter<boolean>,
3738
useRefsForTextInputState: Getter<boolean>,
3839
};
3940

@@ -113,6 +114,11 @@ export const shouldUseRemoveClippedSubviewsAsDefaultOnIOS: Getter<boolean> = cre
113114
*/
114115
export const shouldUseSetNativePropsInFabric: Getter<boolean> = createJavaScriptFlagGetter('shouldUseSetNativePropsInFabric', true);
115116

117+
/**
118+
* Enables use of setNativeProps in Native driven animations in Fabric.
119+
*/
120+
export const shouldUseSetNativePropsInNativeAnimationsInFabric: Getter<boolean> = createJavaScriptFlagGetter('shouldUseSetNativePropsInNativeAnimationsInFabric', false);
121+
116122
/**
117123
* Enable a variant of TextInput that moves some state to refs to avoid unnecessary re-renders
118124
*/

0 commit comments

Comments
 (0)