Skip to content

Commit 6442b0e

Browse files
committed
fix(#2237): fixed node handle lookup for virtualized list on web (by @btoo)
1 parent 711ea7a commit 6442b0e

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed
Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1-
import type React from 'react';
2-
import { findNodeHandle as _findNodeHandle } from 'react-native';
1+
import {
2+
type NodeHandle,
3+
findNodeHandle as _findNodeHandle,
4+
} from 'react-native';
35

46
export function findNodeHandle(
5-
componentOrHandle:
6-
| null
7-
| number
8-
// biome-ignore lint/suspicious/noExplicitAny: fix later
9-
| React.Component<any, any>
10-
// biome-ignore lint/suspicious/noExplicitAny: fix later
11-
| React.ComponentClass<any>
7+
componentOrHandle: Parameters<typeof _findNodeHandle>['0']
128
) {
9+
let nodeHandle: NodeHandle | null;
10+
try {
11+
nodeHandle = _findNodeHandle(componentOrHandle);
12+
if (nodeHandle) {
13+
return nodeHandle;
14+
}
15+
} catch {}
16+
1317
try {
14-
return _findNodeHandle(componentOrHandle);
15-
} catch {
1618
// @ts-ignore
17-
return componentOrHandle.getNativeScrollRef();
19+
nodeHandle = componentOrHandle.getNativeScrollRef();
20+
if (nodeHandle) {
21+
return nodeHandle;
22+
}
23+
} catch {}
24+
25+
// @ts-ignore https://github.com/facebook/react-native/blob/a314e34d6ee875830d36e4df1789a897c7262056/packages/virtualized-lists/Lists/VirtualizedList.js#L1252
26+
nodeHandle = componentOrHandle._scrollRef;
27+
if (nodeHandle) {
28+
return nodeHandle;
1829
}
30+
31+
console.warn('could not find scrollable ref!');
32+
return componentOrHandle;
1933
}

0 commit comments

Comments
 (0)