Skip to content

Commit

Permalink
Remove rest of findNodeHandle on web (#5654)
Browse files Browse the repository at this point in the history
## Summary

As mentioned in [this
comment](#4802 (comment)),
some of `findNodeHandle` calls are still present on web. This PR aims to
remove them in order to get rid of errors in `StrictMode`.

## Test plan

Tested on examples (mainly with scroll, like "ScrollViewExample" or
"ScrollEventExample")
  • Loading branch information
m-bert authored Feb 9, 2024
1 parent 5633e7b commit 1b7a590
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/createAnimatedComponent/createAnimatedComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ export function createAnimatedComponent(
prop.current instanceof WorkletEventHandler
) {
if (viewTag === null) {
viewTag = findNodeHandle(options?.setNativeProps ? this : node);
viewTag = IS_WEB
? this._component
: findNodeHandle(options?.setNativeProps ? this : node);
}
prop.current.registerForEvents(viewTag as number, key);
}
Expand Down Expand Up @@ -308,7 +310,10 @@ export function createAnimatedComponent(
) {
if (viewTag === null) {
const node = this._getEventViewRef() as AnimatedComponentRef;
viewTag = findNodeHandle(options?.setNativeProps ? this : node);

viewTag = IS_WEB
? this._component
: findNodeHandle(options?.setNativeProps ? this : node);
}
prop.current.registerForEvents(viewTag as number, key);
prop.current.reattachNeeded = false;
Expand Down
7 changes: 5 additions & 2 deletions src/reanimated2/hook/useAnimatedRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { makeShareableCloneRecursive } from '../shareables';
import { shareableMappingCache } from '../shareableMappingCache';
import { Platform, findNodeHandle } from 'react-native';
import type { ScrollView, FlatList } from 'react-native';
import { isFabric } from '../PlatformChecker';
import { isFabric, isWeb } from '../PlatformChecker';

const IS_FABRIC = isFabric();
const IS_WEB = isWeb();

interface MaybeScrollableComponent extends Component {
getNativeScrollRef?: FlatList['getNativeScrollRef'];
Expand Down Expand Up @@ -56,7 +57,9 @@ export function useAnimatedRef<
) => {
// enters when ref is set by attaching to a component
if (component) {
tag.value = getTagValueFunction(getComponentOrScrollable(component));
tag.value = IS_WEB
? getComponentOrScrollable(component)
: getTagValueFunction(getComponentOrScrollable(component));
fun.current = component;
// viewName is required only on iOS with Paper
if (Platform.OS === 'ios' && !IS_FABRIC) {
Expand Down
8 changes: 7 additions & 1 deletion src/reanimated2/hook/useScrollViewOffset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import type {
RNNativeScrollEvent,
ReanimatedScrollEvent,
} from './commonTypes';
import { isWeb } from '../PlatformChecker';

const IS_WEB = isWeb();

const scrollEventNames = [
'onScroll',
Expand Down Expand Up @@ -50,7 +53,10 @@ export function useScrollViewOffset(
) as unknown as EventHandlerInternal<ReanimatedScrollEvent>;

useEffect(() => {
const viewTag = findNodeHandle(animatedRef.current);
const viewTag = IS_WEB
? animatedRef.current
: findNodeHandle(animatedRef.current);

eventHandler.current?.registerForEvents(viewTag as number);

return () => {
Expand Down

0 comments on commit 1b7a590

Please sign in to comment.