From b702bda682a8906170ba295880f90e4c45a93100 Mon Sep 17 00:00:00 2001 From: Morgan Trudeau Date: Mon, 29 Sep 2025 16:57:05 -0700 Subject: [PATCH 1/2] Added custom findNodeHandle function to support react 19 and lower --- src/components/CellRendererComponent.tsx | 2 +- src/components/NestableDraggableFlatList.tsx | 3 ++- src/utils.ts | 28 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/components/CellRendererComponent.tsx b/src/components/CellRendererComponent.tsx index e4e861a6..39dba774 100644 --- a/src/components/CellRendererComponent.tsx +++ b/src/components/CellRendererComponent.tsx @@ -1,11 +1,11 @@ import React, { useEffect, useMemo, useRef } from "react"; import { - findNodeHandle, LayoutChangeEvent, MeasureLayoutOnSuccessCallback, StyleProp, ViewStyle, } from "react-native"; +import { findNodeHandle } from "../utils"; import Animated, { runOnUI, useAnimatedStyle, diff --git a/src/components/NestableDraggableFlatList.tsx b/src/components/NestableDraggableFlatList.tsx index 15593527..0fbccbce 100644 --- a/src/components/NestableDraggableFlatList.tsx +++ b/src/components/NestableDraggableFlatList.tsx @@ -1,5 +1,6 @@ import React, { useRef, useState } from "react"; -import { findNodeHandle, LogBox } from "react-native"; +import { LogBox } from "react-native"; +import { findNodeHandle } from "../utils"; import Animated, { useDerivedValue, useSharedValue, diff --git a/src/utils.ts b/src/utils.ts index 7989006d..b564ada9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,33 @@ import React from "react"; +import { findNodeHandle as reactNativeFindNodeHandle } from 'react-native'; // Fixes bug with useMemo + generic types: // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/37087#issuecomment-542793243 export const typedMemo: (c: T) => T = React.memo; + +/** + * React 19 compatible version of findNodeHandle. + * In React 19, findNodeHandle is deprecated and refs should be used directly. + * This utility provides backwards compatibility with React 18 while preparing for React 19. + */ +export function findNodeHandle(ref: any): number | null { + // In React 19+, we can use the ref directly as it contains the native tag + if (ref && typeof ref === 'object' && '_nativeTag' in ref) { + return ref._nativeTag; + } + + // For React 18 and below, use the traditional findNodeHandle + if (reactNativeFindNodeHandle) { + return reactNativeFindNodeHandle(ref); + } + + // Fallback: try to extract native tag from ref + if (ref && typeof ref === 'object') { + // Check for common native tag properties + if ('_nativeTag' in ref) return ref._nativeTag; + if ('nativeTag' in ref) return ref.nativeTag; + if ('tag' in ref) return ref.tag; + } + + return null; +} From 5d322a28f19148945b841e0a4a34369b9c5c2368 Mon Sep 17 00:00:00 2001 From: Morgan Trudeau Date: Mon, 29 Sep 2025 17:20:36 -0700 Subject: [PATCH 2/2] Update utils --- src/utils.ts | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index b564ada9..3c21eba5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,33 +1,14 @@ import React from "react"; -import { findNodeHandle as reactNativeFindNodeHandle } from 'react-native'; +import { findNodeHandle as reactNativeFindNodeHandle, Platform } from 'react-native'; // Fixes bug with useMemo + generic types: // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/37087#issuecomment-542793243 export const typedMemo: (c: T) => T = React.memo; -/** - * React 19 compatible version of findNodeHandle. - * In React 19, findNodeHandle is deprecated and refs should be used directly. - * This utility provides backwards compatibility with React 18 while preparing for React 19. - */ -export function findNodeHandle(ref: any): number | null { - // In React 19+, we can use the ref directly as it contains the native tag - if (ref && typeof ref === 'object' && '_nativeTag' in ref) { - return ref._nativeTag; - } - - // For React 18 and below, use the traditional findNodeHandle - if (reactNativeFindNodeHandle) { - return reactNativeFindNodeHandle(ref); - } - // Fallback: try to extract native tag from ref - if (ref && typeof ref === 'object') { - // Check for common native tag properties - if ('_nativeTag' in ref) return ref._nativeTag; - if ('nativeTag' in ref) return ref.nativeTag; - if ('tag' in ref) return ref.tag; +export function findNodeHandle(ref: any): number | null { + if(Platform.OS === "web") { + return ref && typeof ref === 'object' && 'current' in ref ? ref.current : ref } - - return null; + return reactNativeFindNodeHandle(ref) }