Skip to content

Commit d9d9a49

Browse files
zeyapfacebook-github-bot
authored andcommitted
allow calling createAnimatedNode without batching (#53476)
Summary: Pull Request resolved: #53476 ## Changelog: [General] [Added] - allow calling createAnimatedNode without batching Enable setting `nativeCreateUnbatched` config on an AnimatedNode, when it's true, the call to Animated nativeModule's createAnimatedNode will skip signal batching (will call over JSI before React rendering is finished) and batching in c++, and the creation will be executed at next UI thread render. This will only make AnimatedNodes creation happen early, but node/view connections, node deletion or event drivers will still be batched like before Reviewed By: yungsters Differential Revision: D80968512 fbshipit-source-id: afb607410a174fb85107ef270b9d6f3d61617daf
1 parent 79a8354 commit d9d9a49

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type ValueListenerCallback = (state: {value: number, ...}) => mixed;
1717

1818
export type AnimatedNodeConfig = $ReadOnly<{
1919
debugID?: string,
20+
unstable_disableBatchingForNativeCreate?: boolean,
2021
}>;
2122

2223
let _uniqueId = 1;
@@ -42,6 +43,8 @@ export default class AnimatedNode {
4243
if (__DEV__) {
4344
this.__debugID = config?.debugID;
4445
}
46+
this.__disableBatchingForNativeCreate =
47+
config?.unstable_disableBatchingForNativeCreate;
4548
}
4649

4750
__attach(): void {}
@@ -65,6 +68,7 @@ export default class AnimatedNode {
6568
/* Methods and props used by native Animated impl */
6669
__isNative: boolean = false;
6770
__nativeTag: ?number = undefined;
71+
__disableBatchingForNativeCreate: ?boolean = undefined;
6872

6973
__makeNative(platformConfig: ?PlatformConfig): void {
7074
// Subclasses are expected to set `__isNative` to true before this.
@@ -142,6 +146,9 @@ export default class AnimatedNode {
142146
if (this._platformConfig) {
143147
config.platformConfig = this._platformConfig;
144148
}
149+
if (this.__disableBatchingForNativeCreate) {
150+
config.disableBatchingForNativeCreate = true;
151+
}
145152
NativeAnimatedHelper.API.createAnimatedNode(nativeTag, config);
146153
}
147154
return nativeTag;

packages/react-native/ReactCommon/react/renderer/animated/AnimatedModule.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@ void AnimatedModule::createAnimatedNode(
4848
Tag tag,
4949
jsi::Object config) {
5050
auto configDynamic = dynamicFromValue(rt, jsi::Value(rt, config));
51-
operations_.emplace_back(
52-
CreateAnimatedNodeOp{.tag = tag, .config = std::move(configDynamic)});
51+
if (auto it = configDynamic.find("disableBatchingForNativeCreate");
52+
it != configDynamic.items().end() && it->second == true) {
53+
if (nodesManager_) {
54+
nodesManager_->createAnimatedNode(tag, configDynamic);
55+
}
56+
} else {
57+
operations_.emplace_back(
58+
CreateAnimatedNodeOp{.tag = tag, .config = std::move(configDynamic)});
59+
}
5360
}
5461

5562
void AnimatedModule::updateAnimatedNodeConfig(

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ const API = {
241241
}) as () => void,
242242

243243
createAnimatedNode(tag: number, config: AnimatedNodeConfig): void {
244-
NativeOperations.createAnimatedNode(tag, config);
244+
if (config.disableBatchingForNativeCreate) {
245+
NativeAnimatedModule?.createAnimatedNode(tag, config);
246+
} else {
247+
NativeOperations.createAnimatedNode(tag, config);
248+
}
245249
},
246250

247251
updateAnimatedNodeConfig(tag: number, config: AnimatedNodeConfig): void {

0 commit comments

Comments
 (0)