import React from 'react'; import { NativeModules, requireNativeComponent } from 'react-native'; // To make the transition from React Native's `requireNativeComponent` to Expo's // `requireNativeViewManager` as easy as possible, `requireNativeViewManager` is a drop-in // replacement for `requireNativeComponent`. // // For each view manager, we create a wrapper component that accepts all of the props available to // the author of the universal module. This wrapper component splits the props into two sets: props // passed to React Native's View (ex: style, testID) and custom view props, which are passed to the // adapter view component in a prop called `proxiedProperties`. type NativeExpoComponentProps = { proxiedProperties: object; }; /** * A drop-in replacement for `requireNativeComponent`. */ export function requireNativeViewManager
(viewName: string): React.ComponentType
{
const { viewManagersMetadata } = NativeModules.NativeUnimoduleProxy;
const viewManagerConfig = viewManagersMetadata?.[viewName];
if (__DEV__ && !viewManagerConfig) {
const exportedViewManagerNames = Object.keys(viewManagersMetadata).join(', ');
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}].`
);
}
// Set up the React Native native component, which is an adapter to the universal module's view
// manager
const reactNativeViewName = `ViewManagerAdapter_${viewName}`;
const ReactNativeComponent =
requireNativeComponent