UNPKG

5.02 kBSource Map (JSON)View Raw
1{"version":3,"file":"NativeViewManagerAdapter.native.js","sourceRoot":"","sources":["../src/NativeViewManagerAdapter.native.tsx"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE/F,gFAAgF;AAChF,0FAA0F;AAC1F,4CAA4C;AAC5C,EAAE;AACF,kGAAkG;AAClG,mGAAmG;AACnG,mGAAmG;AACnG,+DAA+D;AAE/D,kGAAkG;AAClG,+FAA+F;AAC/F,qCAAqC;AACrC,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AAMrD;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAU,QAAgB;IAChE,IAAI,OAAO,EAAE;QACX,MAAM,EAAE,oBAAoB,EAAE,GAAG,aAAa,CAAC;QAC/C,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;YAC9D,MAAM,wBAAwB,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnF,OAAO,CAAC,IAAI,CACV,6CAA6C,QAAQ,6JAA6J,wBAAwB,IAAI,CAC/O,CAAC;SACH;KACF;IAED,+FAA+F;IAC/F,UAAU;IACV,MAAM,mBAAmB,GAAG,sBAAsB,QAAQ,EAAE,CAAC;IAC7D,MAAM,oBAAoB,GAAG,sBAAsB,CACjD,mBAAmB,CACpB,CAAC;IACF,MAAM,0BAA0B,GAAG,CAAC,SAAS,CAAC,oBAAoB;QAChE,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,mBAAmB,CAAC;QACrD,CAAC,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC,IAAI;QACrC,WAAW,EAAE,EAAE;QACf,gBAAgB,EAAE,EAAE;KACrB,CAAC;IACF,MAAM,6BAA6B,GAAG;QACpC,UAAU;QACV,GAAG,iBAAiB;QACpB,GAAG,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,WAAW,CAAC;QACtD,GAAG,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,gBAAgB,CAAC;KAC5D,CAAC;IAEF,sFAAsF;IACtF,SAAS,sBAAsB,CAAC,KAAK,EAAE,GAAG;QACxC,8FAA8F;QAC9F,+FAA+F;QAC/F,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,EAAE,6BAA6B,CAAC,CAAC;QAC/D,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,EAAE,6BAA6B,CAAC,CAAC;QAChE,OAAO,oBAAC,oBAAoB,oBAAK,WAAW,IAAE,iBAAiB,EAAE,YAAY,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC9F,CAAC;IACD,sBAAsB,CAAC,WAAW,GAAG,WAAW,QAAQ,GAAG,CAAC;IAC5D,OAAO,KAAK,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import omit from 'lodash/omit';\nimport pick from 'lodash/pick';\nimport React from 'react';\nimport { NativeModules, UIManager, ViewPropTypes, requireNativeComponent } from 'react-native';\n\n// To make the transition from React Native's `requireNativeComponent` to Expo's\n// `requireNativeViewManager` as easy as possible, `requireNativeViewManager` is a drop-in\n// replacement for `requireNativeComponent`.\n//\n// For each view manager, we create a wrapper component that accepts all of the props available to\n// the author of the universal module. This wrapper component splits the props into two sets: props\n// passed to React Native's View (ex: style, testID) and custom view props, which are passed to the\n// adapter view component in a prop called `proxiedProperties`.\n\n// NOTE: React Native is moving away from runtime PropTypes and may remove ViewPropTypes, in which\n// case we will need another way to separate standard React Native view props from other props,\n// which we proxy through the adapter\nconst ViewPropTypesKeys = Object.keys(ViewPropTypes);\n\ntype NativeExpoComponentProps = {\n proxiedProperties: object;\n};\n\n/**\n * A drop-in replacement for `requireNativeComponent`.\n */\nexport function requireNativeViewManager<P = any>(viewName: string): React.ComponentType<P> {\n if (__DEV__) {\n const { NativeUnimoduleProxy } = NativeModules;\n if (!NativeUnimoduleProxy.viewManagersNames.includes(viewName)) {\n const exportedViewManagerNames = NativeUnimoduleProxy.viewManagersNames.join(', ');\n console.warn(\n `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}].`\n );\n }\n }\n\n // Set up the React Native native component, which is an adapter to the universal module's view\n // manager\n const reactNativeViewName = `ViewManagerAdapter_${viewName}`;\n const ReactNativeComponent = requireNativeComponent<NativeExpoComponentProps>(\n reactNativeViewName\n );\n const reactNativeUIConfiguration = (UIManager.getViewManagerConfig\n ? UIManager.getViewManagerConfig(reactNativeViewName)\n : UIManager[reactNativeViewName]) || {\n NativeProps: {},\n directEventTypes: {},\n };\n const reactNativeComponentPropNames = [\n 'children',\n ...ViewPropTypesKeys,\n ...Object.keys(reactNativeUIConfiguration.NativeProps),\n ...Object.keys(reactNativeUIConfiguration.directEventTypes),\n ];\n\n // Define a component for universal-module authors to access their native view manager\n function NativeComponentAdapter(props, ref) {\n // TODO: `omit` may incur a meaningful performance cost across many native components rendered\n // in the same update. Profile this and write out a partition function if this is a bottleneck.\n const nativeProps = pick(props, reactNativeComponentPropNames);\n const proxiedProps = omit(props, reactNativeComponentPropNames);\n return <ReactNativeComponent {...nativeProps} proxiedProperties={proxiedProps} ref={ref} />;\n }\n NativeComponentAdapter.displayName = `Adapter<${viewName}>`;\n return React.forwardRef(NativeComponentAdapter);\n}\n"]}
\No newline at end of file