Skip to content

Commit 0071eb0

Browse files
IvanIhnatsiukIHNATSIUK, IVAN
andauthored
fix: findNodeHandle on the web platform (#912)
## 📜 Description In the new version of `react-native-web` they added an error throw if you try to use findNodeHandle from `react-native` https://github.com/necolas/react-native-web/blob/922c134f2b7c428cc19daaeb3cac4b6a4c8ec6a3/packages/react-native-web/src/exports/findNodeHandle/index.js#L11. So I created a findNodeHandle utility that uses react-native's findNodeHandle for the native platform and returns Node or null for web. ## 💡 Motivation and Context <!-- Why is this change required? What problem does it solve? --> <!-- If it fixes an open issue, please link to the issue here. --> This library should work well on all platforms ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### JS - added findNodeHandle util ## 🤔 How Has This Been Tested? <!-- Please describe in detail how you tested your changes. --> <!-- Include details of your testing environment, and the tests you ran to --> <!-- see how your change affects other areas of the code, etc. --> tested in a web browser ## 📸 Screenshots (if appropriate): <!-- Add screenshots/video if needed --> <!-- That would be highly appreciated if you can add how it looked before and after your changes --> Before: https://github.com/user-attachments/assets/7056e962-3427-4127-86ad-c204d09df874 After: https://github.com/user-attachments/assets/a2593a86-38dd-4f8d-aa73-0be04f1b3227 ## 📝 Checklist - [x] CI successfully passed - [ ] I added new mocks and corresponding unit-tests if library API was changed Co-authored-by: IHNATSIUK, IVAN <[email protected]>
1 parent 9011a90 commit 0071eb0

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

src/components/KeyboardAwareScrollView/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { forwardRef, useCallback, useMemo } from "react";
2-
import { findNodeHandle } from "react-native";
32
import Reanimated, {
43
interpolate,
54
scrollTo,
@@ -15,6 +14,7 @@ import {
1514
useReanimatedFocusedInput,
1615
useWindowDimensions,
1716
} from "../../hooks";
17+
import { findNodeHandle } from "../../utils/findNodeHandle";
1818

1919
import { useSmoothKeyboardHandler } from "./useSmoothKeyboardHandler";
2020
import { debounce, scrollDistanceWithRespectToSnapPoints } from "./utils";

src/internal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useRef } from "react";
2-
import { Animated, findNodeHandle } from "react-native";
2+
import { Animated } from "react-native";
33

44
import { registerEventHandler, unregisterEventHandler } from "./event-handler";
5+
import { findNodeHandle } from "./utils/findNodeHandle";
56

67
type EventHandler = (event: never) => void;
78
type ComponentOrHandle = Parameters<typeof findNodeHandle>[0];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { findNodeHandle } from "react-native";
2+
3+
export { findNodeHandle };

src/utils/findNodeHandle/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { findNodeHandle as findNodeHandleRN } from "react-native";
2+
3+
type FindNodeHandleRN = typeof findNodeHandleRN;
4+
5+
export const findNodeHandle: FindNodeHandleRN = (componentOrHandle) =>
6+
componentOrHandle as number | null;

0 commit comments

Comments
 (0)