UNPKG

1.45 kBPlain TextView Raw
1'use strict';
2/* eslint-disable @typescript-eslint/no-explicit-any */
3
4// This is a makeshift solution to handle both 0.73 and 0.74 versions of React Native.
5
6export let getViewInfo = (element: any) => {
7 if (element._nativeTag !== undefined && element.__nativeTag !== null) {
8 getViewInfo = getViewInfo73;
9 return getViewInfo73(element);
10 } else if (
11 element.__nativeTag !== undefined &&
12 element.__nativeTag !== null
13 ) {
14 getViewInfo = getViewInfoLatest;
15 return getViewInfoLatest(element);
16 }
17 return getViewInfo73(element);
18};
19
20function getViewInfo73(element: any) {
21 return {
22 // we can access view tag in the same way it's accessed here https://github.com/facebook/react/blob/e3f4eb7272d4ca0ee49f27577156b57eeb07cf73/packages/react-native-renderer/src/ReactFabric.js#L146
23 viewName: element?.viewConfig?.uiViewClassName,
24 /**
25 * RN uses viewConfig for components for storing different properties of the component(example: https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Components/ScrollView/ScrollViewNativeComponent.js#L24).
26 * The name we're looking for is in the field named uiViewClassName.
27 */
28 viewTag: element?._nativeTag,
29 viewConfig: element?.viewConfig,
30 };
31}
32
33function getViewInfoLatest(element: any) {
34 return {
35 viewName: element?._viewConfig?.uiViewClassName,
36 viewTag: element?.__nativeTag,
37 viewConfig: element?._viewConfig,
38 };
39}