1 | 'use strict';
|
2 |
|
3 |
|
4 | import type { ShadowNodeWrapper } from './commonTypes';
|
5 |
|
6 | let findHostInstance_DEPRECATED: (ref: unknown) => void;
|
7 | let getInternalInstanceHandleFromPublicInstance: (ref: unknown) => {
|
8 | stateNode: { node: unknown };
|
9 | };
|
10 |
|
11 | export function getShadowNodeWrapperFromRef(
|
12 | ref: React.Component
|
13 | ): ShadowNodeWrapper {
|
14 |
|
15 | if (findHostInstance_DEPRECATED === undefined) {
|
16 | try {
|
17 | findHostInstance_DEPRECATED =
|
18 | require('react-native/Libraries/Renderer/shims/ReactFabric').findHostInstance_DEPRECATED;
|
19 | } catch (e) {
|
20 | findHostInstance_DEPRECATED = (_ref: unknown) => null;
|
21 | }
|
22 | }
|
23 |
|
24 | if (getInternalInstanceHandleFromPublicInstance === undefined) {
|
25 | try {
|
26 | getInternalInstanceHandleFromPublicInstance =
|
27 | require('react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance')
|
28 | .getInternalInstanceHandleFromPublicInstance ??
|
29 | ((_ref: any) => _ref._internalInstanceHandle);
|
30 | } catch (e) {
|
31 | getInternalInstanceHandleFromPublicInstance = (_ref: any) =>
|
32 | _ref._internalInstanceHandle;
|
33 | }
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 | const scrollViewRef = ref?.getScrollResponder?.()?.getNativeScrollRef?.();
|
39 |
|
40 | const otherScrollViewRef = ref?.getNativeScrollRef?.();
|
41 |
|
42 | const textInputRef = ref?.__internalInstanceHandle?.stateNode?.node;
|
43 |
|
44 | let resolvedRef;
|
45 | if (scrollViewRef) {
|
46 | resolvedRef = scrollViewRef.__internalInstanceHandle.stateNode.node;
|
47 | } else if (otherScrollViewRef) {
|
48 | resolvedRef = otherScrollViewRef.__internalInstanceHandle.stateNode.node;
|
49 | } else if (textInputRef) {
|
50 | resolvedRef = textInputRef;
|
51 | } else {
|
52 | resolvedRef = getInternalInstanceHandleFromPublicInstance(
|
53 | findHostInstance_DEPRECATED(ref)
|
54 | ).stateNode.node;
|
55 | }
|
56 |
|
57 | return resolvedRef;
|
58 | }
|