Skip to content

Commit

Permalink
Replace findNodeHandle with reading _componentViewTag (#6720)
Browse files Browse the repository at this point in the history
## 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 <krzysztof.piaskowy@swmansion.com>
  • Loading branch information
2 people authored and tjzel committed Dec 13, 2024
1 parent 1fe79bc commit 4fe1844
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
import { NativeEventEmitter, Platform } from 'react-native';
import { findNodeHandle } from '../platformFunctions/findNodeHandle';
import type { NativeModule } from 'react-native';
import { shouldBeUseWeb } from '../PlatformChecker';
import type { StyleProps } from '../commonTypes';
Expand Down Expand Up @@ -39,7 +38,7 @@ class JSPropsUpdaterPaper implements IJSPropsUpdater {
> &
IAnimatedComponentInternal
) {
const viewTag = findNodeHandle(animatedComponent);
const viewTag = animatedComponent._componentViewTag;
JSPropsUpdaterPaper._tagToComponentMapping.set(viewTag, animatedComponent);
if (JSPropsUpdaterPaper._tagToComponentMapping.size === 1) {
const listener = (data: ListenerData) => {
Expand All @@ -61,7 +60,7 @@ class JSPropsUpdaterPaper implements IJSPropsUpdater {
> &
IAnimatedComponentInternal
) {
const viewTag = findNodeHandle(animatedComponent);
const viewTag = animatedComponent._componentViewTag;
JSPropsUpdaterPaper._tagToComponentMapping.delete(viewTag);
if (JSPropsUpdaterPaper._tagToComponentMapping.size === 0) {
this._reanimatedEventEmitter.removeAllListeners(
Expand Down Expand Up @@ -101,7 +100,7 @@ class JSPropsUpdaterFabric implements IJSPropsUpdater {
if (!JSPropsUpdaterFabric.isInitialized) {
return;
}
const viewTag = findNodeHandle(animatedComponent);
const viewTag = animatedComponent._componentViewTag;
JSPropsUpdaterFabric._tagToComponentMapping.set(viewTag, animatedComponent);
}

Expand All @@ -114,7 +113,7 @@ class JSPropsUpdaterFabric implements IJSPropsUpdater {
if (!JSPropsUpdaterFabric.isInitialized) {
return;
}
const viewTag = findNodeHandle(animatedComponent);
const viewTag = animatedComponent._componentViewTag;
JSPropsUpdaterFabric._tagToComponentMapping.delete(viewTag);
}
}
Expand Down

0 comments on commit 4fe1844

Please sign in to comment.