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 |
|
33 | const reactNativeUIConfiguration = (UIManager.getViewManagerConfig
|
34 | ? UIManager.getViewManagerConfig(reactNativeViewName)
|
35 | : UIManager[reactNativeViewName]) || {
|
36 | NativeProps: {},
|
37 | directEventTypes: {},
|
38 | };
|
39 | const reactNativeComponentPropNames = [
|
40 | 'children',
|
41 | ...ViewPropTypesKeys,
|
42 | ...Object.keys(reactNativeUIConfiguration.NativeProps),
|
43 | ...Object.keys(reactNativeUIConfiguration.directEventTypes),
|
44 | ];
|
45 |
|
46 | function NativeComponentAdapter(props, ref) {
|
47 |
|
48 |
|
49 | const nativeProps = pick(props, reactNativeComponentPropNames);
|
50 | const proxiedProps = omit(props, reactNativeComponentPropNames);
|
51 | return <ReactNativeComponent {...nativeProps} proxiedProperties={proxiedProps} ref={ref}/>;
|
52 | }
|
53 | NativeComponentAdapter.displayName = `Adapter<${viewName}>`;
|
54 | return React.forwardRef(NativeComponentAdapter);
|
55 | }
|
56 | //# sourceMappingURL=NativeViewManagerAdapter.js.map |
\ | No newline at end of file |