From 67847f4f11f2c18dcaae4ecc0ab116c2794087fd Mon Sep 17 00:00:00 2001 From: Evan Bacon Date: Thu, 28 May 2020 10:43:34 -0700 Subject: [PATCH] [react-native-adapter] Swap native with web (#8502) * Swap native with web * Update packages/@unimodules/react-native-adapter/src/NativeModulesProxy.ts Co-authored-by: James Ide * fix build Co-authored-by: James Ide --- .../build/NativeModulesProxy.d.ts | 10 +-- .../build/NativeModulesProxy.js | 32 +-------- .../build/NativeModulesProxy.js.map | 2 +- .../build/NativeModulesProxy.native.d.ts | 5 ++ .../build/NativeModulesProxy.native.js | 31 +++++++++ .../build/NativeModulesProxy.native.js.map | 1 + .../build/NativeModulesProxy.types.d.ts | 5 ++ .../build/NativeModulesProxy.types.js | 1 + .../build/NativeModulesProxy.types.js.map | 1 + .../build/NativeModulesProxy.web.d.ts | 2 - .../build/NativeModulesProxy.web.js | 2 - .../build/NativeModulesProxy.web.js.map | 1 - .../build/NativeViewManagerAdapter.d.ts | 3 - .../build/NativeViewManagerAdapter.js | 54 +-------------- .../build/NativeViewManagerAdapter.js.map | 2 +- ...s => NativeViewManagerAdapter.native.d.ts} | 3 + .../build/NativeViewManagerAdapter.native.js | 55 +++++++++++++++ .../NativeViewManagerAdapter.native.js.map | 1 + .../build/NativeViewManagerAdapter.web.js | 5 -- .../build/NativeViewManagerAdapter.web.js.map | 1 - .../react-native-adapter/build/index.d.ts | 3 +- .../react-native-adapter/build/index.js.map | 2 +- .../build/nativeEmitters.d.ts | 4 +- .../build/nativeEmitters.js | 4 +- .../build/nativeEmitters.js.map | 2 +- .../build/nativeEmitters.native.d.ts | 3 + .../build/nativeEmitters.native.js | 4 ++ .../build/nativeEmitters.native.js.map | 1 + .../build/nativeEmitters.web.d.ts | 3 - .../build/nativeEmitters.web.js | 4 -- .../build/nativeEmitters.web.js.map | 1 - .../src/NativeModulesProxy.native.ts | 46 +++++++++++++ .../src/NativeModulesProxy.ts | 52 +------------- .../src/NativeModulesProxy.types.ts | 5 ++ .../src/NativeModulesProxy.web.ts | 1 - .../src/NativeViewManagerAdapter.native.tsx | 67 +++++++++++++++++++ .../src/NativeViewManagerAdapter.tsx | 64 +----------------- .../src/NativeViewManagerAdapter.web.tsx | 7 -- .../react-native-adapter/src/index.ts | 3 +- .../src/nativeEmitters.native.ts | 4 ++ .../src/nativeEmitters.ts | 4 +- .../src/nativeEmitters.web.ts | 4 -- 42 files changed, 259 insertions(+), 246 deletions(-) create mode 100644 packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.d.ts create mode 100644 packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js create mode 100644 packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js.map create mode 100644 packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.d.ts create mode 100644 packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.js create mode 100644 packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.js.map delete mode 100644 packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.d.ts delete mode 100644 packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.js delete mode 100644 packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.js.map rename packages/@unimodules/react-native-adapter/build/{NativeViewManagerAdapter.web.d.ts => NativeViewManagerAdapter.native.d.ts} (67%) create mode 100644 packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.native.js create mode 100644 packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.native.js.map delete mode 100644 packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.web.js delete mode 100644 packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.web.js.map create mode 100644 packages/@unimodules/react-native-adapter/build/nativeEmitters.native.d.ts create mode 100644 packages/@unimodules/react-native-adapter/build/nativeEmitters.native.js create mode 100644 packages/@unimodules/react-native-adapter/build/nativeEmitters.native.js.map delete mode 100644 packages/@unimodules/react-native-adapter/build/nativeEmitters.web.d.ts delete mode 100644 packages/@unimodules/react-native-adapter/build/nativeEmitters.web.js delete mode 100644 packages/@unimodules/react-native-adapter/build/nativeEmitters.web.js.map create mode 100644 packages/@unimodules/react-native-adapter/src/NativeModulesProxy.native.ts create mode 100644 packages/@unimodules/react-native-adapter/src/NativeModulesProxy.types.ts delete mode 100644 packages/@unimodules/react-native-adapter/src/NativeModulesProxy.web.ts create mode 100644 packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.native.tsx delete mode 100644 packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.web.tsx create mode 100644 packages/@unimodules/react-native-adapter/src/nativeEmitters.native.ts delete mode 100644 packages/@unimodules/react-native-adapter/src/nativeEmitters.web.ts diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.d.ts b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.d.ts index 0b735457fef41..45ca5183990f9 100644 --- a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.d.ts +++ b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.d.ts @@ -1,9 +1,5 @@ -export declare type ProxyNativeModule = { - [propertyName: string]: any; - addListener: (eventName: string) => void; - removeListeners: (count: number) => void; -}; -declare const NativeModulesProxy: { +import { ProxyNativeModule } from './NativeModulesProxy.types'; +declare const _default: { [moduleName: string]: ProxyNativeModule; }; -export default NativeModulesProxy; +export default _default; diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.js b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.js index 49c5134f91dd8..968fce870b779 100644 --- a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.js +++ b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.js @@ -1,31 +1,3 @@ -import { NativeModules } from 'react-native'; -const NativeProxy = NativeModules.NativeUnimoduleProxy; -const modulesConstantsKey = 'modulesConstants'; -const exportedMethodsKey = 'exportedMethods'; -const NativeModulesProxy = {}; -if (NativeProxy) { - Object.keys(NativeProxy[exportedMethodsKey]).forEach(moduleName => { - NativeModulesProxy[moduleName] = NativeProxy[modulesConstantsKey][moduleName] || {}; - NativeProxy[exportedMethodsKey][moduleName].forEach(methodInfo => { - NativeModulesProxy[moduleName][methodInfo.name] = (...args) => { - const { key, argumentsCount } = methodInfo; - if (argumentsCount !== args.length) { - return Promise.reject(new Error(`Native method ${moduleName}.${methodInfo.name} expects ${argumentsCount} ${argumentsCount === 1 ? 'argument' : 'arguments'} but received ${args.length}`)); - } - return NativeProxy.callMethod(moduleName, key, args); - }; - }); - // These are called by EventEmitter (which is a wrapper for NativeEventEmitter) - // only on iOS and they use iOS-specific native module, EXReactNativeEventEmitter. - // - // On Android only {start,stop}Observing are called on the native module - // and these should be exported as Expo methods. - NativeModulesProxy[moduleName].addListener = (...args) => NativeModules.UMReactNativeEventEmitter.addProxiedListener(moduleName, ...args); - NativeModulesProxy[moduleName].removeListeners = (...args) => NativeModules.UMReactNativeEventEmitter.removeProxiedListeners(moduleName, ...args); - }); -} -else { - console.warn(`The "UMNativeModulesProxy" native module is not exported through NativeModules; verify that @unimodules/react-native-adapter's native code is linked properly`); -} -export default NativeModulesProxy; +// We default to an empty object shim wherever we don't have an environment-specific implementation +export default {}; //# sourceMappingURL=NativeModulesProxy.js.map \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.js.map b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.js.map index 99a015348f06f..3ccf93712b51d 100644 --- a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.js.map +++ b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.js.map @@ -1 +1 @@ -{"version":3,"file":"NativeModulesProxy.js","sourceRoot":"","sources":["../src/NativeModulesProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,WAAW,GAAG,aAAa,CAAC,oBAAoB,CAAC;AACvD,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAC/C,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAQ7C,MAAM,kBAAkB,GAAgD,EAAE,CAAC;AAE3E,IAAI,WAAW,EAAE;IACf,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QAChE,kBAAkB,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACpF,WAAW,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC/D,kBAAkB,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAe,EAAgB,EAAE;gBACrF,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,UAAU,CAAC;gBAC3C,IAAI,cAAc,KAAK,IAAI,CAAC,MAAM,EAAE;oBAClC,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,iBAAiB,UAAU,IAAI,UAAU,CAAC,IAAI,YAAY,cAAc,IACtE,cAAc,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WACtC,iBAAiB,IAAI,CAAC,MAAM,EAAE,CAC/B,CACF,CAAC;iBACH;gBACD,OAAO,WAAW,CAAC,UAAU,CAAC,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YACvD,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,+EAA+E;QAC/E,kFAAkF;QAClF,EAAE;QACF,wEAAwE;QACxE,gDAAgD;QAChD,kBAAkB,CAAC,UAAU,CAAC,CAAC,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CACvD,aAAa,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;QAClF,kBAAkB,CAAC,UAAU,CAAC,CAAC,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAC3D,aAAa,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;CACJ;KAAM;IACL,OAAO,CAAC,IAAI,CACV,+JAA+J,CAChK,CAAC;CACH;AAED,eAAe,kBAAkB,CAAC","sourcesContent":["import { NativeModules } from 'react-native';\n\nconst NativeProxy = NativeModules.NativeUnimoduleProxy;\nconst modulesConstantsKey = 'modulesConstants';\nconst exportedMethodsKey = 'exportedMethods';\n\nexport type ProxyNativeModule = {\n [propertyName: string]: any;\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n};\n\nconst NativeModulesProxy: { [moduleName: string]: ProxyNativeModule } = {};\n\nif (NativeProxy) {\n Object.keys(NativeProxy[exportedMethodsKey]).forEach(moduleName => {\n NativeModulesProxy[moduleName] = NativeProxy[modulesConstantsKey][moduleName] || {};\n NativeProxy[exportedMethodsKey][moduleName].forEach(methodInfo => {\n NativeModulesProxy[moduleName][methodInfo.name] = (...args: unknown[]): Promise => {\n const { key, argumentsCount } = methodInfo;\n if (argumentsCount !== args.length) {\n return Promise.reject(\n new Error(\n `Native method ${moduleName}.${methodInfo.name} expects ${argumentsCount} ${\n argumentsCount === 1 ? 'argument' : 'arguments'\n } but received ${args.length}`\n )\n );\n }\n return NativeProxy.callMethod(moduleName, key, args);\n };\n });\n\n // These are called by EventEmitter (which is a wrapper for NativeEventEmitter)\n // only on iOS and they use iOS-specific native module, EXReactNativeEventEmitter.\n //\n // On Android only {start,stop}Observing are called on the native module\n // and these should be exported as Expo methods.\n NativeModulesProxy[moduleName].addListener = (...args) =>\n NativeModules.UMReactNativeEventEmitter.addProxiedListener(moduleName, ...args);\n NativeModulesProxy[moduleName].removeListeners = (...args) =>\n NativeModules.UMReactNativeEventEmitter.removeProxiedListeners(moduleName, ...args);\n });\n} else {\n console.warn(\n `The \"UMNativeModulesProxy\" native module is not exported through NativeModules; verify that @unimodules/react-native-adapter's native code is linked properly`\n );\n}\n\nexport default NativeModulesProxy;\n"]} \ No newline at end of file +{"version":3,"file":"NativeModulesProxy.js","sourceRoot":"","sources":["../src/NativeModulesProxy.ts"],"names":[],"mappings":"AAEA,mGAAmG;AACnG,eAAe,EAAiD,CAAC","sourcesContent":["import { ProxyNativeModule } from './NativeModulesProxy.types';\n\n// We default to an empty object shim wherever we don't have an environment-specific implementation\nexport default {} as { [moduleName: string]: ProxyNativeModule };\n"]} \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.d.ts b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.d.ts new file mode 100644 index 0000000000000..328333529f253 --- /dev/null +++ b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.d.ts @@ -0,0 +1,5 @@ +import { ProxyNativeModule } from './NativeModulesProxy.types'; +declare const NativeModulesProxy: { + [moduleName: string]: ProxyNativeModule; +}; +export default NativeModulesProxy; diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js new file mode 100644 index 0000000000000..fdcfaba5a818a --- /dev/null +++ b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js @@ -0,0 +1,31 @@ +import { NativeModules } from 'react-native'; +const NativeProxy = NativeModules.NativeUnimoduleProxy; +const modulesConstantsKey = 'modulesConstants'; +const exportedMethodsKey = 'exportedMethods'; +const NativeModulesProxy = {}; +if (NativeProxy) { + Object.keys(NativeProxy[exportedMethodsKey]).forEach(moduleName => { + NativeModulesProxy[moduleName] = NativeProxy[modulesConstantsKey][moduleName] || {}; + NativeProxy[exportedMethodsKey][moduleName].forEach(methodInfo => { + NativeModulesProxy[moduleName][methodInfo.name] = (...args) => { + const { key, argumentsCount } = methodInfo; + if (argumentsCount !== args.length) { + return Promise.reject(new Error(`Native method ${moduleName}.${methodInfo.name} expects ${argumentsCount} ${argumentsCount === 1 ? 'argument' : 'arguments'} but received ${args.length}`)); + } + return NativeProxy.callMethod(moduleName, key, args); + }; + }); + // These are called by EventEmitter (which is a wrapper for NativeEventEmitter) + // only on iOS and they use iOS-specific native module, EXReactNativeEventEmitter. + // + // On Android only {start,stop}Observing are called on the native module + // and these should be exported as Expo methods. + NativeModulesProxy[moduleName].addListener = (...args) => NativeModules.UMReactNativeEventEmitter.addProxiedListener(moduleName, ...args); + NativeModulesProxy[moduleName].removeListeners = (...args) => NativeModules.UMReactNativeEventEmitter.removeProxiedListeners(moduleName, ...args); + }); +} +else { + console.warn(`The "UMNativeModulesProxy" native module is not exported through NativeModules; verify that @unimodules/react-native-adapter's native code is linked properly`); +} +export default NativeModulesProxy; +//# sourceMappingURL=NativeModulesProxy.native.js.map \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js.map b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js.map new file mode 100644 index 0000000000000..473be64e798a1 --- /dev/null +++ b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js.map @@ -0,0 +1 @@ +{"version":3,"file":"NativeModulesProxy.native.js","sourceRoot":"","sources":["../src/NativeModulesProxy.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,MAAM,WAAW,GAAG,aAAa,CAAC,oBAAoB,CAAC;AACvD,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAC/C,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAE7C,MAAM,kBAAkB,GAAgD,EAAE,CAAC;AAE3E,IAAI,WAAW,EAAE;IACf,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QAChE,kBAAkB,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACpF,WAAW,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC/D,kBAAkB,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAe,EAAgB,EAAE;gBACrF,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,UAAU,CAAC;gBAC3C,IAAI,cAAc,KAAK,IAAI,CAAC,MAAM,EAAE;oBAClC,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,iBAAiB,UAAU,IAAI,UAAU,CAAC,IAAI,YAAY,cAAc,IACtE,cAAc,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WACtC,iBAAiB,IAAI,CAAC,MAAM,EAAE,CAC/B,CACF,CAAC;iBACH;gBACD,OAAO,WAAW,CAAC,UAAU,CAAC,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YACvD,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,+EAA+E;QAC/E,kFAAkF;QAClF,EAAE;QACF,wEAAwE;QACxE,gDAAgD;QAChD,kBAAkB,CAAC,UAAU,CAAC,CAAC,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CACvD,aAAa,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;QAClF,kBAAkB,CAAC,UAAU,CAAC,CAAC,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAC3D,aAAa,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;CACJ;KAAM;IACL,OAAO,CAAC,IAAI,CACV,+JAA+J,CAChK,CAAC;CACH;AAED,eAAe,kBAAkB,CAAC","sourcesContent":["import { NativeModules } from 'react-native';\n\nimport { ProxyNativeModule } from './NativeModulesProxy.types';\n\nconst NativeProxy = NativeModules.NativeUnimoduleProxy;\nconst modulesConstantsKey = 'modulesConstants';\nconst exportedMethodsKey = 'exportedMethods';\n\nconst NativeModulesProxy: { [moduleName: string]: ProxyNativeModule } = {};\n\nif (NativeProxy) {\n Object.keys(NativeProxy[exportedMethodsKey]).forEach(moduleName => {\n NativeModulesProxy[moduleName] = NativeProxy[modulesConstantsKey][moduleName] || {};\n NativeProxy[exportedMethodsKey][moduleName].forEach(methodInfo => {\n NativeModulesProxy[moduleName][methodInfo.name] = (...args: unknown[]): Promise => {\n const { key, argumentsCount } = methodInfo;\n if (argumentsCount !== args.length) {\n return Promise.reject(\n new Error(\n `Native method ${moduleName}.${methodInfo.name} expects ${argumentsCount} ${\n argumentsCount === 1 ? 'argument' : 'arguments'\n } but received ${args.length}`\n )\n );\n }\n return NativeProxy.callMethod(moduleName, key, args);\n };\n });\n\n // These are called by EventEmitter (which is a wrapper for NativeEventEmitter)\n // only on iOS and they use iOS-specific native module, EXReactNativeEventEmitter.\n //\n // On Android only {start,stop}Observing are called on the native module\n // and these should be exported as Expo methods.\n NativeModulesProxy[moduleName].addListener = (...args) =>\n NativeModules.UMReactNativeEventEmitter.addProxiedListener(moduleName, ...args);\n NativeModulesProxy[moduleName].removeListeners = (...args) =>\n NativeModules.UMReactNativeEventEmitter.removeProxiedListeners(moduleName, ...args);\n });\n} else {\n console.warn(\n `The \"UMNativeModulesProxy\" native module is not exported through NativeModules; verify that @unimodules/react-native-adapter's native code is linked properly`\n );\n}\n\nexport default NativeModulesProxy;\n"]} \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.d.ts b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.d.ts new file mode 100644 index 0000000000000..3cd9cd4105fb1 --- /dev/null +++ b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.d.ts @@ -0,0 +1,5 @@ +export declare type ProxyNativeModule = { + [propertyName: string]: any; + addListener: (eventName: string) => void; + removeListeners: (count: number) => void; +}; diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.js b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.js new file mode 100644 index 0000000000000..ed2e6589f1e5d --- /dev/null +++ b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.js @@ -0,0 +1 @@ +//# sourceMappingURL=NativeModulesProxy.types.js.map \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.js.map b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.js.map new file mode 100644 index 0000000000000..73d19db67e413 --- /dev/null +++ b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"NativeModulesProxy.types.js","sourceRoot":"","sources":["../src/NativeModulesProxy.types.ts"],"names":[],"mappings":"","sourcesContent":["export type ProxyNativeModule = {\n [propertyName: string]: any;\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n};\n"]} \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.d.ts b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.d.ts deleted file mode 100644 index d87c48512f1ad..0000000000000 --- a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -declare const _default: {}; -export default _default; diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.js b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.js deleted file mode 100644 index 60e750d09f602..0000000000000 --- a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.js +++ /dev/null @@ -1,2 +0,0 @@ -export default {}; -//# sourceMappingURL=NativeModulesProxy.web.js.map \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.js.map b/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.js.map deleted file mode 100644 index fbce42e4c6450..0000000000000 --- a/packages/@unimodules/react-native-adapter/build/NativeModulesProxy.web.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"NativeModulesProxy.web.js","sourceRoot":"","sources":["../src/NativeModulesProxy.web.ts"],"names":[],"mappings":"AAAA,eAAe,EAAE,CAAC","sourcesContent":["export default {};\n"]} \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.d.ts b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.d.ts index 922fa78fb1888..480e0e7b3abef 100644 --- a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.d.ts +++ b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.d.ts @@ -1,5 +1,2 @@ import React from 'react'; -/** - * A drop-in replacement for `requireNativeComponent`. - */ export declare function requireNativeViewManager

(viewName: string): React.ComponentType

; diff --git a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.js b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.js index 131ea1325cd9d..88e486953cb56 100644 --- a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.js +++ b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.js @@ -1,55 +1,5 @@ -import omit from 'lodash/omit'; -import pick from 'lodash/pick'; -import React from 'react'; -import { NativeModules, UIManager, ViewPropTypes, 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`. -// NOTE: React Native is moving away from runtime PropTypes and may remove ViewPropTypes, in which -// case we will need another way to separate standard React Native view props from other props, -// which we proxy through the adapter -const ViewPropTypesKeys = Object.keys(ViewPropTypes); -/** - * A drop-in replacement for `requireNativeComponent`. - */ +import { UnavailabilityError } from './errors/UnavailabilityError'; export function requireNativeViewManager(viewName) { - if (__DEV__) { - const { NativeUnimoduleProxy } = NativeModules; - if (!NativeUnimoduleProxy.viewManagersNames.includes(viewName)) { - const exportedViewManagerNames = NativeUnimoduleProxy.viewManagersNames.join(', '); - 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}].`); - } - } - // 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(reactNativeViewName); - const reactNativeUIConfiguration = (UIManager.getViewManagerConfig - ? UIManager.getViewManagerConfig(reactNativeViewName) - : UIManager[reactNativeViewName]) || { - NativeProps: {}, - directEventTypes: {}, - }; - const reactNativeComponentPropNames = [ - 'children', - ...ViewPropTypesKeys, - ...Object.keys(reactNativeUIConfiguration.NativeProps), - ...Object.keys(reactNativeUIConfiguration.directEventTypes), - ]; - // Define a component for universal-module authors to access their native view manager - function NativeComponentAdapter(props, ref) { - // TODO: `omit` may incur a meaningful performance cost across many native components rendered - // in the same update. Profile this and write out a partition function if this is a bottleneck. - const nativeProps = pick(props, reactNativeComponentPropNames); - const proxiedProps = omit(props, reactNativeComponentPropNames); - return React.createElement(ReactNativeComponent, Object.assign({}, nativeProps, { proxiedProperties: proxiedProps, ref: ref })); - } - NativeComponentAdapter.displayName = `Adapter<${viewName}>`; - return React.forwardRef(NativeComponentAdapter); + throw new UnavailabilityError('@unimodules/react-native-adapter', 'requireNativeViewManager'); } //# sourceMappingURL=NativeViewManagerAdapter.js.map \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.js.map b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.js.map index 55491babc5e75..3847540862a2e 100644 --- a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.js.map +++ b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.js.map @@ -1 +1 @@ -{"version":3,"file":"NativeViewManagerAdapter.js","sourceRoot":"","sources":["../src/NativeViewManagerAdapter.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

(viewName: string): React.ComponentType

{\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(\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 ;\n }\n NativeComponentAdapter.displayName = `Adapter<${viewName}>`;\n return React.forwardRef(NativeComponentAdapter);\n}\n"]} \ No newline at end of file +{"version":3,"file":"NativeViewManagerAdapter.js","sourceRoot":"","sources":["../src/NativeViewManagerAdapter.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,MAAM,UAAU,wBAAwB,CAAU,QAAgB;IAChE,MAAM,IAAI,mBAAmB,CAAC,kCAAkC,EAAE,0BAA0B,CAAC,CAAC;AAChG,CAAC","sourcesContent":["import React from 'react';\n\nimport { UnavailabilityError } from './errors/UnavailabilityError';\n\nexport function requireNativeViewManager

(viewName: string): React.ComponentType

{\n throw new UnavailabilityError('@unimodules/react-native-adapter', 'requireNativeViewManager');\n}\n"]} \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.web.d.ts b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.native.d.ts similarity index 67% rename from packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.web.d.ts rename to packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.native.d.ts index 480e0e7b3abef..922fa78fb1888 100644 --- a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.web.d.ts +++ b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.native.d.ts @@ -1,2 +1,5 @@ import React from 'react'; +/** + * A drop-in replacement for `requireNativeComponent`. + */ export declare function requireNativeViewManager

(viewName: string): React.ComponentType

; diff --git a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.native.js b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.native.js new file mode 100644 index 0000000000000..79b477574fc15 --- /dev/null +++ b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.native.js @@ -0,0 +1,55 @@ +import omit from 'lodash/omit'; +import pick from 'lodash/pick'; +import React from 'react'; +import { NativeModules, UIManager, ViewPropTypes, 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`. +// NOTE: React Native is moving away from runtime PropTypes and may remove ViewPropTypes, in which +// case we will need another way to separate standard React Native view props from other props, +// which we proxy through the adapter +const ViewPropTypesKeys = Object.keys(ViewPropTypes); +/** + * A drop-in replacement for `requireNativeComponent`. + */ +export function requireNativeViewManager(viewName) { + if (__DEV__) { + const { NativeUnimoduleProxy } = NativeModules; + if (!NativeUnimoduleProxy.viewManagersNames.includes(viewName)) { + const exportedViewManagerNames = NativeUnimoduleProxy.viewManagersNames.join(', '); + 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}].`); + } + } + // 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(reactNativeViewName); + const reactNativeUIConfiguration = (UIManager.getViewManagerConfig + ? UIManager.getViewManagerConfig(reactNativeViewName) + : UIManager[reactNativeViewName]) || { + NativeProps: {}, + directEventTypes: {}, + }; + const reactNativeComponentPropNames = [ + 'children', + ...ViewPropTypesKeys, + ...Object.keys(reactNativeUIConfiguration.NativeProps), + ...Object.keys(reactNativeUIConfiguration.directEventTypes), + ]; + // Define a component for universal-module authors to access their native view manager + function NativeComponentAdapter(props, ref) { + // TODO: `omit` may incur a meaningful performance cost across many native components rendered + // in the same update. Profile this and write out a partition function if this is a bottleneck. + const nativeProps = pick(props, reactNativeComponentPropNames); + const proxiedProps = omit(props, reactNativeComponentPropNames); + return React.createElement(ReactNativeComponent, Object.assign({}, nativeProps, { proxiedProperties: proxiedProps, ref: ref })); + } + NativeComponentAdapter.displayName = `Adapter<${viewName}>`; + return React.forwardRef(NativeComponentAdapter); +} +//# sourceMappingURL=NativeViewManagerAdapter.native.js.map \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.native.js.map b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.native.js.map new file mode 100644 index 0000000000000..f63f581763d69 --- /dev/null +++ b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.native.js.map @@ -0,0 +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

(viewName: string): React.ComponentType

{\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(\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 ;\n }\n NativeComponentAdapter.displayName = `Adapter<${viewName}>`;\n return React.forwardRef(NativeComponentAdapter);\n}\n"]} \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.web.js b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.web.js deleted file mode 100644 index 62b516f12ee44..0000000000000 --- a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.web.js +++ /dev/null @@ -1,5 +0,0 @@ -import { UnavailabilityError } from './errors/UnavailabilityError'; -export function requireNativeViewManager(viewName) { - throw new UnavailabilityError('@unimodules/react-native-adapter', 'requireNativeViewManager'); -} -//# sourceMappingURL=NativeViewManagerAdapter.web.js.map \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.web.js.map b/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.web.js.map deleted file mode 100644 index d4f0f6e59ef25..0000000000000 --- a/packages/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.web.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"NativeViewManagerAdapter.web.js","sourceRoot":"","sources":["../src/NativeViewManagerAdapter.web.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,MAAM,UAAU,wBAAwB,CAAU,QAAgB;IAChE,MAAM,IAAI,mBAAmB,CAAC,kCAAkC,EAAE,0BAA0B,CAAC,CAAC;AAChG,CAAC","sourcesContent":["import React from 'react';\n\nimport { UnavailabilityError } from './errors/UnavailabilityError';\n\nexport function requireNativeViewManager

(viewName: string): React.ComponentType

{\n throw new UnavailabilityError('@unimodules/react-native-adapter', 'requireNativeViewManager');\n}\n"]} \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/index.d.ts b/packages/@unimodules/react-native-adapter/build/index.d.ts index c3b1915515687..5272614a2e15d 100644 --- a/packages/@unimodules/react-native-adapter/build/index.d.ts +++ b/packages/@unimodules/react-native-adapter/build/index.d.ts @@ -1,5 +1,6 @@ import { EventEmitter, Subscription } from './EventEmitter'; -import NativeModulesProxy, { ProxyNativeModule } from './NativeModulesProxy'; +import NativeModulesProxy from './NativeModulesProxy'; +import { ProxyNativeModule } from './NativeModulesProxy.types'; import { requireNativeViewManager } from './NativeViewManagerAdapter'; import Platform from './Platform'; import SyntheticPlatformEmitter from './SyntheticPlatformEmitter'; diff --git a/packages/@unimodules/react-native-adapter/build/index.js.map b/packages/@unimodules/react-native-adapter/build/index.js.map index a3dfaab8ac4d6..eb4fca6bd4b87 100644 --- a/packages/@unimodules/react-native-adapter/build/index.js.map +++ b/packages/@unimodules/react-native-adapter/build/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAC5D,OAAO,kBAAyC,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,sFAAsF;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAElB,QAAQ,EAER,wBAAwB,EACxB,wBAAwB;AACxB,SAAS;AACT,UAAU,EACV,mBAAmB,GACpB,CAAC","sourcesContent":["import { EventEmitter, Subscription } from './EventEmitter';\nimport NativeModulesProxy, { ProxyNativeModule } from './NativeModulesProxy';\nimport { requireNativeViewManager } from './NativeViewManagerAdapter';\nimport Platform from './Platform';\nimport SyntheticPlatformEmitter from './SyntheticPlatformEmitter';\n// RCTDeviceEventEmitter pending https://github.com/necolas/react-native-web/pull/1402\nimport { CodedError } from './errors/CodedError';\nimport { UnavailabilityError } from './errors/UnavailabilityError';\nimport { RCTDeviceEventEmitter } from './nativeEmitters';\n\nexport {\n RCTDeviceEventEmitter,\n EventEmitter,\n NativeModulesProxy,\n ProxyNativeModule,\n Platform,\n Subscription,\n SyntheticPlatformEmitter,\n requireNativeViewManager,\n // Errors\n CodedError,\n UnavailabilityError,\n};\n"]} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAC5D,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,sFAAsF;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAElB,QAAQ,EAER,wBAAwB,EACxB,wBAAwB;AACxB,SAAS;AACT,UAAU,EACV,mBAAmB,GACpB,CAAC","sourcesContent":["import { EventEmitter, Subscription } from './EventEmitter';\nimport NativeModulesProxy from './NativeModulesProxy';\nimport { ProxyNativeModule } from './NativeModulesProxy.types';\nimport { requireNativeViewManager } from './NativeViewManagerAdapter';\nimport Platform from './Platform';\nimport SyntheticPlatformEmitter from './SyntheticPlatformEmitter';\n// RCTDeviceEventEmitter pending https://github.com/necolas/react-native-web/pull/1402\nimport { CodedError } from './errors/CodedError';\nimport { UnavailabilityError } from './errors/UnavailabilityError';\nimport { RCTDeviceEventEmitter } from './nativeEmitters';\n\nexport {\n RCTDeviceEventEmitter,\n EventEmitter,\n NativeModulesProxy,\n ProxyNativeModule,\n Platform,\n Subscription,\n SyntheticPlatformEmitter,\n requireNativeViewManager,\n // Errors\n CodedError,\n UnavailabilityError,\n};\n"]} \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/nativeEmitters.d.ts b/packages/@unimodules/react-native-adapter/build/nativeEmitters.d.ts index 5c81cb6111fff..06dde91c4e08a 100644 --- a/packages/@unimodules/react-native-adapter/build/nativeEmitters.d.ts +++ b/packages/@unimodules/react-native-adapter/build/nativeEmitters.d.ts @@ -1,3 +1,3 @@ -import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter'; -import RCTEventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter'; +import RCTDeviceEventEmitter from 'react-native-web/dist/vendor/react-native/NativeEventEmitter/RCTDeviceEventEmitter'; +import RCTEventEmitter from 'react-native-web/dist/vendor/react-native/emitter/EventEmitter'; export { RCTEventEmitter, RCTDeviceEventEmitter }; diff --git a/packages/@unimodules/react-native-adapter/build/nativeEmitters.js b/packages/@unimodules/react-native-adapter/build/nativeEmitters.js index 5f774bca3af77..22bc3219c544a 100644 --- a/packages/@unimodules/react-native-adapter/build/nativeEmitters.js +++ b/packages/@unimodules/react-native-adapter/build/nativeEmitters.js @@ -1,4 +1,4 @@ -import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter'; -import RCTEventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter'; +import RCTDeviceEventEmitter from 'react-native-web/dist/vendor/react-native/NativeEventEmitter/RCTDeviceEventEmitter'; +import RCTEventEmitter from 'react-native-web/dist/vendor/react-native/emitter/EventEmitter'; export { RCTEventEmitter, RCTDeviceEventEmitter }; //# sourceMappingURL=nativeEmitters.js.map \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/nativeEmitters.js.map b/packages/@unimodules/react-native-adapter/build/nativeEmitters.js.map index 56eef680c023f..77bef22ef4626 100644 --- a/packages/@unimodules/react-native-adapter/build/nativeEmitters.js.map +++ b/packages/@unimodules/react-native-adapter/build/nativeEmitters.js.map @@ -1 +1 @@ -{"version":3,"file":"nativeEmitters.js","sourceRoot":"","sources":["../src/nativeEmitters.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,2DAA2D,CAAC;AAC9F,OAAO,eAAe,MAAM,oDAAoD,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,CAAC","sourcesContent":["import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter';\nimport RCTEventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';\n\nexport { RCTEventEmitter, RCTDeviceEventEmitter };\n"]} \ No newline at end of file +{"version":3,"file":"nativeEmitters.js","sourceRoot":"","sources":["../src/nativeEmitters.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,oFAAoF,CAAC;AACvH,OAAO,eAAe,MAAM,gEAAgE,CAAC;AAE7F,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,CAAC","sourcesContent":["import RCTDeviceEventEmitter from 'react-native-web/dist/vendor/react-native/NativeEventEmitter/RCTDeviceEventEmitter';\nimport RCTEventEmitter from 'react-native-web/dist/vendor/react-native/emitter/EventEmitter';\n\nexport { RCTEventEmitter, RCTDeviceEventEmitter };\n"]} \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/nativeEmitters.native.d.ts b/packages/@unimodules/react-native-adapter/build/nativeEmitters.native.d.ts new file mode 100644 index 0000000000000..5c81cb6111fff --- /dev/null +++ b/packages/@unimodules/react-native-adapter/build/nativeEmitters.native.d.ts @@ -0,0 +1,3 @@ +import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter'; +import RCTEventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter'; +export { RCTEventEmitter, RCTDeviceEventEmitter }; diff --git a/packages/@unimodules/react-native-adapter/build/nativeEmitters.native.js b/packages/@unimodules/react-native-adapter/build/nativeEmitters.native.js new file mode 100644 index 0000000000000..a667aac54585f --- /dev/null +++ b/packages/@unimodules/react-native-adapter/build/nativeEmitters.native.js @@ -0,0 +1,4 @@ +import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter'; +import RCTEventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter'; +export { RCTEventEmitter, RCTDeviceEventEmitter }; +//# sourceMappingURL=nativeEmitters.native.js.map \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/nativeEmitters.native.js.map b/packages/@unimodules/react-native-adapter/build/nativeEmitters.native.js.map new file mode 100644 index 0000000000000..ba5435718be8d --- /dev/null +++ b/packages/@unimodules/react-native-adapter/build/nativeEmitters.native.js.map @@ -0,0 +1 @@ +{"version":3,"file":"nativeEmitters.native.js","sourceRoot":"","sources":["../src/nativeEmitters.native.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,2DAA2D,CAAC;AAC9F,OAAO,eAAe,MAAM,oDAAoD,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,CAAC","sourcesContent":["import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter';\nimport RCTEventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';\n\nexport { RCTEventEmitter, RCTDeviceEventEmitter };\n"]} \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/nativeEmitters.web.d.ts b/packages/@unimodules/react-native-adapter/build/nativeEmitters.web.d.ts deleted file mode 100644 index 06dde91c4e08a..0000000000000 --- a/packages/@unimodules/react-native-adapter/build/nativeEmitters.web.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import RCTDeviceEventEmitter from 'react-native-web/dist/vendor/react-native/NativeEventEmitter/RCTDeviceEventEmitter'; -import RCTEventEmitter from 'react-native-web/dist/vendor/react-native/emitter/EventEmitter'; -export { RCTEventEmitter, RCTDeviceEventEmitter }; diff --git a/packages/@unimodules/react-native-adapter/build/nativeEmitters.web.js b/packages/@unimodules/react-native-adapter/build/nativeEmitters.web.js deleted file mode 100644 index 20cd16920a1be..0000000000000 --- a/packages/@unimodules/react-native-adapter/build/nativeEmitters.web.js +++ /dev/null @@ -1,4 +0,0 @@ -import RCTDeviceEventEmitter from 'react-native-web/dist/vendor/react-native/NativeEventEmitter/RCTDeviceEventEmitter'; -import RCTEventEmitter from 'react-native-web/dist/vendor/react-native/emitter/EventEmitter'; -export { RCTEventEmitter, RCTDeviceEventEmitter }; -//# sourceMappingURL=nativeEmitters.web.js.map \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/build/nativeEmitters.web.js.map b/packages/@unimodules/react-native-adapter/build/nativeEmitters.web.js.map deleted file mode 100644 index 340f2dd803c8b..0000000000000 --- a/packages/@unimodules/react-native-adapter/build/nativeEmitters.web.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"nativeEmitters.web.js","sourceRoot":"","sources":["../src/nativeEmitters.web.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,oFAAoF,CAAC;AACvH,OAAO,eAAe,MAAM,gEAAgE,CAAC;AAE7F,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,CAAC","sourcesContent":["import RCTDeviceEventEmitter from 'react-native-web/dist/vendor/react-native/NativeEventEmitter/RCTDeviceEventEmitter';\nimport RCTEventEmitter from 'react-native-web/dist/vendor/react-native/emitter/EventEmitter';\n\nexport { RCTEventEmitter, RCTDeviceEventEmitter };\n"]} \ No newline at end of file diff --git a/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.native.ts b/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.native.ts new file mode 100644 index 0000000000000..ae3081b0ad47b --- /dev/null +++ b/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.native.ts @@ -0,0 +1,46 @@ +import { NativeModules } from 'react-native'; + +import { ProxyNativeModule } from './NativeModulesProxy.types'; + +const NativeProxy = NativeModules.NativeUnimoduleProxy; +const modulesConstantsKey = 'modulesConstants'; +const exportedMethodsKey = 'exportedMethods'; + +const NativeModulesProxy: { [moduleName: string]: ProxyNativeModule } = {}; + +if (NativeProxy) { + Object.keys(NativeProxy[exportedMethodsKey]).forEach(moduleName => { + NativeModulesProxy[moduleName] = NativeProxy[modulesConstantsKey][moduleName] || {}; + NativeProxy[exportedMethodsKey][moduleName].forEach(methodInfo => { + NativeModulesProxy[moduleName][methodInfo.name] = (...args: unknown[]): Promise => { + const { key, argumentsCount } = methodInfo; + if (argumentsCount !== args.length) { + return Promise.reject( + new Error( + `Native method ${moduleName}.${methodInfo.name} expects ${argumentsCount} ${ + argumentsCount === 1 ? 'argument' : 'arguments' + } but received ${args.length}` + ) + ); + } + return NativeProxy.callMethod(moduleName, key, args); + }; + }); + + // These are called by EventEmitter (which is a wrapper for NativeEventEmitter) + // only on iOS and they use iOS-specific native module, EXReactNativeEventEmitter. + // + // On Android only {start,stop}Observing are called on the native module + // and these should be exported as Expo methods. + NativeModulesProxy[moduleName].addListener = (...args) => + NativeModules.UMReactNativeEventEmitter.addProxiedListener(moduleName, ...args); + NativeModulesProxy[moduleName].removeListeners = (...args) => + NativeModules.UMReactNativeEventEmitter.removeProxiedListeners(moduleName, ...args); + }); +} else { + console.warn( + `The "UMNativeModulesProxy" native module is not exported through NativeModules; verify that @unimodules/react-native-adapter's native code is linked properly` + ); +} + +export default NativeModulesProxy; diff --git a/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.ts b/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.ts index ba3afd8b12cc8..af6ec291d917f 100644 --- a/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.ts +++ b/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.ts @@ -1,50 +1,4 @@ -import { NativeModules } from 'react-native'; +import { ProxyNativeModule } from './NativeModulesProxy.types'; -const NativeProxy = NativeModules.NativeUnimoduleProxy; -const modulesConstantsKey = 'modulesConstants'; -const exportedMethodsKey = 'exportedMethods'; - -export type ProxyNativeModule = { - [propertyName: string]: any; - addListener: (eventName: string) => void; - removeListeners: (count: number) => void; -}; - -const NativeModulesProxy: { [moduleName: string]: ProxyNativeModule } = {}; - -if (NativeProxy) { - Object.keys(NativeProxy[exportedMethodsKey]).forEach(moduleName => { - NativeModulesProxy[moduleName] = NativeProxy[modulesConstantsKey][moduleName] || {}; - NativeProxy[exportedMethodsKey][moduleName].forEach(methodInfo => { - NativeModulesProxy[moduleName][methodInfo.name] = (...args: unknown[]): Promise => { - const { key, argumentsCount } = methodInfo; - if (argumentsCount !== args.length) { - return Promise.reject( - new Error( - `Native method ${moduleName}.${methodInfo.name} expects ${argumentsCount} ${ - argumentsCount === 1 ? 'argument' : 'arguments' - } but received ${args.length}` - ) - ); - } - return NativeProxy.callMethod(moduleName, key, args); - }; - }); - - // These are called by EventEmitter (which is a wrapper for NativeEventEmitter) - // only on iOS and they use iOS-specific native module, EXReactNativeEventEmitter. - // - // On Android only {start,stop}Observing are called on the native module - // and these should be exported as Expo methods. - NativeModulesProxy[moduleName].addListener = (...args) => - NativeModules.UMReactNativeEventEmitter.addProxiedListener(moduleName, ...args); - NativeModulesProxy[moduleName].removeListeners = (...args) => - NativeModules.UMReactNativeEventEmitter.removeProxiedListeners(moduleName, ...args); - }); -} else { - console.warn( - `The "UMNativeModulesProxy" native module is not exported through NativeModules; verify that @unimodules/react-native-adapter's native code is linked properly` - ); -} - -export default NativeModulesProxy; +// We default to an empty object shim wherever we don't have an environment-specific implementation +export default {} as { [moduleName: string]: ProxyNativeModule }; diff --git a/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.types.ts b/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.types.ts new file mode 100644 index 0000000000000..4cabf50812d8c --- /dev/null +++ b/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.types.ts @@ -0,0 +1,5 @@ +export type ProxyNativeModule = { + [propertyName: string]: any; + addListener: (eventName: string) => void; + removeListeners: (count: number) => void; +}; diff --git a/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.web.ts b/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.web.ts deleted file mode 100644 index ff8b4c56321a3..0000000000000 --- a/packages/@unimodules/react-native-adapter/src/NativeModulesProxy.web.ts +++ /dev/null @@ -1 +0,0 @@ -export default {}; diff --git a/packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.native.tsx b/packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.native.tsx new file mode 100644 index 0000000000000..ffe9ba0b410d0 --- /dev/null +++ b/packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.native.tsx @@ -0,0 +1,67 @@ +import omit from 'lodash/omit'; +import pick from 'lodash/pick'; +import React from 'react'; +import { NativeModules, UIManager, ViewPropTypes, 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`. + +// NOTE: React Native is moving away from runtime PropTypes and may remove ViewPropTypes, in which +// case we will need another way to separate standard React Native view props from other props, +// which we proxy through the adapter +const ViewPropTypesKeys = Object.keys(ViewPropTypes); + +type NativeExpoComponentProps = { + proxiedProperties: object; +}; + +/** + * A drop-in replacement for `requireNativeComponent`. + */ +export function requireNativeViewManager

(viewName: string): React.ComponentType

{ + if (__DEV__) { + const { NativeUnimoduleProxy } = NativeModules; + if (!NativeUnimoduleProxy.viewManagersNames.includes(viewName)) { + const exportedViewManagerNames = NativeUnimoduleProxy.viewManagersNames.join(', '); + 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}].` + ); + } + } + + // 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( + reactNativeViewName + ); + const reactNativeUIConfiguration = (UIManager.getViewManagerConfig + ? UIManager.getViewManagerConfig(reactNativeViewName) + : UIManager[reactNativeViewName]) || { + NativeProps: {}, + directEventTypes: {}, + }; + const reactNativeComponentPropNames = [ + 'children', + ...ViewPropTypesKeys, + ...Object.keys(reactNativeUIConfiguration.NativeProps), + ...Object.keys(reactNativeUIConfiguration.directEventTypes), + ]; + + // Define a component for universal-module authors to access their native view manager + function NativeComponentAdapter(props, ref) { + // TODO: `omit` may incur a meaningful performance cost across many native components rendered + // in the same update. Profile this and write out a partition function if this is a bottleneck. + const nativeProps = pick(props, reactNativeComponentPropNames); + const proxiedProps = omit(props, reactNativeComponentPropNames); + return ; + } + NativeComponentAdapter.displayName = `Adapter<${viewName}>`; + return React.forwardRef(NativeComponentAdapter); +} diff --git a/packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.tsx b/packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.tsx index ffe9ba0b410d0..909a1e7baa81a 100644 --- a/packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.tsx +++ b/packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.tsx @@ -1,67 +1,7 @@ -import omit from 'lodash/omit'; -import pick from 'lodash/pick'; import React from 'react'; -import { NativeModules, UIManager, ViewPropTypes, 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`. +import { UnavailabilityError } from './errors/UnavailabilityError'; -// NOTE: React Native is moving away from runtime PropTypes and may remove ViewPropTypes, in which -// case we will need another way to separate standard React Native view props from other props, -// which we proxy through the adapter -const ViewPropTypesKeys = Object.keys(ViewPropTypes); - -type NativeExpoComponentProps = { - proxiedProperties: object; -}; - -/** - * A drop-in replacement for `requireNativeComponent`. - */ export function requireNativeViewManager

(viewName: string): React.ComponentType

{ - if (__DEV__) { - const { NativeUnimoduleProxy } = NativeModules; - if (!NativeUnimoduleProxy.viewManagersNames.includes(viewName)) { - const exportedViewManagerNames = NativeUnimoduleProxy.viewManagersNames.join(', '); - 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}].` - ); - } - } - - // 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( - reactNativeViewName - ); - const reactNativeUIConfiguration = (UIManager.getViewManagerConfig - ? UIManager.getViewManagerConfig(reactNativeViewName) - : UIManager[reactNativeViewName]) || { - NativeProps: {}, - directEventTypes: {}, - }; - const reactNativeComponentPropNames = [ - 'children', - ...ViewPropTypesKeys, - ...Object.keys(reactNativeUIConfiguration.NativeProps), - ...Object.keys(reactNativeUIConfiguration.directEventTypes), - ]; - - // Define a component for universal-module authors to access their native view manager - function NativeComponentAdapter(props, ref) { - // TODO: `omit` may incur a meaningful performance cost across many native components rendered - // in the same update. Profile this and write out a partition function if this is a bottleneck. - const nativeProps = pick(props, reactNativeComponentPropNames); - const proxiedProps = omit(props, reactNativeComponentPropNames); - return ; - } - NativeComponentAdapter.displayName = `Adapter<${viewName}>`; - return React.forwardRef(NativeComponentAdapter); + throw new UnavailabilityError('@unimodules/react-native-adapter', 'requireNativeViewManager'); } diff --git a/packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.web.tsx b/packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.web.tsx deleted file mode 100644 index 909a1e7baa81a..0000000000000 --- a/packages/@unimodules/react-native-adapter/src/NativeViewManagerAdapter.web.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react'; - -import { UnavailabilityError } from './errors/UnavailabilityError'; - -export function requireNativeViewManager

(viewName: string): React.ComponentType

{ - throw new UnavailabilityError('@unimodules/react-native-adapter', 'requireNativeViewManager'); -} diff --git a/packages/@unimodules/react-native-adapter/src/index.ts b/packages/@unimodules/react-native-adapter/src/index.ts index bb2ba6139036b..c0973c90adae1 100644 --- a/packages/@unimodules/react-native-adapter/src/index.ts +++ b/packages/@unimodules/react-native-adapter/src/index.ts @@ -1,5 +1,6 @@ import { EventEmitter, Subscription } from './EventEmitter'; -import NativeModulesProxy, { ProxyNativeModule } from './NativeModulesProxy'; +import NativeModulesProxy from './NativeModulesProxy'; +import { ProxyNativeModule } from './NativeModulesProxy.types'; import { requireNativeViewManager } from './NativeViewManagerAdapter'; import Platform from './Platform'; import SyntheticPlatformEmitter from './SyntheticPlatformEmitter'; diff --git a/packages/@unimodules/react-native-adapter/src/nativeEmitters.native.ts b/packages/@unimodules/react-native-adapter/src/nativeEmitters.native.ts new file mode 100644 index 0000000000000..0394e222498b4 --- /dev/null +++ b/packages/@unimodules/react-native-adapter/src/nativeEmitters.native.ts @@ -0,0 +1,4 @@ +import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter'; +import RCTEventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter'; + +export { RCTEventEmitter, RCTDeviceEventEmitter }; diff --git a/packages/@unimodules/react-native-adapter/src/nativeEmitters.ts b/packages/@unimodules/react-native-adapter/src/nativeEmitters.ts index 0394e222498b4..ef84013b84761 100644 --- a/packages/@unimodules/react-native-adapter/src/nativeEmitters.ts +++ b/packages/@unimodules/react-native-adapter/src/nativeEmitters.ts @@ -1,4 +1,4 @@ -import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter'; -import RCTEventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter'; +import RCTDeviceEventEmitter from 'react-native-web/dist/vendor/react-native/NativeEventEmitter/RCTDeviceEventEmitter'; +import RCTEventEmitter from 'react-native-web/dist/vendor/react-native/emitter/EventEmitter'; export { RCTEventEmitter, RCTDeviceEventEmitter }; diff --git a/packages/@unimodules/react-native-adapter/src/nativeEmitters.web.ts b/packages/@unimodules/react-native-adapter/src/nativeEmitters.web.ts deleted file mode 100644 index ef84013b84761..0000000000000 --- a/packages/@unimodules/react-native-adapter/src/nativeEmitters.web.ts +++ /dev/null @@ -1,4 +0,0 @@ -import RCTDeviceEventEmitter from 'react-native-web/dist/vendor/react-native/NativeEventEmitter/RCTDeviceEventEmitter'; -import RCTEventEmitter from 'react-native-web/dist/vendor/react-native/emitter/EventEmitter'; - -export { RCTEventEmitter, RCTDeviceEventEmitter };