Skip to content

Commit 169c098

Browse files
gaearonpiaskowyk
authored andcommitted
Replace findNodeHandle with reading _componentViewTag (#6720)
## Summary Partially addresses #6719. This is better because it doesn't enter the traversal codepath inside React. The `findNodeHandle` calculation inside the `Animated.View` itself is not so bad because it's short circuited inside for native refs (at least with `View`). Whereas passing a class instance like here always triggers the slower path in React. Regardless, it's already computed so why compute again? ## Test plan I've added console logs in our app to verify whether `animatedComponent._componentViewTag === findNodeHandle(animatedComponent)` and it always turned out true in the cases I hit. Not sure if there any cases where those could be different. Co-authored-by: Krzysztof Piaskowy <[email protected]>
1 parent 0448a47 commit 169c098

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

packages/react-native-reanimated/src/createAnimatedComponent/JSPropsUpdater.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22
import { NativeEventEmitter, Platform } from 'react-native';
3-
import { findNodeHandle } from '../platformFunctions/findNodeHandle';
43
import type { NativeModule } from 'react-native';
54
import { shouldBeUseWeb } from '../PlatformChecker';
65
import type { StyleProps } from '../commonTypes';
@@ -39,7 +38,7 @@ class JSPropsUpdaterPaper implements IJSPropsUpdater {
3938
> &
4039
IAnimatedComponentInternal
4140
) {
42-
const viewTag = findNodeHandle(animatedComponent);
41+
const viewTag = animatedComponent._componentViewTag;
4342
JSPropsUpdaterPaper._tagToComponentMapping.set(viewTag, animatedComponent);
4443
if (JSPropsUpdaterPaper._tagToComponentMapping.size === 1) {
4544
const listener = (data: ListenerData) => {
@@ -61,7 +60,7 @@ class JSPropsUpdaterPaper implements IJSPropsUpdater {
6160
> &
6261
IAnimatedComponentInternal
6362
) {
64-
const viewTag = findNodeHandle(animatedComponent);
63+
const viewTag = animatedComponent._componentViewTag;
6564
JSPropsUpdaterPaper._tagToComponentMapping.delete(viewTag);
6665
if (JSPropsUpdaterPaper._tagToComponentMapping.size === 0) {
6766
this._reanimatedEventEmitter.removeAllListeners(
@@ -101,7 +100,7 @@ class JSPropsUpdaterFabric implements IJSPropsUpdater {
101100
if (!JSPropsUpdaterFabric.isInitialized) {
102101
return;
103102
}
104-
const viewTag = findNodeHandle(animatedComponent);
103+
const viewTag = animatedComponent._componentViewTag;
105104
JSPropsUpdaterFabric._tagToComponentMapping.set(viewTag, animatedComponent);
106105
}
107106

@@ -114,7 +113,7 @@ class JSPropsUpdaterFabric implements IJSPropsUpdater {
114113
if (!JSPropsUpdaterFabric.isInitialized) {
115114
return;
116115
}
117-
const viewTag = findNodeHandle(animatedComponent);
116+
const viewTag = animatedComponent._componentViewTag;
118117
JSPropsUpdaterFabric._tagToComponentMapping.delete(viewTag);
119118
}
120119
}

0 commit comments

Comments
 (0)