Skip to content

Commit a6b7e18

Browse files
rozelefacebook-github-bot
authored andcommitted
Re-use Animation _nativeIds (#45109)
Summary: Pull Request resolved: #45109 Re-using _nativeIds should be perfectly safe. Tracking animations already re-use animation IDs when the value being tracked is updated. This change is in preparation for an exploratory API for triggering Animated actions on events (e.g., starting an animation on hover). Differential Revision: D58770465
1 parent f7fe688 commit a6b7e18

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

packages/react-native/Libraries/Animated/animations/Animation.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {PlatformConfig} from '../AnimatedPlatformConfig';
1414
import type AnimatedNode from '../nodes/AnimatedNode';
1515
import type AnimatedValue from '../nodes/AnimatedValue';
1616

17+
import * as ReactNativeFeatureFlags from '../../../src/private/featureflags/ReactNativeFeatureFlags';
1718
import NativeAnimatedHelper from '../NativeAnimatedHelper';
1819
import AnimatedProps from '../nodes/AnimatedProps';
1920

@@ -92,7 +93,12 @@ export default class Animation {
9293
try {
9394
const config = this.__getNativeAnimationConfig();
9495
animatedValue.__makeNative(config.platformConfig);
95-
this._nativeId = NativeAnimatedHelper.generateNewAnimationId();
96+
if (
97+
!this._nativeId ||
98+
!ReactNativeFeatureFlags.animatedShouldUsePermanentAnimationId()
99+
) {
100+
this._nativeId = NativeAnimatedHelper.generateNewAnimationId();
101+
}
96102
NativeAnimatedHelper.API.startAnimatingNode(
97103
this._nativeId,
98104
animatedValue.__getNativeTag(),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ const definitions: FeatureFlagDefinitions = {
167167
description:
168168
'Enables an experimental flush-queue debouncing in Animated.js.',
169169
},
170+
animatedShouldUsePermanentAnimationId: {
171+
defaultValue: false,
172+
description:
173+
'Enables an experimental option to reuse the native ID for an animation.',
174+
},
170175
animatedShouldUseSingleOp: {
171176
defaultValue: false,
172177
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<<522f11a571457cb932f451cf81bd384a>>
7+
* @generated SignedSource<<3ff3985c50d0b1abc5116a657e148938>>
88
* @flow strict-local
99
*/
1010

@@ -28,6 +28,7 @@ import {
2828
export type ReactNativeFeatureFlagsJsOnly = {
2929
jsOnlyTestFlag: Getter<boolean>,
3030
animatedShouldDebounceQueueFlush: Getter<boolean>,
31+
animatedShouldUsePermanentAnimationId: Getter<boolean>,
3132
animatedShouldUseSingleOp: Getter<boolean>,
3233
enableAccessToHostTreeInFabric: Getter<boolean>,
3334
isLayoutAnimationEnabled: Getter<boolean>,
@@ -78,6 +79,11 @@ export const jsOnlyTestFlag: Getter<boolean> = createJavaScriptFlagGetter('jsOnl
7879
*/
7980
export const animatedShouldDebounceQueueFlush: Getter<boolean> = createJavaScriptFlagGetter('animatedShouldDebounceQueueFlush', false);
8081

82+
/**
83+
* Enables an experimental option to reuse the native ID for an animation.
84+
*/
85+
export const animatedShouldUsePermanentAnimationId: Getter<boolean> = createJavaScriptFlagGetter('animatedShouldUsePermanentAnimationId', false);
86+
8187
/**
8288
* Enables an experimental mega-operation for Animated.js that replaces many calls to native with a single call into native, to reduce JSI/JNI traffic.
8389
*/

0 commit comments

Comments
 (0)