expo-modules-core 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +1 -1
  3. package/android/ExpoModulesCorePlugin.gradle +15 -0
  4. package/android/build.gradle +46 -32
  5. package/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java +5 -5
  6. package/android/src/main/java/expo/modules/adapters/react/services/UIManagerModuleWrapper.java +13 -0
  7. package/android/src/main/java/expo/modules/core/ViewManager.java +9 -0
  8. package/android/src/main/java/expo/modules/core/interfaces/JavaScriptContextProvider.java +4 -0
  9. package/android/src/main/java/expo/modules/core/interfaces/ReactActivityHandler.java +37 -1
  10. package/android/src/main/java/expo/modules/core/interfaces/ReactNativeHostHandler.java +19 -0
  11. package/android/src/main/java/expo/modules/core/interfaces/services/UIManager.java +2 -0
  12. package/android/src/main/java/expo/modules/kotlin/AppContext.kt +13 -5
  13. package/android/src/main/java/expo/modules/kotlin/KPromiseWrapper.kt +2 -13
  14. package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +11 -5
  15. package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +5 -1
  16. package/android/src/main/java/expo/modules/kotlin/ModuleRegistry.kt +17 -0
  17. package/android/src/main/java/expo/modules/kotlin/callbacks/ViewCallback.kt +14 -3
  18. package/android/src/main/java/expo/modules/kotlin/events/EventEmitter.kt +13 -0
  19. package/android/src/main/java/expo/modules/kotlin/events/KModuleEventEmitterWrapper.kt +102 -0
  20. package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +25 -1
  21. package/android/src/main/java/expo/modules/kotlin/{methods/AnyMethod.kt → functions/AnyFunction.kt} +6 -5
  22. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +15 -0
  23. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +61 -0
  24. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromise.kt +15 -0
  25. package/android/src/main/java/expo/modules/kotlin/functions/AsyncSuspendFunction.kt +36 -0
  26. package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +14 -0
  27. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +176 -27
  28. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionData.kt +2 -2
  29. package/android/src/main/java/expo/modules/kotlin/records/FieldValidator.kt +139 -0
  30. package/android/src/main/java/expo/modules/kotlin/records/Record.kt +0 -39
  31. package/android/src/main/java/expo/modules/kotlin/records/RecordTypeConverter.kt +59 -10
  32. package/android/src/main/java/expo/modules/kotlin/records/Required.kt +5 -0
  33. package/android/src/main/java/expo/modules/kotlin/records/ValidationBinder.kt +110 -0
  34. package/android/src/main/java/expo/modules/kotlin/records/Validators.kt +61 -0
  35. package/android/src/main/java/expo/modules/kotlin/types/JSTypeConverter.kt +35 -0
  36. package/android/src/main/java/expo/modules/kotlin/types/JSTypeConverterHelper.kt +148 -0
  37. package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +9 -1
  38. package/android/src/main/java/expo/modules/kotlin/views/GroupViewManagerWrapper.kt +49 -0
  39. package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinition.kt +18 -0
  40. package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinitionBuilder.kt +64 -0
  41. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinition.kt +4 -1
  42. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +15 -2
  43. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerWrapperDelegate.kt +3 -0
  44. package/build/NativeModulesProxy.native.d.ts +0 -4
  45. package/build/NativeModulesProxy.native.d.ts.map +1 -1
  46. package/build/NativeModulesProxy.native.js +1 -14
  47. package/build/NativeModulesProxy.native.js.map +1 -1
  48. package/build/NativeModulesProxy.types.d.ts +0 -3
  49. package/build/NativeModulesProxy.types.d.ts.map +1 -1
  50. package/build/NativeModulesProxy.types.js.map +1 -1
  51. package/build/NativeViewManagerAdapter.native.d.ts.map +1 -1
  52. package/build/NativeViewManagerAdapter.native.js +9 -33
  53. package/build/NativeViewManagerAdapter.native.js.map +1 -1
  54. package/build/sweet/NativeErrorManager.js +1 -1
  55. package/build/sweet/NativeErrorManager.js.map +1 -1
  56. package/ios/AppDelegates/EXAppDelegatesLoader.m +4 -8
  57. package/ios/AppDelegates/ExpoAppDelegate.swift +4 -10
  58. package/ios/EXAppDefines.h +1 -0
  59. package/ios/EXAppDefines.m +6 -0
  60. package/ios/EXUtilities.h +2 -0
  61. package/ios/EXUtilities.m +12 -0
  62. package/ios/ExpoModulesCore.h +4 -0
  63. package/ios/ExpoModulesCore.podspec +4 -2
  64. package/ios/Interfaces/FileSystem/EXFileSystemInterface.h +1 -1
  65. package/ios/Interfaces/TaskManager/EXTaskServiceInterface.h +1 -0
  66. package/ios/JSI/{JSIConversions.h → EXJSIConversions.h} +4 -1
  67. package/ios/JSI/{JSIConversions.mm → EXJSIConversions.mm} +16 -5
  68. package/ios/JSI/{JSIInstaller.h → EXJSIInstaller.h} +3 -3
  69. package/ios/JSI/EXJSIInstaller.mm +17 -0
  70. package/ios/JSI/{ExpoModulesProxySpec.h → EXJSIUtils.h} +0 -9
  71. package/ios/JSI/{ExpoModulesProxySpec.mm → EXJSIUtils.mm} +4 -48
  72. package/ios/JSI/EXJavaScriptObject.h +97 -0
  73. package/ios/JSI/EXJavaScriptObject.mm +121 -0
  74. package/ios/JSI/{JavaScriptRuntime.h → EXJavaScriptRuntime.h} +27 -8
  75. package/ios/JSI/EXJavaScriptRuntime.mm +153 -0
  76. package/ios/JSI/EXJavaScriptValue.h +57 -0
  77. package/ios/JSI/EXJavaScriptValue.mm +166 -0
  78. package/ios/JSI/ExpoModulesHostObject.mm +2 -1
  79. package/ios/JSI/JavaScriptRuntime.swift +32 -0
  80. package/ios/JSI/JavaScriptValue.swift +94 -0
  81. package/ios/ModuleRegistryAdapter/EXModuleRegistryAdapter.m +1 -11
  82. package/ios/NativeModulesProxy/EXNativeModulesProxy.h +2 -2
  83. package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +24 -22
  84. package/ios/ReactDelegates/EXReactCompatibleHelpers.h +18 -0
  85. package/ios/ReactDelegates/EXReactCompatibleHelpers.m +19 -0
  86. package/ios/ReactDelegates/ExpoReactDelegate.swift +2 -2
  87. package/ios/ReactDelegates/ExpoReactDelegateHandler.swift +1 -1
  88. package/ios/Swift/AppContext.swift +27 -1
  89. package/ios/Swift/Functions/AsyncFunction.swift +17 -0
  90. package/ios/Swift/Functions/ConcreteFunction.swift +6 -1
  91. package/ios/Swift/JavaScriptUtils.swift +11 -0
  92. package/ios/Swift/ModuleHolder.swift +14 -3
  93. package/ios/Swift/ModulesProvider.swift +3 -10
  94. package/ios/Swift/Objects/ObjectDefinitionComponents.swift +176 -0
  95. package/ios/Swift/SwiftInteropBridge.swift +14 -5
  96. package/ios/Swift/Views/ComponentData.swift +2 -1
  97. package/ios/Swift/Views/ExpoView.swift +8 -0
  98. package/ios/Swift.h +5 -0
  99. package/ios/Tests/ArgumentTypeSpec.swift +2 -3
  100. package/ios/Tests/ConstantsSpec.swift +2 -3
  101. package/ios/Tests/ConvertiblesSpec.swift +2 -3
  102. package/ios/Tests/ExceptionsSpec.swift +2 -3
  103. package/ios/Tests/ExpoModulesSpec.swift +76 -0
  104. package/ios/Tests/FunctionSpec.swift +2 -3
  105. package/ios/Tests/FunctionWithConvertiblesSpec.swift +2 -3
  106. package/ios/Tests/JavaScriptObjectSpec.swift +97 -0
  107. package/ios/Tests/JavaScriptRuntimeSpec.swift +94 -0
  108. package/ios/Tests/ModuleEventListenersSpec.swift +2 -3
  109. package/ios/Tests/ModuleRegistrySpec.swift +2 -3
  110. package/ios/Tests/RecordSpec.swift +2 -3
  111. package/package.json +2 -2
  112. package/src/NativeModulesProxy.native.ts +2 -22
  113. package/src/NativeModulesProxy.types.ts +0 -8
  114. package/src/NativeViewManagerAdapter.native.tsx +12 -28
  115. package/src/sweet/NativeErrorManager.ts +1 -1
  116. package/android/src/main/java/expo/modules/kotlin/events/KEventEmitterWrapper.kt +0 -26
  117. package/android/src/main/java/expo/modules/kotlin/methods/Method.kt +0 -14
  118. package/android/src/main/java/expo/modules/kotlin/methods/PromiseMethod.kt +0 -15
  119. package/ios/JSI/JSIInstaller.mm +0 -34
  120. package/ios/JSI/JavaScriptObject.h +0 -60
  121. package/ios/JSI/JavaScriptObject.mm +0 -93
  122. package/ios/JSI/JavaScriptRuntime.mm +0 -102
  123. package/ios/NativeModulesProxy/EXComponentDataCompatibleWrapper.h +0 -16
  124. package/ios/NativeModulesProxy/EXComponentDataCompatibleWrapper.m +0 -28
@@ -1 +1 @@
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\nexport type TurboNativeModuleProxy = {\n callMethodAsync: <ReturnType>(\n moduleName: string,\n methodName: string,\n args: any[]\n ) => Promise<ReturnType>;\n};\n"]}
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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"NativeViewManagerAdapter.native.d.ts","sourceRoot":"","sources":["../src/NativeViewManagerAdapter.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAqB1B;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAqC1F"}
1
+ {"version":3,"file":"NativeViewManagerAdapter.native.d.ts","sourceRoot":"","sources":["../src/NativeViewManagerAdapter.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAgB1B;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CA0B1F"}
@@ -1,48 +1,24 @@
1
1
  import React from 'react';
2
- import { NativeModules, UIManager, ViewPropTypes, requireNativeComponent } from 'react-native';
3
- // To make the transition from React Native's `requireNativeComponent` to Expo's
4
- // `requireNativeViewManager` as easy as possible, `requireNativeViewManager` is a drop-in
5
- // replacement for `requireNativeComponent`.
6
- //
7
- // For each view manager, we create a wrapper component that accepts all of the props available to
8
- // the author of the universal module. This wrapper component splits the props into two sets: props
9
- // passed to React Native's View (ex: style, testID) and custom view props, which are passed to the
10
- // adapter view component in a prop called `proxiedProperties`.
11
- // NOTE: React Native is moving away from runtime PropTypes and may remove ViewPropTypes, in which
12
- // case we will need another way to separate standard React Native view props from other props,
13
- // which we proxy through the adapter
14
- const ViewPropTypesKeys = Object.keys(ViewPropTypes);
2
+ import { NativeModules, requireNativeComponent } from 'react-native';
15
3
  /**
16
4
  * A drop-in replacement for `requireNativeComponent`.
17
5
  */
18
6
  export function requireNativeViewManager(viewName) {
19
- if (__DEV__) {
20
- const { NativeUnimoduleProxy } = NativeModules;
21
- if (!NativeUnimoduleProxy.viewManagersNames.includes(viewName)) {
22
- const exportedViewManagerNames = NativeUnimoduleProxy.viewManagersNames.join(', ');
23
- 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}].`);
24
- }
7
+ const { viewManagersMetadata } = NativeModules.NativeUnimoduleProxy;
8
+ const viewManagerConfig = viewManagersMetadata?.[viewName];
9
+ if (__DEV__ && !viewManagerConfig) {
10
+ const exportedViewManagerNames = Object.keys(viewManagersMetadata).join(', ');
11
+ 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}].`);
25
12
  }
26
13
  // Set up the React Native native component, which is an adapter to the universal module's view
27
14
  // manager
28
15
  const reactNativeViewName = `ViewManagerAdapter_${viewName}`;
29
16
  const ReactNativeComponent = requireNativeComponent(reactNativeViewName);
30
- const reactNativeUIConfiguration = (UIManager.getViewManagerConfig
31
- ? UIManager.getViewManagerConfig(reactNativeViewName)
32
- : UIManager[reactNativeViewName]) || {
33
- NativeProps: {},
34
- directEventTypes: {},
35
- };
36
- const reactNativeComponentPropNames = [
37
- 'children',
38
- ...ViewPropTypesKeys,
39
- ...Object.keys(reactNativeUIConfiguration.NativeProps),
40
- ...Object.keys(reactNativeUIConfiguration.directEventTypes),
41
- ];
17
+ const proxiedPropsNames = viewManagerConfig?.propsNames ?? [];
42
18
  // Define a component for universal-module authors to access their native view manager
43
19
  function NativeComponentAdapter(props, ref) {
44
- const nativeProps = pick(props, reactNativeComponentPropNames);
45
- const proxiedProps = omit(props, reactNativeComponentPropNames);
20
+ const nativeProps = omit(props, proxiedPropsNames);
21
+ const proxiedProps = pick(props, proxiedPropsNames);
46
22
  return React.createElement(ReactNativeComponent, { ...nativeProps, proxiedProperties: proxiedProps, ref: ref });
47
23
  }
48
24
  NativeComponentAdapter.displayName = `Adapter<${viewName}>`;
@@ -1 +1 @@
1
- {"version":3,"file":"NativeViewManagerAdapter.native.js","sourceRoot":"","sources":["../src/NativeViewManagerAdapter.native.tsx"],"names":[],"mappings":"AAAA,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,8IAA8I,wBAAwB,IAAI,CAChO,CAAC;SACH;KACF;IAED,+FAA+F;IAC/F,UAAU;IACV,MAAM,mBAAmB,GAAG,sBAAsB,QAAQ,EAAE,CAAC;IAC7D,MAAM,oBAAoB,GACxB,sBAAsB,CAA2B,mBAAmB,CAAC,CAAC;IACxE,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,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,OAAK,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;IAC9F,CAAC;IACD,sBAAsB,CAAC,WAAW,GAAG,WAAW,QAAQ,GAAG,CAAC;IAC5D,OAAO,KAAK,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,IAAI,CAAC,KAA0B,EAAE,SAAmB;IAC3D,MAAM,MAAM,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAC5B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAChC,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;KACzB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,IAAI,CAAC,KAA0B,EAAE,SAAmB;IAC3D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QACrC,IAAI,IAAI,IAAI,KAAK,EAAE;YACjB,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;SAC1B;QACD,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import 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 expo-modules-core. 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 =\n requireNativeComponent<NativeExpoComponentProps>(reactNativeViewName);\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 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\nfunction omit(props: Record<string, any>, propNames: string[]) {\n const copied = { ...props };\n for (const propName of propNames) {\n delete copied[propName];\n }\n return copied;\n}\n\nfunction pick(props: Record<string, any>, propNames: string[]) {\n return propNames.reduce((prev, curr) => {\n if (curr in props) {\n prev[curr] = props[curr];\n }\n return prev;\n }, {});\n}\n"]}
1
+ {"version":3,"file":"NativeViewManagerAdapter.native.js","sourceRoot":"","sources":["../src/NativeViewManagerAdapter.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAerE;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAU,QAAgB;IAChE,MAAM,EAAE,oBAAoB,EAAE,GAAG,aAAa,CAAC,oBAAoB,CAAC;IACpE,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,CAAC,QAAQ,CAAC,CAAC;IAE3D,IAAI,OAAO,IAAI,CAAC,iBAAiB,EAAE;QACjC,MAAM,wBAAwB,GAAG,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9E,OAAO,CAAC,IAAI,CACV,6CAA6C,QAAQ,8IAA8I,wBAAwB,IAAI,CAChO,CAAC;KACH;IAED,+FAA+F;IAC/F,UAAU;IACV,MAAM,mBAAmB,GAAG,sBAAsB,QAAQ,EAAE,CAAC;IAC7D,MAAM,oBAAoB,GACxB,sBAAsB,CAA2B,mBAAmB,CAAC,CAAC;IACxE,MAAM,iBAAiB,GAAG,iBAAiB,EAAE,UAAU,IAAI,EAAE,CAAC;IAE9D,sFAAsF;IACtF,SAAS,sBAAsB,CAAC,KAAK,EAAE,GAAG;QACxC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;QACnD,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;QACpD,OAAO,oBAAC,oBAAoB,OAAK,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;IAC9F,CAAC;IACD,sBAAsB,CAAC,WAAW,GAAG,WAAW,QAAQ,GAAG,CAAC;IAC5D,OAAO,KAAK,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,IAAI,CAAC,KAA0B,EAAE,SAAmB;IAC3D,MAAM,MAAM,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAC5B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAChC,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;KACzB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,IAAI,CAAC,KAA0B,EAAE,SAAmB;IAC3D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QACrC,IAAI,IAAI,IAAI,KAAK,EAAE;YACjB,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;SAC1B;QACD,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import React from 'react';\nimport { NativeModules, 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\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 const { viewManagersMetadata } = NativeModules.NativeUnimoduleProxy;\n const viewManagerConfig = viewManagersMetadata?.[viewName];\n\n if (__DEV__ && !viewManagerConfig) {\n const exportedViewManagerNames = Object.keys(viewManagersMetadata).join(', ');\n console.warn(\n `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}].`\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 =\n requireNativeComponent<NativeExpoComponentProps>(reactNativeViewName);\n const proxiedPropsNames = viewManagerConfig?.propsNames ?? [];\n\n // Define a component for universal-module authors to access their native view manager\n function NativeComponentAdapter(props, ref) {\n const nativeProps = omit(props, proxiedPropsNames);\n const proxiedProps = pick(props, proxiedPropsNames);\n return <ReactNativeComponent {...nativeProps} proxiedProperties={proxiedProps} ref={ref} />;\n }\n NativeComponentAdapter.displayName = `Adapter<${viewName}>`;\n return React.forwardRef(NativeComponentAdapter);\n}\n\nfunction omit(props: Record<string, any>, propNames: string[]) {\n const copied = { ...props };\n for (const propName of propNames) {\n delete copied[propName];\n }\n return copied;\n}\n\nfunction pick(props: Record<string, any>, propNames: string[]) {\n return propNames.reduce((prev, curr) => {\n if (curr in props) {\n prev[curr] = props[curr];\n }\n return prev;\n }, {});\n}\n"]}
@@ -1,3 +1,3 @@
1
- import { NativeModulesProxy } from '..';
1
+ import NativeModulesProxy from '../NativeModulesProxy';
2
2
  export default NativeModulesProxy.ExpoModulesCoreErrorManager;
3
3
  //# sourceMappingURL=NativeErrorManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NativeErrorManager.js","sourceRoot":"","sources":["../../src/sweet/NativeErrorManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAC;AACxC,eAAe,kBAAkB,CAAC,2BAA2B,CAAC","sourcesContent":["import { NativeModulesProxy } from '..';\nexport default NativeModulesProxy.ExpoModulesCoreErrorManager;\n"]}
1
+ {"version":3,"file":"NativeErrorManager.js","sourceRoot":"","sources":["../../src/sweet/NativeErrorManager.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AACvD,eAAe,kBAAkB,CAAC,2BAA2B,CAAC","sourcesContent":["import NativeModulesProxy from '../NativeModulesProxy';\nexport default NativeModulesProxy.ExpoModulesCoreErrorManager;\n"]}
@@ -1,14 +1,10 @@
1
1
  // Copyright 2018-present 650 Industries. All rights reserved.
2
2
 
3
+ #import <ExpoModulesCore/EXLegacyAppDelegateWrapper.h>
4
+
3
5
  #import <ExpoModulesCore/EXAppDelegatesLoader.h>
4
6
  #import <ExpoModulesCore/EXNativeModulesProxy.h>
5
-
6
- #if __has_include(<ExpoModulesCore/ExpoModulesCore-Swift.h>)
7
- // When `use_frameworks!` is used, the generated Swift header is inside ExpoModulesCore module.
8
- #import <ExpoModulesCore/ExpoModulesCore-Swift.h>
9
- #else
10
- #import "ExpoModulesCore-Swift.h"
11
- #endif
7
+ #import <ExpoModulesCore/Swift.h>
12
8
 
13
9
  // Make the legacy wrapper conform to the protocol for subscribers.
14
10
  @interface EXLegacyAppDelegateWrapper () <EXAppDelegateSubscriberProtocol>
@@ -21,7 +17,7 @@
21
17
  // and before any code is executed, so we switch back to Objective-C just to do this one thing.
22
18
  + (void)load
23
19
  {
24
- id<ModulesProviderObjCProtocol> modulesProvider = [EXNativeModulesProxy getExpoModulesProvider];
20
+ ModulesProvider *modulesProvider = [EXNativeModulesProxy getExpoModulesProvider];
25
21
  [EXExpoAppDelegate registerSubscriber:[[EXLegacyAppDelegateWrapper alloc] init]];
26
22
  [EXExpoAppDelegate registerSubscribersFromModulesProvider:modulesProvider];
27
23
  [EXExpoAppDelegate registerReactDelegateHandlersFromModulesProvider:modulesProvider];
@@ -263,11 +263,8 @@ open class ExpoAppDelegate: UIResponder, UIApplicationDelegate {
263
263
  // MARK: - Statics
264
264
 
265
265
  @objc
266
- public static func registerSubscribersFrom(modulesProvider: ModulesProviderObjCProtocol) {
267
- guard let provider = modulesProvider as? ModulesProviderProtocol else {
268
- fatalError("Expo modules provider must implement `ModulesProviderProtocol`.")
269
- }
270
- provider.getAppDelegateSubscribers().forEach { subscriberType in
266
+ public static func registerSubscribersFrom(modulesProvider: ModulesProvider) {
267
+ modulesProvider.getAppDelegateSubscribers().forEach { subscriberType in
271
268
  registerSubscriber(subscriberType.init())
272
269
  }
273
270
  }
@@ -286,11 +283,8 @@ open class ExpoAppDelegate: UIResponder, UIApplicationDelegate {
286
283
  }
287
284
 
288
285
  @objc
289
- public static func registerReactDelegateHandlersFrom(modulesProvider: ModulesProviderObjCProtocol) {
290
- guard let provider = modulesProvider as? ModulesProviderProtocol else {
291
- fatalError("Expo modules provider must implement `ModulesProviderProtocol`.")
292
- }
293
- provider.getReactDelegateHandlers()
286
+ public static func registerReactDelegateHandlersFrom(modulesProvider: ModulesProvider) {
287
+ modulesProvider.getReactDelegateHandlers()
294
288
  .sorted { tuple1, tuple2 -> Bool in
295
289
  return ModulePriorities.get(tuple1.packageName) > ModulePriorities.get(tuple2.packageName)
296
290
  }
@@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
16
16
  @property (class, nonatomic, assign, readonly) BOOL APP_DEBUG NS_SWIFT_NAME(APP_DEBUG);
17
17
  @property (class, nonatomic, assign, readonly) BOOL APP_RCT_DEBUG NS_SWIFT_NAME(APP_RCT_DEBUG);
18
18
  @property (class, nonatomic, assign, readonly) BOOL APP_RCT_DEV NS_SWIFT_NAME(APP_RCT_DEV);
19
+ @property (class, nonatomic, assign, readonly) BOOL APP_NEW_ARCH_ENABLED NS_SWIFT_NAME(APP_NEW_ARCH_ENABLED);
19
20
 
20
21
  + (NSDictionary *)getAllDefines;
21
22
 
@@ -26,6 +26,12 @@ static BOOL _loaded = NO;
26
26
  return [_storage[@"APP_RCT_DEV"] boolValue];
27
27
  }
28
28
 
29
+ + (BOOL)APP_NEW_ARCH_ENABLED
30
+ {
31
+ [self throwIfNotLoaded];
32
+ return [_storage[@"APP_NEW_ARCH_ENABLED"] boolValue];
33
+ }
34
+
29
35
  + (NSDictionary *)getAllDefines
30
36
  {
31
37
  return _storage;
package/ios/EXUtilities.h CHANGED
@@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
20
20
  - (nullable UIViewController *)currentViewController;
21
21
  - (nullable NSDictionary *)launchOptions;
22
22
 
23
+ + (BOOL)catchException:(void(^)(void))tryBlock error:(__autoreleasing NSError **)error;
24
+
23
25
  @end
24
26
 
25
27
  NS_ASSUME_NONNULL_END
package/ios/EXUtilities.m CHANGED
@@ -206,6 +206,18 @@ EX_REGISTER_MODULE();
206
206
  }
207
207
  }
208
208
 
209
+ + (BOOL)catchException:(void(^)(void))tryBlock error:(__autoreleasing NSError **)error
210
+ {
211
+ @try {
212
+ tryBlock();
213
+ return YES;
214
+ }
215
+ @catch (NSException *exception) {
216
+ *error = [[NSError alloc] initWithDomain:exception.name code:0 userInfo:exception.userInfo];
217
+ return NO;
218
+ }
219
+ }
220
+
209
221
  @end
210
222
 
211
223
  UIApplication * EXSharedApplication(void)
@@ -1,5 +1,9 @@
1
1
  // Copyright 2015-present 650 Industries. All rights reserved.
2
2
 
3
+ // Some headers needs to be imported from Objective-C code too.
4
+ // Otherwise they won't be visible in `ExpoModulesCore-Swift.h`.
5
+ #import <React/RCTView.h>
6
+
3
7
  #if __has_include("ExpoModulesCore-umbrella.h")
4
8
  #import "ExpoModulesCore-umbrella.h"
5
9
  #endif
@@ -23,6 +23,9 @@ Pod::Spec.new do |s|
23
23
  'CLANG_CXX_LANGUAGE_STANDARD' => 'c++14',
24
24
  'SWIFT_COMPILATION_MODE' => 'wholemodule',
25
25
  }
26
+ s.user_target_xcconfig = {
27
+ "HEADER_SEARCH_PATHS" => "\"${PODS_CONFIGURATION_BUILD_DIR}/ExpoModulesCore/Swift Compatibility Header\"",
28
+ }
26
29
 
27
30
  s.dependency 'React-Core'
28
31
  s.dependency 'ReactCommon/turbomodule/core'
@@ -38,8 +41,7 @@ Pod::Spec.new do |s|
38
41
  s.private_header_files = ['**/*+Private.h', '**/Swift.h']
39
42
 
40
43
  s.test_spec 'Tests' do |test_spec|
41
- test_spec.dependency 'Quick'
42
- test_spec.dependency 'Nimble'
44
+ test_spec.dependency 'ExpoModulesTestCore'
43
45
 
44
46
  test_spec.source_files = 'Tests/**/*.{m,swift}'
45
47
  end
@@ -17,7 +17,7 @@ typedef NS_OPTIONS(unsigned int, EXFileSystemPermissionFlags) {
17
17
 
18
18
  // TODO: Move permissionsForURI to EXFileSystemManagerInterface
19
19
  - (EXFileSystemPermissionFlags)permissionsForURI:(NSURL *)uri;
20
- - (NSString *)generatePathInDirectory:(NSString *)directory withExtension:(NSString *)extension;
20
+ - (nonnull NSString *)generatePathInDirectory:(NSString *)directory withExtension:(NSString *)extension;
21
21
  - (BOOL)ensureDirExistsWithPath:(NSString *)path;
22
22
 
23
23
  @end
@@ -1,6 +1,7 @@
1
1
  // Copyright 2015-present 650 Industries. All rights reserved.
2
2
 
3
3
  #import <ExpoModulesCore/EXTaskInterface.h>
4
+ #import <ExpoModulesCore/EXTaskManagerInterface.h>
4
5
 
5
6
  @protocol EXTaskServiceInterface
6
7
 
@@ -11,6 +11,9 @@
11
11
  using namespace facebook;
12
12
  using namespace react;
13
13
 
14
+ @class EXJavaScriptValue;
15
+ @class EXJavaScriptRuntime;
16
+
14
17
  namespace expo {
15
18
 
16
19
  jsi::Value convertNSNumberToJSIBoolean(jsi::Runtime &runtime, NSNumber *value);
@@ -31,7 +34,7 @@ NSString *convertJSIStringToNSString(jsi::Runtime &runtime, const jsi::String &v
31
34
 
32
35
  NSArray *convertJSIArrayToNSArray(jsi::Runtime &runtime, const jsi::Array &value, std::shared_ptr<CallInvoker> jsInvoker);
33
36
 
34
- NSArray *convertJSIValuesToNSArray(jsi::Runtime &runtime, const jsi::Value *values, size_t count, std::shared_ptr<CallInvoker> jsInvoker);
37
+ NSArray<EXJavaScriptValue *> *convertJSIValuesToNSArray(EXJavaScriptRuntime *runtime, const jsi::Value *values, size_t count);
35
38
 
36
39
  NSDictionary *convertJSIObjectToNSDictionary(jsi::Runtime &runtime, const jsi::Object &value, std::shared_ptr<CallInvoker> jsInvoker);
37
40
 
@@ -1,7 +1,9 @@
1
1
  // Copyright 2018-present 650 Industries. All rights reserved.
2
2
 
3
3
  #import <ReactCommon/TurboModuleUtils.h>
4
- #import <ExpoModulesCore/JSIConversions.h>
4
+ #import <ExpoModulesCore/EXJSIConversions.h>
5
+ #import <ExpoModulesCore/EXJavaScriptValue.h>
6
+ #import <ExpoModulesCore/EXJavaScriptRuntime.h>
5
7
 
6
8
  namespace expo {
7
9
 
@@ -52,6 +54,12 @@ std::vector<jsi::Value> convertNSArrayToStdVector(jsi::Runtime &runtime, NSArray
52
54
 
53
55
  jsi::Value convertObjCObjectToJSIValue(jsi::Runtime &runtime, id value)
54
56
  {
57
+ if ([value isKindOfClass:[EXJavaScriptValue class]]) {
58
+ return jsi::Value(runtime, *[(EXJavaScriptValue *)value get]);
59
+ }
60
+ if ([value isKindOfClass:[EXJavaScriptObject class]]) {
61
+ return jsi::Value(runtime, *[(EXJavaScriptObject *)value get]);
62
+ }
55
63
  if ([value isKindOfClass:[NSString class]]) {
56
64
  return convertNSStringToJSIString(runtime, (NSString *)value);
57
65
  } else if ([value isKindOfClass:[NSNumber class]]) {
@@ -86,13 +94,16 @@ NSArray *convertJSIArrayToNSArray(jsi::Runtime &runtime, const jsi::Array &value
86
94
  return [result copy];
87
95
  }
88
96
 
89
- NSArray *convertJSIValuesToNSArray(jsi::Runtime &runtime, const jsi::Value *values, size_t count, std::shared_ptr<CallInvoker> jsInvoker)
97
+ NSArray<EXJavaScriptValue *> *convertJSIValuesToNSArray(EXJavaScriptRuntime *runtime, const jsi::Value *values, size_t count)
90
98
  {
91
- NSMutableArray *result = [NSMutableArray arrayWithCapacity:count];
99
+ NSMutableArray<EXJavaScriptValue *> *array = [NSMutableArray arrayWithCapacity:count];
100
+ jsi::Runtime *jsiRuntime = [runtime get];
101
+
92
102
  for (int i = 0; i < count; i++) {
93
- result[i] = convertJSIValueToObjCObject(runtime, values[i], jsInvoker);
103
+ std::shared_ptr<jsi::Value> value = std::make_shared<jsi::Value>(*jsiRuntime, values[i]);
104
+ array[i] = [[EXJavaScriptValue alloc] initWithRuntime:runtime value:value];
94
105
  }
95
- return result;
106
+ return array;
96
107
  }
97
108
 
98
109
  NSDictionary *convertJSIObjectToNSDictionary(jsi::Runtime &runtime, const jsi::Object &value, std::shared_ptr<CallInvoker> jsInvoker)
@@ -18,12 +18,12 @@ void installRuntimeObjects(jsi::Runtime &runtime, std::shared_ptr<CallInvoker> c
18
18
 
19
19
  #endif
20
20
 
21
- #import <ExpoModulesCore/JavaScriptRuntime.h>
21
+ #import <ExpoModulesCore/EXJavaScriptRuntime.h>
22
22
 
23
23
  @class SwiftInteropBridge;
24
24
 
25
- @interface JavaScriptRuntimeManager : NSObject
25
+ @interface EXJavaScriptRuntimeManager : NSObject
26
26
 
27
- + (void)installExpoModulesToRuntime:(nonnull JavaScriptRuntime *)runtime withSwiftInterop:(nonnull SwiftInteropBridge *)swiftInterop;
27
+ + (void)installExpoModulesToRuntime:(nonnull EXJavaScriptRuntime *)runtime withSwiftInterop:(nonnull SwiftInteropBridge *)swiftInterop;
28
28
 
29
29
  @end
@@ -0,0 +1,17 @@
1
+ // Copyright 2018-present 650 Industries. All rights reserved.
2
+
3
+ #import <ExpoModulesCore/EXJSIInstaller.h>
4
+ #import <ExpoModulesCore/ExpoModulesHostObject.h>
5
+ #import <ExpoModulesCore/Swift.h>
6
+
7
+ @implementation EXJavaScriptRuntimeManager
8
+
9
+ + (void)installExpoModulesToRuntime:(nonnull EXJavaScriptRuntime *)runtime withSwiftInterop:(nonnull SwiftInteropBridge *)swiftInterop
10
+ {
11
+ std::shared_ptr<expo::ExpoModulesHostObject> hostObjectPtr = std::make_shared<expo::ExpoModulesHostObject>(swiftInterop);
12
+ EXJavaScriptObject *global = [runtime global];
13
+
14
+ [global setProperty:@"ExpoModules" value:[runtime createHostObject:hostObjectPtr]];
15
+ }
16
+
17
+ @end
@@ -5,8 +5,6 @@
5
5
  #import <jsi/jsi.h>
6
6
  #import <ReactCommon/RCTTurboModule.h>
7
7
 
8
- #import <ExpoModulesCore/EXNativeModulesProxy.h>
9
-
10
8
  using namespace facebook;
11
9
  using namespace react;
12
10
 
@@ -16,13 +14,6 @@ using PromiseInvocationBlock = void (^)(RCTPromiseResolveBlock resolveWrapper, R
16
14
 
17
15
  void callPromiseSetupWithBlock(jsi::Runtime &runtime, std::shared_ptr<CallInvoker> jsInvoker, std::shared_ptr<Promise> promise, PromiseInvocationBlock setupBlock);
18
16
 
19
- class JSI_EXPORT ExpoModulesProxySpec : public TurboModule {
20
- public:
21
- ExpoModulesProxySpec(std::shared_ptr<CallInvoker> callInvoker, EXNativeModulesProxy *nativeModulesProxy);
22
-
23
- EXNativeModulesProxy *nativeModulesProxy;
24
- };
25
-
26
17
  } // namespace expo
27
18
 
28
19
  #endif
@@ -1,9 +1,10 @@
1
- // Copyright 2018-present 650 Industries. All rights reserved.
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
2
 
3
3
  #import <React/RCTUtils.h>
4
+ #import <ExpoModulesCore/EXJSIConversions.h>
5
+ #import <ExpoModulesCore/EXJSIUtils.h>
4
6
 
5
- #import <ExpoModulesCore/JSIConversions.h>
6
- #import <ExpoModulesCore/ExpoModulesProxySpec.h>
7
+ using namespace facebook;
7
8
 
8
9
  namespace expo {
9
10
 
@@ -85,49 +86,4 @@ void callPromiseSetupWithBlock(jsi::Runtime &runtime, std::shared_ptr<CallInvoke
85
86
  setupBlock(resolveBlock, rejectBlock);
86
87
  }
87
88
 
88
- static jsi::Value __hostFunction_ExpoModulesProxySpec_callMethodAsync(jsi::Runtime &runtime, TurboModule &turboModule, const jsi::Value *args, size_t count)
89
- {
90
- auto expoModulesProxy = static_cast<ExpoModulesProxySpec *>(&turboModule);
91
-
92
- // The function that is invoked as a setup of the JS `Promise`.
93
- auto promiseSetupFunc = [expoModulesProxy, args](jsi::Runtime &runtime, std::shared_ptr<Promise> promise) {
94
- callPromiseSetupWithBlock(runtime, expoModulesProxy->jsInvoker_, promise, ^(RCTPromiseResolveBlock resolver, RCTPromiseRejectBlock rejecter) {
95
- NSString *moduleName = convertJSIStringToNSString(runtime, args[0].getString(runtime));
96
- NSString *methodName = convertJSIStringToNSString(runtime, args[1].getString(runtime));
97
- NSArray *arguments = convertJSIArrayToNSArray(runtime, args[2].getObject(runtime).asArray(runtime), expoModulesProxy->jsInvoker_);
98
-
99
- [expoModulesProxy->nativeModulesProxy callMethod:moduleName
100
- methodNameOrKey:methodName
101
- arguments:arguments
102
- resolver:resolver
103
- rejecter:rejecter];
104
- });
105
- };
106
-
107
- return createPromiseAsJSIValue(runtime, promiseSetupFunc);
108
- }
109
-
110
- static jsi::Value __hostFunction_ExpoModulesProxySpec_callMethodSync(jsi::Runtime &runtime, TurboModule &turboModule, const jsi::Value *args, size_t count)
111
- {
112
- auto expoModulesProxy = static_cast<ExpoModulesProxySpec *>(&turboModule);
113
- NSString *moduleName = convertJSIStringToNSString(runtime, args[0].getString(runtime));
114
- NSString *methodName = convertJSIStringToNSString(runtime, args[1].getString(runtime));
115
- NSArray *arguments = convertJSIArrayToNSArray(runtime, args[2].getObject(runtime).asArray(runtime), expoModulesProxy->jsInvoker_);
116
-
117
- id result = [expoModulesProxy->nativeModulesProxy callMethodSync:moduleName
118
- methodName:methodName
119
- arguments:arguments];
120
-
121
- return convertObjCObjectToJSIValue(runtime, result);
122
- }
123
-
124
- ExpoModulesProxySpec::ExpoModulesProxySpec(std::shared_ptr<CallInvoker> callInvoker, EXNativeModulesProxy *nativeModulesProxy) :
125
- TurboModule("ExpoModulesProxy", callInvoker),
126
- nativeModulesProxy(nativeModulesProxy)
127
- {
128
- methodMap_["callMethodAsync"] = MethodMetadata {3, __hostFunction_ExpoModulesProxySpec_callMethodAsync};
129
-
130
- methodMap_["callMethodSync"] = MethodMetadata {3, __hostFunction_ExpoModulesProxySpec_callMethodSync};
131
- }
132
-
133
89
  } // namespace expo
@@ -0,0 +1,97 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ #import <Foundation/Foundation.h>
4
+ #import <React/RCTBridgeModule.h>
5
+
6
+ #ifdef __cplusplus
7
+ #import <jsi/jsi.h>
8
+ #import <ReactCommon/CallInvoker.h>
9
+
10
+ namespace jsi = facebook::jsi;
11
+ #endif // __cplusplus
12
+
13
+ typedef void (^JSAsyncFunctionBlock)(NSArray * _Nonnull, RCTPromiseResolveBlock _Nonnull, RCTPromiseRejectBlock _Nonnull);
14
+ typedef id _Nullable (^JSSyncFunctionBlock)(NSArray * _Nonnull);
15
+
16
+ @class EXJavaScriptRuntime;
17
+ @class EXJavaScriptValue;
18
+
19
+ /**
20
+ The property descriptor options for the property being defined or modified.
21
+ */
22
+ typedef NS_OPTIONS(NSInteger, EXJavaScriptObjectPropertyDescriptor) {
23
+ /**
24
+ If set, the type of this property descriptor may be changed and if the property may be deleted from the corresponding object.
25
+ */
26
+ EXJavaScriptObjectPropertyDescriptorConfigurable = 1 << 0,
27
+ /**
28
+ If set, the property shows up during enumeration of the properties on the corresponding object.
29
+ */
30
+ EXJavaScriptObjectPropertyDescriptorEnumerable = 1 << 1,
31
+ /**
32
+ If set, the value associated with the property may be changed with an assignment operator.
33
+ */
34
+ EXJavaScriptObjectPropertyDescriptorWritable = 1 << 2,
35
+ } NS_SWIFT_NAME(JavaScriptObjectPropertyDescriptor);
36
+
37
+ NS_SWIFT_NAME(JavaScriptObject)
38
+ @interface EXJavaScriptObject : NSObject
39
+
40
+ // Some parts of the interface must be hidden for Swift – it can't import any C++ code.
41
+ #ifdef __cplusplus
42
+ - (nonnull instancetype)initWith:(std::shared_ptr<jsi::Object>)jsObjectPtr
43
+ runtime:(nonnull EXJavaScriptRuntime *)runtime;
44
+
45
+ /**
46
+ Returns the pointer to the underlying object.
47
+ */
48
+ - (nonnull jsi::Object *)get;
49
+ #endif // __cplusplus
50
+
51
+ #pragma mark - Accessing object properties
52
+
53
+ /**
54
+ \return a bool whether the object has a property with the given name.
55
+ */
56
+ - (BOOL)hasProperty:(nonnull NSString *)name;
57
+
58
+ /**
59
+ \return the property of the object with the given name.
60
+ If the name isn't a property on the object, returns the `undefined` value.
61
+ */
62
+ - (nonnull EXJavaScriptValue *)getProperty:(nonnull NSString *)name;
63
+
64
+ /**
65
+ \return an array consisting of all enumerable property names in the object and its prototype chain.
66
+ */
67
+ - (nonnull NSArray<NSString *> *)getPropertyNames;
68
+
69
+ #pragma mark - Modifying object properties
70
+
71
+ /**
72
+ Sets the value for the property with the given name.
73
+ */
74
+ - (void)setProperty:(nonnull NSString *)name value:(nullable id)value;
75
+
76
+ /**
77
+ Defines a new property or modifies an existing property on the object. Calls `Object.defineProperty` under the hood.
78
+ */
79
+ - (void)defineProperty:(nonnull NSString *)name value:(nullable id)value options:(EXJavaScriptObjectPropertyDescriptor)options;
80
+
81
+ #pragma mark - Functions
82
+
83
+ /**
84
+ Sets given function block on the object as a host function returning a promise.
85
+ */
86
+ - (void)setAsyncFunction:(nonnull NSString *)key
87
+ argsCount:(NSInteger)argsCount
88
+ block:(nonnull JSAsyncFunctionBlock)block;
89
+
90
+ /**
91
+ Sets given synchronous function block as a host function on the object.
92
+ */
93
+ - (void)setSyncFunction:(nonnull NSString *)name
94
+ argsCount:(NSInteger)argsCount
95
+ block:(nonnull JSSyncFunctionBlock)block;
96
+
97
+ @end