Skip to content

Commit 33cbef5

Browse files
zeyapfacebook-github-bot
authored andcommitted
Guard forced-native animations from JS updates
Summary: Prevent animation nodes from entering the JS update path when native driving is forced. If the invariant is violated, emit a one-time warning and stop before JS-driven reconciliation. Changelog: [Internal] Reviewed By: rubennorte Differential Revision: D112822632
1 parent 5070236 commit 33cbef5

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

packages/react-native/src/private/animated/createAnimatedPropsHook.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import AnimatedValue from '../../../Libraries/Animated/nodes/AnimatedValue';
1717
import {isPublicInstance as isFabricPublicInstance} from '../../../Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstanceUtils';
1818
import {RootTagContext} from '../../../Libraries/ReactNative/RootTag';
1919
import useRefEffect from '../../../Libraries/Utilities/useRefEffect';
20+
import warnOnce from '../../../Libraries/Utilities/warnOnce';
2021
import * as ReactNativeFeatureFlags from '../featureflags/ReactNativeFeatureFlags';
2122
import {createAnimatedPropsMemoHook} from './createAnimatedPropsMemoHook';
2223
import NativeAnimatedHelper from './NativeAnimatedHelper';
@@ -52,9 +53,6 @@ export default function createAnimatedPropsHook(
5253
): AnimatedPropsHook {
5354
const useAnimatedPropsMemo = createAnimatedPropsMemoHook(allowlist);
5455

55-
const useNativePropsInFabric =
56-
ReactNativeFeatureFlags.shouldUseSetNativePropsInFabric();
57-
5856
return function useAnimatedProps<TProps extends {...}, TInstance>(
5957
props: TProps,
6058
): [ReducedProps<TProps>, CallbackRef<TInstance | null>] {
@@ -145,6 +143,17 @@ export default function createAnimatedPropsHook(
145143
return;
146144
}
147145

146+
// TODO: T274006331 - Remove js-only animation once shared backend is fully rolled out
147+
const isNativeDriverForced =
148+
NativeAnimatedHelper.isNativeDriverForced();
149+
if (isNativeDriverForced) {
150+
warnOnce(
151+
'animated-force-native-driver-js-update',
152+
'Animated: Expected the animation node to use the native driver when the native driver is forced.',
153+
);
154+
return;
155+
}
156+
148157
if (
149158
typeof instance !== 'object' ||
150159
typeof instance?.setNativeProps !== 'function'
@@ -160,6 +169,8 @@ export default function createAnimatedPropsHook(
160169
return instance.setNativeProps(node.__getAnimatedValue());
161170
}
162171

172+
const useNativePropsInFabric =
173+
ReactNativeFeatureFlags.shouldUseSetNativePropsInFabric();
163174
if (!useNativePropsInFabric) {
164175
// Check 5: setNativeProps are disabled.
165176
return scheduleUpdate();

0 commit comments

Comments
 (0)