Skip to content

Commit 87ec096

Browse files
zeyapfacebook-github-bot
authored andcommitted
Allow setting debugID on AnimatedValue and TimingAnimation (#48106)
Summary: Pull Request resolved: #48106 This could make it easier to locate and debug AnimatedValue and driver from native - so far on the native side of animated, the only way to identify an Animation driver or AnimatedNode is integer IDs and the type, which made it difficult to debug when surface gets complicated Here I only enabled it for AnimatedValue and TimingAnimation, because * TimingAnimation is most commonly used * all the animation drivers (frames, spring, decay) can only drive Value type of AnimatedNode on the native side, so it's the primitive component of AnimatedNode Changelog: [Internal] Reviewed By: yungsters Differential Revision: D66790298 fbshipit-source-id: ddd64a5728120f061aa902f25c93b1701617031b
1 parent c6f1225 commit 87ec096

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type AnimationConfig = $ReadOnly<{
2626
onComplete?: ?EndCallback,
2727
iterations?: number,
2828
isLooping?: boolean,
29+
debugID?: ?string,
2930
...
3031
}>;
3132

@@ -43,6 +44,7 @@ export default class Animation {
4344
__isInteraction: boolean;
4445
__isLooping: ?boolean;
4546
__iterations: number;
47+
__debugID: ?string;
4648

4749
constructor(config: AnimationConfig) {
4850
this.#useNativeDriver = NativeAnimatedHelper.shouldUseNativeDriver(config);
@@ -51,6 +53,9 @@ export default class Animation {
5153
this.__isInteraction = config.isInteraction ?? !this.#useNativeDriver;
5254
this.__isLooping = config.isLooping;
5355
this.__iterations = config.iterations ?? 1;
56+
if (__DEV__) {
57+
this.__debugID = config.debugID;
58+
}
5459
}
5560

5661
start(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export default class TimingAnimation extends Animation {
9999
toValue: this._toValue,
100100
iterations: this.__iterations,
101101
platformConfig: this._platformConfig,
102+
debugID: __DEV__ ? this.__debugID : undefined,
102103
};
103104
}
104105

packages/react-native/Libraries/Animated/nodes/AnimatedNode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,6 @@ export default class AnimatedNode {
197197
toJSON(): mixed {
198198
return this.__getValue();
199199
}
200+
201+
__debugID: ?string = undefined;
200202
}

packages/react-native/Libraries/Animated/nodes/AnimatedValue.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import AnimatedWithChildren from './AnimatedWithChildren';
2222

2323
export type AnimatedValueConfig = $ReadOnly<{
2424
useNativeDriver: boolean,
25+
debugID?: string,
2526
}>;
2627

2728
const NativeAnimatedAPI = NativeAnimatedHelper.API;
@@ -97,8 +98,13 @@ export default class AnimatedValue extends AnimatedWithChildren {
9798
this._startingValue = this._value = value;
9899
this._offset = 0;
99100
this._animation = null;
100-
if (config && config.useNativeDriver) {
101-
this.__makeNative();
101+
if (config) {
102+
if (config.useNativeDriver) {
103+
this.__makeNative();
104+
}
105+
if (__DEV__) {
106+
this.__debugID = config.debugID;
107+
}
102108
}
103109
}
104110

@@ -298,6 +304,7 @@ export default class AnimatedValue extends AnimatedWithChildren {
298304
type: 'value',
299305
value: this._value,
300306
offset: this._offset,
307+
debugID: __DEV__ ? this.__debugID : undefined,
301308
};
302309
}
303310
}

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,15 @@ export type AnimationConfig = $ReadOnly<{
424424
onComplete?: ?EndCallback,
425425
iterations?: number,
426426
isLooping?: boolean,
427+
debugID?: ?string,
427428
...
428429
}>;
429430
declare export default class Animation {
430431
__active: boolean;
431432
__isInteraction: boolean;
432433
__isLooping: ?boolean;
433434
__iterations: number;
435+
__debugID: ?string;
434436
constructor(config: AnimationConfig): void;
435437
start(
436438
fromValue: number,
@@ -959,6 +961,7 @@ exports[`public API should not change unintentionally Libraries/Animated/nodes/A
959961
__getPlatformConfig(): ?PlatformConfig;
960962
__setPlatformConfig(platformConfig: ?PlatformConfig): void;
961963
toJSON(): mixed;
964+
__debugID: ?string;
962965
}
963966
"
964967
`;
@@ -1107,6 +1110,7 @@ declare export default class AnimatedTransform extends AnimatedWithChildren {
11071110
exports[`public API should not change unintentionally Libraries/Animated/nodes/AnimatedValue.js 1`] = `
11081111
"export type AnimatedValueConfig = $ReadOnly<{
11091112
useNativeDriver: boolean,
1113+
debugID?: string,
11101114
}>;
11111115
declare export function flushValue(rootNode: AnimatedNode): void;
11121116
declare export default class AnimatedValue extends AnimatedWithChildren {

0 commit comments

Comments
 (0)