1import React from 'react';
2import { NativeModules, requireNativeComponent } from 'react-native';
3/**
4 * A map that caches registered native components.
5 */
6const nativeComponentsCache = new Map();
7/**
8 * Requires a React Native component from cache if possible. This prevents
9 * "Tried to register two views with the same name" errors on fast refresh, but
10 * also when there are multiple versions of the same package with native component.
11 */
12function requireCachedNativeComponent(viewName) {
13    const cachedNativeComponent = nativeComponentsCache.get(viewName);
14    if (!cachedNativeComponent) {
15        const nativeComponent = requireNativeComponent(viewName);
16        nativeComponentsCache.set(viewName, nativeComponent);
17        return nativeComponent;
18    }
19    return cachedNativeComponent;
20}
21/**
22 * A drop-in replacement for `requireNativeComponent`.
23 */
24export function requireNativeViewManager(viewName) {
25    const { viewManagersMetadata } = NativeModules.NativeUnimoduleProxy;
26    const viewManagerConfig = viewManagersMetadata?.[viewName];
27    if (__DEV__ && !viewManagerConfig) {
28        const exportedViewManagerNames = Object.keys(viewManagersMetadata).join(', ');
29        console.warn(`The native view manager required by name (${viewName}) from NativeViewManagerAdapter isn't exported by expo-modules-core. Views of this type may not render correctly. Exported view managers: [${exportedViewManagerNames}].`);
30    }
31    // Set up the React Native native component, which is an adapter to the universal module's view
32    // manager
33    const reactNativeViewName = `ViewManagerAdapter_${viewName}`;
34    const ReactNativeComponent = requireCachedNativeComponent(reactNativeViewName);
35    const proxiedPropsNames = viewManagerConfig?.propsNames ?? [];
36    // Define a component for universal-module authors to access their native view manager
37    const NativeComponentAdapter = React.forwardRef((props, ref) => {
38        const nativeProps = omit(props, proxiedPropsNames);
39        const proxiedProps = pick(props, proxiedPropsNames);
40        return React.createElement(ReactNativeComponent, { ...nativeProps, proxiedProperties: proxiedProps, ref: ref });
41    });
42    NativeComponentAdapter.displayName = `Adapter<${viewName}>`;
43    return NativeComponentAdapter;
44}
45function omit(props, propNames) {
46    const copied = { ...props };
47    for (const propName of propNames) {
48        delete copied[propName];
49    }
50    return copied;
51}
52function pick(props, propNames) {
53    return propNames.reduce((prev, curr) => {
54        if (curr in props) {
55            prev[curr] = props[curr];
56        }
57        return prev;
58    }, {});
59}
60//# sourceMappingURL=NativeViewManagerAdapter.native.js.map