1 | import omit from 'lodash/omit';
|
2 | import pick from 'lodash/pick';
|
3 | import React from 'react';
|
4 | import { NativeModules, UIManager, ViewPropTypes, requireNativeComponent } from 'react-native';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | const ViewPropTypesKeys = Object.keys(ViewPropTypes);
|
17 |
|
18 |
|
19 |
|
20 | export function requireNativeViewManager(viewName) {
|
21 | if (__DEV__) {
|
22 | const { NativeUnimoduleProxy } = NativeModules;
|
23 | if (!NativeUnimoduleProxy.viewManagersNames.includes(viewName)) {
|
24 | const exportedViewManagerNames = NativeUnimoduleProxy.viewManagersNames.join(', ');
|
25 | console.warn(`The native view manager required by name (${viewName}) from NativeViewManagerAdapter isn't exported by @unimodules/react-native-adapter. Views of this type may not render correctly. Exported view managers: [${exportedViewManagerNames}].`);
|
26 | }
|
27 | }
|
28 |
|
29 |
|
30 | const reactNativeViewName = `ViewManagerAdapter_${viewName}`;
|
31 | const ReactNativeComponent = requireNativeComponent(reactNativeViewName);
|
32 | const reactNativeUIConfiguration = (UIManager.getViewManagerConfig
|
33 | ? UIManager.getViewManagerConfig(reactNativeViewName)
|
34 | : UIManager[reactNativeViewName]) || {
|
35 | NativeProps: {},
|
36 | directEventTypes: {},
|
37 | };
|
38 | const reactNativeComponentPropNames = [
|
39 | 'children',
|
40 | ...ViewPropTypesKeys,
|
41 | ...Object.keys(reactNativeUIConfiguration.NativeProps),
|
42 | ...Object.keys(reactNativeUIConfiguration.directEventTypes),
|
43 | ];
|
44 |
|
45 | function NativeComponentAdapter(props, ref) {
|
46 |
|
47 |
|
48 | const nativeProps = pick(props, reactNativeComponentPropNames);
|
49 | const proxiedProps = omit(props, reactNativeComponentPropNames);
|
50 | return React.createElement(ReactNativeComponent, Object.assign({}, nativeProps, { proxiedProperties: proxiedProps, ref: ref }));
|
51 | }
|
52 | NativeComponentAdapter.displayName = `Adapter<${viewName}>`;
|
53 | return React.forwardRef(NativeComponentAdapter);
|
54 | }
|
55 |
|
\ | No newline at end of file |