Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web] Add findNodeHandle web version #6403

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
} from 'react';
import type { ReactNode } from 'react';
import { setShouldAnimateExitingForTag } from '../core';
import { findNodeHandle } from 'react-native';
import { findNodeHandle } from '../platformFunctions/findNodeHandle';

export const SkipEnteringContext =
createContext<React.MutableRefObject<boolean> | null>(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
import { NativeEventEmitter, Platform, findNodeHandle } from 'react-native';
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
} from './commonTypes';
import { has } from './utils';
import { WorkletEventHandler } from '../WorkletEventHandler';
import { findNodeHandle } from 'react-native';
import { findNodeHandle } from '../platformFunctions/findNodeHandle';

export class NativeEventsManager implements INativeEventsManager {
readonly #managedComponent: ManagedAnimatedComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type {
MutableRefObject,
} from 'react';
import React from 'react';
import { findNodeHandle, Platform } from 'react-native';
import { Platform } from 'react-native';
import { findNodeHandle } from '../platformFunctions/findNodeHandle';
import '../layoutReanimation/animationsManager';
import invariant from 'invariant';
import { adaptViewConfig } from '../ConfigHelper';
Expand Down Expand Up @@ -478,9 +479,7 @@ export function createAnimatedComponent(
setLocalRef: (ref) => {
// TODO update config

const tag = IS_WEB
? (ref as HTMLElement)
: findNodeHandle(ref as Component);
const tag = findNodeHandle(ref as Component);

this._componentViewTag = tag as number;

Expand All @@ -504,7 +503,7 @@ export function createAnimatedComponent(
: getReduceMotionFromConfig();
if (!reduceMotionInExiting) {
updateLayoutAnimations(
tag as number,
tag,
LayoutAnimationType.EXITING,
maybeBuild(
exiting,
Expand All @@ -518,7 +517,7 @@ export function createAnimatedComponent(
const skipEntering = this.context?.current;
if (entering && !skipEntering && !IS_WEB) {
updateLayoutAnimations(
tag as number,
tag,
LayoutAnimationType.ENTERING,
maybeBuild(
entering,
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native-reanimated/src/hook/useAnimatedRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type { ShadowNodeWrapper } from '../commonTypes';
import { getShadowNodeWrapperFromRef } from '../fabricUtils';
import { makeShareableCloneRecursive } from '../shareables';
import { shareableMappingCache } from '../shareableMappingCache';
import { Platform, findNodeHandle } from 'react-native';
import { Platform } from 'react-native';
import { findNodeHandle } from '../platformFunctions/findNodeHandle';
import type { ScrollView, FlatList } from 'react-native';
import { isFabric, isWeb } from '../PlatformChecker';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';
import { findNodeHandle } from 'react-native';

export { findNodeHandle };
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';
import type { Component, ComponentClass } from 'react';

export function findNodeHandle(
componentOrHandle: null | number | Component<any, any> | ComponentClass<any>
) {
return componentOrHandle;
}