expo-modules-core 0.9.2 → 0.11.1

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 (193) hide show
  1. package/CHANGELOG.md +33 -3
  2. package/README.md +3 -3
  3. package/android/CMakeLists.txt +163 -0
  4. package/android/build.gradle +343 -5
  5. package/android/src/main/cpp/CachedReferencesRegistry.cpp +65 -0
  6. package/android/src/main/cpp/CachedReferencesRegistry.h +80 -0
  7. package/android/src/main/cpp/Exceptions.cpp +22 -0
  8. package/android/src/main/cpp/Exceptions.h +38 -0
  9. package/android/src/main/cpp/ExpoModulesHostObject.cpp +47 -0
  10. package/android/src/main/cpp/ExpoModulesHostObject.h +32 -0
  11. package/android/src/main/cpp/JNIFunctionBody.cpp +44 -0
  12. package/android/src/main/cpp/JNIFunctionBody.h +50 -0
  13. package/android/src/main/cpp/JNIInjector.cpp +23 -0
  14. package/android/src/main/cpp/JSIInteropModuleRegistry.cpp +122 -0
  15. package/android/src/main/cpp/JSIInteropModuleRegistry.h +96 -0
  16. package/android/src/main/cpp/JSIObjectWrapper.h +33 -0
  17. package/android/src/main/cpp/JSITypeConverter.h +84 -0
  18. package/android/src/main/cpp/JavaScriptModuleObject.cpp +219 -0
  19. package/android/src/main/cpp/JavaScriptModuleObject.h +144 -0
  20. package/android/src/main/cpp/JavaScriptObject.cpp +125 -0
  21. package/android/src/main/cpp/JavaScriptObject.h +131 -0
  22. package/android/src/main/cpp/JavaScriptRuntime.cpp +127 -0
  23. package/android/src/main/cpp/JavaScriptRuntime.h +87 -0
  24. package/android/src/main/cpp/JavaScriptValue.cpp +172 -0
  25. package/android/src/main/cpp/JavaScriptValue.h +78 -0
  26. package/android/src/main/cpp/MethodMetadata.cpp +340 -0
  27. package/android/src/main/cpp/MethodMetadata.h +131 -0
  28. package/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java +2 -0
  29. package/android/src/main/java/expo/modules/core/errors/ContextDestroyedException.kt +7 -0
  30. package/android/src/main/java/expo/modules/interfaces/permissions/Permissions.java +30 -0
  31. package/android/src/main/java/expo/modules/kotlin/AppContext.kt +98 -3
  32. package/android/src/main/java/expo/modules/kotlin/ConcatIterator.kt +18 -0
  33. package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +15 -12
  34. package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +45 -3
  35. package/android/src/main/java/expo/modules/kotlin/activityaware/AppCompatActivityAware.kt +49 -0
  36. package/android/src/main/java/expo/modules/kotlin/activityaware/AppCompatActivityAwareHelper.kt +43 -0
  37. package/android/src/main/java/expo/modules/kotlin/activityaware/OnActivityAvailableListener.kt +18 -0
  38. package/android/src/main/java/expo/modules/kotlin/activityresult/ActivityResultsManager.kt +99 -0
  39. package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultCaller.kt +25 -0
  40. package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultContract.kt +27 -0
  41. package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultFallbackCallback.kt +17 -0
  42. package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultLauncher.kt +30 -0
  43. package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultRegistry.kt +358 -0
  44. package/android/src/main/java/expo/modules/kotlin/activityresult/DataPersistor.kt +135 -0
  45. package/android/src/main/java/expo/modules/kotlin/defaultmodules/ErrorManagerModule.kt +2 -2
  46. package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +13 -0
  47. package/android/src/main/java/expo/modules/kotlin/exception/ExceptionDecorator.kt +2 -0
  48. package/android/src/main/java/expo/modules/kotlin/functions/AnyFunction.kt +53 -15
  49. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +35 -7
  50. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +13 -121
  51. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionComponent.kt +21 -0
  52. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromiseComponent.kt +21 -0
  53. package/android/src/main/java/expo/modules/kotlin/functions/SuspendFunctionComponent.kt +63 -0
  54. package/android/src/main/java/expo/modules/kotlin/functions/SyncFunctionComponent.kt +36 -0
  55. package/android/src/main/java/expo/modules/kotlin/jni/CppType.kt +19 -0
  56. package/android/src/main/java/expo/modules/kotlin/jni/JNIFunctionBody.kt +39 -0
  57. package/android/src/main/java/expo/modules/kotlin/jni/JSIInteropModuleRegistry.kt +89 -0
  58. package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptModuleObject.kt +46 -0
  59. package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptObject.kt +113 -0
  60. package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptValue.kt +35 -0
  61. package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +16 -6
  62. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +5 -500
  63. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionData.kt +30 -5
  64. package/android/src/main/java/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +271 -0
  65. package/android/src/main/java/expo/modules/kotlin/objects/ObjectDefinitionData.kt +21 -0
  66. package/android/src/main/java/expo/modules/kotlin/objects/PropertyComponent.kt +54 -0
  67. package/android/src/main/java/expo/modules/kotlin/objects/PropertyComponentBuilder.kt +32 -0
  68. package/android/src/main/java/expo/modules/kotlin/providers/AppContextProvider.kt +14 -0
  69. package/android/src/main/java/expo/modules/kotlin/providers/CurrentActivityProvider.kt +22 -0
  70. package/android/src/main/java/expo/modules/kotlin/records/RecordTypeConverter.kt +19 -2
  71. package/android/src/main/java/expo/modules/kotlin/types/AnyType.kt +3 -2
  72. package/android/src/main/java/expo/modules/kotlin/types/AnyTypeConverter.kt +36 -0
  73. package/android/src/main/java/expo/modules/kotlin/types/ArrayTypeConverter.kt +7 -2
  74. package/android/src/main/java/expo/modules/kotlin/types/BasicTypeConverters.kt +68 -20
  75. package/android/src/main/java/expo/modules/kotlin/types/EnumTypeConverter.kt +50 -22
  76. package/android/src/main/java/expo/modules/kotlin/types/ListTypeConverter.kt +18 -2
  77. package/android/src/main/java/expo/modules/kotlin/types/MapTypeConverter.kt +18 -2
  78. package/android/src/main/java/expo/modules/kotlin/types/PairTypeConverter.kt +17 -2
  79. package/android/src/main/java/expo/modules/kotlin/types/TypeConverter.kt +43 -3
  80. package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +12 -0
  81. package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinitionBuilder.kt +0 -41
  82. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +0 -33
  83. package/build/NativeModulesProxy.native.d.ts.map +1 -1
  84. package/build/NativeModulesProxy.native.js +9 -3
  85. package/build/NativeModulesProxy.native.js.map +1 -1
  86. package/build/PermissionsInterface.d.ts +29 -0
  87. package/build/PermissionsInterface.d.ts.map +1 -1
  88. package/build/PermissionsInterface.js +9 -0
  89. package/build/PermissionsInterface.js.map +1 -1
  90. package/ios/AppDelegates/EXAppDelegatesLoader.m +1 -2
  91. package/ios/ExpoModulesCore.podspec +3 -2
  92. package/ios/JSI/EXJSIConversions.mm +6 -0
  93. package/ios/JSI/EXJSIInstaller.h +15 -21
  94. package/ios/JSI/EXJSIInstaller.mm +39 -3
  95. package/ios/JSI/EXJSIUtils.h +48 -3
  96. package/ios/JSI/EXJSIUtils.mm +88 -4
  97. package/ios/JSI/EXJavaScriptObject.h +11 -18
  98. package/ios/JSI/EXJavaScriptObject.mm +37 -18
  99. package/ios/JSI/EXJavaScriptRuntime.h +43 -9
  100. package/ios/JSI/EXJavaScriptRuntime.mm +70 -27
  101. package/ios/JSI/EXJavaScriptTypedArray.h +30 -0
  102. package/ios/JSI/EXJavaScriptTypedArray.mm +29 -0
  103. package/ios/JSI/EXJavaScriptValue.h +3 -2
  104. package/ios/JSI/EXJavaScriptValue.mm +17 -20
  105. package/ios/JSI/EXJavaScriptWeakObject.h +23 -0
  106. package/ios/JSI/EXJavaScriptWeakObject.mm +53 -0
  107. package/ios/JSI/EXObjectDeallocator.h +27 -0
  108. package/ios/JSI/ExpoModulesHostObject.h +3 -3
  109. package/ios/JSI/ExpoModulesHostObject.mm +4 -4
  110. package/ios/JSI/JavaScriptRuntime.swift +38 -1
  111. package/ios/JSI/JavaScriptValue.swift +7 -0
  112. package/ios/JSI/TypedArray.cpp +67 -0
  113. package/ios/JSI/TypedArray.h +46 -0
  114. package/ios/ModuleRegistryAdapter/EXModuleRegistryAdapter.m +0 -11
  115. package/ios/NativeModulesProxy/EXNativeModulesProxy.h +17 -10
  116. package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +86 -77
  117. package/ios/NativeModulesProxy/NativeModulesProxyModule.swift +17 -0
  118. package/ios/Services/EXReactNativeEventEmitter.h +2 -2
  119. package/ios/Services/EXReactNativeEventEmitter.m +11 -6
  120. package/ios/Swift/AppContext.swift +206 -28
  121. package/ios/Swift/Arguments/AnyArgument.swift +18 -0
  122. package/ios/Swift/Arguments/{Types/EnumArgumentType.swift → EnumArgument.swift} +2 -17
  123. package/ios/Swift/Classes/ClassComponent.swift +95 -0
  124. package/ios/Swift/Classes/ClassComponentElement.swift +33 -0
  125. package/ios/Swift/Classes/ClassComponentElementsBuilder.swift +34 -0
  126. package/ios/Swift/Classes/ClassComponentFactories.swift +96 -0
  127. package/ios/Swift/DynamicTypes/AnyDynamicType.swift +44 -0
  128. package/ios/Swift/DynamicTypes/DynamicArrayType.swift +56 -0
  129. package/ios/Swift/DynamicTypes/DynamicConvertibleType.swift +27 -0
  130. package/ios/Swift/DynamicTypes/DynamicEnumType.swift +27 -0
  131. package/ios/Swift/DynamicTypes/DynamicOptionalType.swift +63 -0
  132. package/ios/Swift/DynamicTypes/DynamicRawType.swift +33 -0
  133. package/ios/Swift/DynamicTypes/DynamicSharedObjectType.swift +37 -0
  134. package/ios/Swift/DynamicTypes/DynamicType.swift +39 -0
  135. package/ios/Swift/DynamicTypes/DynamicTypedArrayType.swift +46 -0
  136. package/ios/Swift/Exceptions/ChainableException.swift +3 -3
  137. package/ios/Swift/Exceptions/CodedError.swift +1 -1
  138. package/ios/Swift/Exceptions/Exception.swift +8 -6
  139. package/ios/Swift/Exceptions/UnexpectedException.swift +2 -1
  140. package/ios/Swift/ExpoBridgeModule.m +5 -0
  141. package/ios/Swift/ExpoBridgeModule.swift +79 -0
  142. package/ios/Swift/Functions/AnyFunction.swift +33 -31
  143. package/ios/Swift/Functions/AsyncFunctionComponent.swift +196 -59
  144. package/ios/Swift/Functions/SyncFunctionComponent.swift +142 -58
  145. package/ios/Swift/JavaScriptUtils.swift +32 -57
  146. package/ios/Swift/Logging/LogHandlers.swift +39 -0
  147. package/ios/Swift/Logging/LogType.swift +62 -0
  148. package/ios/Swift/Logging/Logger.swift +201 -0
  149. package/ios/Swift/ModuleHolder.swift +19 -54
  150. package/ios/Swift/ModuleRegistry.swift +7 -1
  151. package/ios/Swift/Modules/AnyModule.swift +3 -3
  152. package/ios/Swift/ModulesProvider.swift +2 -0
  153. package/ios/Swift/Objects/JavaScriptObjectBuilder.swift +37 -0
  154. package/ios/Swift/Objects/ObjectDefinition.swift +74 -1
  155. package/ios/Swift/Objects/ObjectDefinitionComponents.swift +77 -68
  156. package/ios/Swift/Objects/PropertyComponent.swift +147 -0
  157. package/ios/Swift/Promise.swift +17 -4
  158. package/ios/Swift/Records/Field.swift +2 -2
  159. package/ios/Swift/SharedObjects/SharedObject.swift +20 -0
  160. package/ios/Swift/SharedObjects/SharedObjectRegistry.swift +129 -0
  161. package/ios/Swift/TypedArrays/AnyTypedArray.swift +11 -0
  162. package/ios/Swift/TypedArrays/ConcreteTypedArrays.swift +56 -0
  163. package/ios/Swift/TypedArrays/GenericTypedArray.swift +49 -0
  164. package/ios/Swift/TypedArrays/TypedArray.swift +80 -0
  165. package/ios/Swift/Utilities.swift +28 -0
  166. package/ios/Swift/Views/ConcreteViewProp.swift +3 -3
  167. package/ios/Swift/Views/ViewManagerDefinitionComponents.swift +2 -2
  168. package/ios/Tests/ClassComponentSpec.swift +210 -0
  169. package/ios/Tests/DynamicTypeSpec.swift +336 -0
  170. package/ios/Tests/EnumArgumentSpec.swift +48 -0
  171. package/ios/Tests/ExpoModulesSpec.swift +17 -3
  172. package/ios/Tests/FunctionSpec.swift +167 -118
  173. package/ios/Tests/Mocks/ModuleMocks.swift +1 -1
  174. package/ios/Tests/PropertyComponentSpec.swift +95 -0
  175. package/ios/Tests/SharedObjectRegistrySpec.swift +109 -0
  176. package/ios/Tests/TypedArraysSpec.swift +136 -0
  177. package/package.json +2 -2
  178. package/src/NativeModulesProxy.native.ts +13 -3
  179. package/src/PermissionsInterface.ts +29 -0
  180. package/src/ts-declarations/ExpoModules.d.ts +7 -0
  181. package/tsconfig.json +1 -1
  182. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromise.kt +0 -15
  183. package/android/src/main/java/expo/modules/kotlin/functions/AsyncSuspendFunction.kt +0 -36
  184. package/ios/Swift/Arguments/AnyArgumentType.swift +0 -13
  185. package/ios/Swift/Arguments/ArgumentType.swift +0 -28
  186. package/ios/Swift/Arguments/Types/ArrayArgumentType.swift +0 -42
  187. package/ios/Swift/Arguments/Types/ConvertibleArgumentType.swift +0 -16
  188. package/ios/Swift/Arguments/Types/OptionalArgumentType.swift +0 -49
  189. package/ios/Swift/Arguments/Types/PromiseArgumentType.swift +0 -15
  190. package/ios/Swift/Arguments/Types/RawArgumentType.swift +0 -25
  191. package/ios/Swift/Functions/ConcreteFunction.swift +0 -103
  192. package/ios/Swift/SwiftInteropBridge.swift +0 -155
  193. package/ios/Tests/ArgumentTypeSpec.swift +0 -143
@@ -0,0 +1,46 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ #ifdef __cplusplus
4
+
5
+ #include <jsi/jsi.h>
6
+
7
+ namespace jsi = facebook::jsi;
8
+
9
+ namespace expo {
10
+
11
+ // Please keep it in-sync with the `EXTypedArrayKind` in Objective-C.
12
+ // We need to maintain two implementations to expose this enum to Swift.
13
+ enum class TypedArrayKind {
14
+ Int8Array = 1,
15
+ Int16Array = 2,
16
+ Int32Array = 3,
17
+ Uint8Array = 4,
18
+ Uint8ClampedArray = 5,
19
+ Uint16Array = 6,
20
+ Uint32Array = 7,
21
+ Float32Array = 8,
22
+ Float64Array = 9,
23
+ BigInt64Array = 10,
24
+ BigUint64Array = 11,
25
+ };
26
+
27
+ class TypedArray : public jsi::Object {
28
+ public:
29
+ TypedArray(jsi::Runtime &, const jsi::Object &);
30
+ TypedArray(TypedArray &&) = default;
31
+ TypedArray &operator=(TypedArray &&) = default;
32
+
33
+ TypedArrayKind getKind(jsi::Runtime &runtime) const;
34
+
35
+ size_t byteOffset(jsi::Runtime &runtime) const;
36
+
37
+ jsi::ArrayBuffer getBuffer(jsi::Runtime &runtime) const;
38
+
39
+ void* getRawPointer(jsi::Runtime &runtime);
40
+ };
41
+
42
+ bool isTypedArray(jsi::Runtime &runtime, const jsi::Object &jsObj);
43
+
44
+ } // namespace expo
45
+
46
+ #endif // __cplusplus
@@ -7,13 +7,11 @@
7
7
  #import <ExpoModulesCore/EXViewManagerAdapterClassesRegistry.h>
8
8
  #import <ExpoModulesCore/EXModuleRegistryHolderReactModule.h>
9
9
  #import <ExpoModulesCore/EXReactNativeEventEmitter.h>
10
- #import <ExpoModulesCore/Swift.h>
11
10
 
12
11
  @interface EXModuleRegistryAdapter ()
13
12
 
14
13
  @property (nonatomic, strong) EXModuleRegistryProvider *moduleRegistryProvider;
15
14
  @property (nonatomic, strong) EXViewManagerAdapterClassesRegistry *viewManagersClassesRegistry;
16
- @property (nonatomic, strong, nullable) ModulesProvider *swiftModulesProvider;
17
15
 
18
16
  @end
19
17
 
@@ -75,13 +73,4 @@
75
73
  return extraModules;
76
74
  }
77
75
 
78
- - (nullable SwiftInteropBridge *)swiftInteropBridgeModulesRegistry:(EXModuleRegistry *)moduleRegistry
79
- {
80
- if (_swiftModulesProvider) {
81
- return [[SwiftInteropBridge alloc] initWithModulesProvider:_swiftModulesProvider legacyModuleRegistry:moduleRegistry];
82
- } else {
83
- return nil;
84
- }
85
- }
86
-
87
76
  @end
@@ -5,26 +5,33 @@
5
5
  #import <ExpoModulesCore/EXInternalModule.h>
6
6
  #import <ExpoModulesCore/EXModuleRegistry.h>
7
7
 
8
+ // A convenience class, which acts as a store for the native modules proxy config
9
+
10
+ NS_SWIFT_NAME(ModulesProxyConfig)
11
+ @interface EXModulesProxyConfig : NSObject
12
+
13
+ - (instancetype)initWithConstants:(nonnull NSDictionary *)constants
14
+ methodNames:(nonnull NSDictionary *)methodNames
15
+ viewManagers:(nonnull NSDictionary *)viewManagerMetadata;
16
+
17
+ - (void)addEntriesFromConfig:(nonnull const EXModulesProxyConfig *)config;
18
+ - (nonnull NSDictionary<NSString *, id> *)toDictionary;
19
+
20
+ @end
21
+
8
22
  // RCTBridgeModule capable of receiving method calls from JS and forwarding them
9
23
  // to proper exported universal modules. Also, it exports important constants to JS, like
10
24
  // properties of exported methods and modules' constants.
11
25
 
12
- // Swift compatibility headers (e.g. `ExpoModulesCore-Swift.h`) are not available in headers,
13
- // so we use class forward declaration here. Swift header must be imported in the `.m` file.
14
- @class SwiftInteropBridge;
15
- @class ModulesProvider;
16
-
17
- NS_SWIFT_NAME(NativeModulesProxy)
26
+ NS_SWIFT_NAME(LegacyNativeModulesProxy)
18
27
  @interface EXNativeModulesProxy : NSObject <RCTBridgeModule>
19
28
 
20
- @property (nonatomic, strong) SwiftInteropBridge *swiftInteropBridge;
29
+ @property (nonatomic, strong, readonly) EXModulesProxyConfig *nativeModulesConfig;
21
30
 
22
31
  - (nonnull instancetype)init;
23
32
  - (nonnull instancetype)initWithModuleRegistry:(nullable EXModuleRegistry *)moduleRegistry;
33
+ - (nonnull instancetype)initWithCustomModuleRegistry:(nonnull EXModuleRegistry *)moduleRegistry;
24
34
 
25
35
  - (void)callMethod:(NSString *)moduleName methodNameOrKey:(id)methodNameOrKey arguments:(NSArray *)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
26
- - (id)callMethodSync:(NSString *)moduleName methodName:(NSString *)methodName arguments:(NSArray *)arguments;
27
-
28
- + (ModulesProvider *)getExpoModulesProvider;
29
36
 
30
37
  @end
@@ -28,6 +28,46 @@ static const NSString *methodInfoKeyKey = @"key";
28
28
  static const NSString *methodInfoNameKey = @"name";
29
29
  static const NSString *methodInfoArgumentsCountKey = @"argumentsCount";
30
30
 
31
+ @interface EXModulesProxyConfig ()
32
+
33
+ @property (readonly) NSMutableDictionary *exportedConstants;
34
+ @property (readonly) NSMutableDictionary *methodNames;
35
+ @property (readonly) NSMutableDictionary *viewManagerMetadata;
36
+
37
+ @end
38
+
39
+ @implementation EXModulesProxyConfig
40
+
41
+ - (instancetype)initWithConstants:(nonnull NSDictionary *)constants
42
+ methodNames:(nonnull NSDictionary *)methodNames
43
+ viewManagers:(nonnull NSDictionary *)viewManagerMetadata
44
+ {
45
+ if (self = [super init]) {
46
+ _exportedConstants = constants;
47
+ _methodNames = methodNames;
48
+ _viewManagerMetadata = viewManagerMetadata;
49
+ }
50
+ return self;
51
+ }
52
+
53
+ - (void)addEntriesFromConfig:(nonnull const EXModulesProxyConfig*)config
54
+ {
55
+ [_exportedConstants addEntriesFromDictionary:config.exportedConstants];
56
+ [_methodNames addEntriesFromDictionary:config.methodNames];
57
+ [_viewManagerMetadata addEntriesFromDictionary:config.viewManagerMetadata];
58
+ }
59
+
60
+ - (nonnull NSDictionary<NSString *, id> *)toDictionary
61
+ {
62
+ NSMutableDictionary <NSString *, id> *constantsAccumulator = [NSMutableDictionary dictionary];
63
+ constantsAccumulator[viewManagersMetadataKeyPath] = _viewManagerMetadata;
64
+ constantsAccumulator[exportedConstantsKeyPath] = _exportedConstants;
65
+ constantsAccumulator[exportedMethodsNamesKeyPath] = _methodNames;
66
+ return constantsAccumulator;
67
+ }
68
+
69
+ @end
70
+
31
71
  @interface RCTBridge (RegisterAdditionalModuleClasses)
32
72
 
33
73
  - (NSArray<RCTModuleData *> *)registerModulesForClasses:(NSArray<Class> *)moduleClasses;
@@ -51,9 +91,12 @@ static const NSString *methodInfoArgumentsCountKey = @"argumentsCount";
51
91
 
52
92
  @end
53
93
 
54
- @implementation EXNativeModulesProxy
94
+ @implementation EXNativeModulesProxy {
95
+ __weak EXAppContext * _Nullable _appContext;
96
+ }
55
97
 
56
98
  @synthesize bridge = _bridge;
99
+ @synthesize nativeModulesConfig = _nativeModulesConfig;
57
100
 
58
101
  RCT_EXPORT_MODULE(NativeUnimoduleProxy)
59
102
 
@@ -65,7 +108,6 @@ RCT_EXPORT_MODULE(NativeUnimoduleProxy)
65
108
  {
66
109
  if (self = [super init]) {
67
110
  _exModuleRegistry = moduleRegistry != nil ? moduleRegistry : [[EXModuleRegistryProvider new] moduleRegistry];
68
- _swiftInteropBridge = [[SwiftInteropBridge alloc] initWithModulesProvider:[EXNativeModulesProxy getExpoModulesProvider] legacyModuleRegistry:_exModuleRegistry];
69
111
  _exportedMethodsKeys = [NSMutableDictionary dictionary];
70
112
  _exportedMethodsReverseKeys = [NSMutableDictionary dictionary];
71
113
  _ownsModuleRegistry = moduleRegistry == nil;
@@ -73,6 +115,18 @@ RCT_EXPORT_MODULE(NativeUnimoduleProxy)
73
115
  return self;
74
116
  }
75
117
 
118
+ /**
119
+ The initializer for Expo Go to pass a custom `EXModuleRegistry`
120
+ other than the default one from `EXModuleRegistryProvider`.
121
+ The `EXModuleRegistry` is still owned by this class.
122
+ */
123
+ - (instancetype)initWithCustomModuleRegistry:(nonnull EXModuleRegistry *)moduleRegistry
124
+ {
125
+ self = [self initWithModuleRegistry:moduleRegistry];
126
+ self.ownsModuleRegistry = YES;
127
+ return self;
128
+ }
129
+
76
130
  /**
77
131
  Convenience initializer used by React Native in the new setup, where the modules are registered automatically.
78
132
  */
@@ -88,12 +142,12 @@ RCT_EXPORT_MODULE(NativeUnimoduleProxy)
88
142
  return YES;
89
143
  }
90
144
 
91
- - (NSDictionary *)constantsToExport
145
+ - (nonnull EXModulesProxyConfig *)nativeModulesConfig
92
146
  {
93
- // Install ExpoModules host object in the runtime. It's probably not the right place,
94
- // but it's the earliest moment in bridge's lifecycle when we have access to the runtime.
95
- [self installExpoModulesHostObject];
96
-
147
+ if (_nativeModulesConfig) {
148
+ return _nativeModulesConfig;
149
+ }
150
+
97
151
  NSMutableDictionary <NSString *, id> *exportedModulesConstants = [NSMutableDictionary dictionary];
98
152
  // Grab all the constants exported by modules
99
153
  for (EXExportedModule *exportedModule in [_exModuleRegistry getAllExportedModules]) {
@@ -103,7 +157,6 @@ RCT_EXPORT_MODULE(NativeUnimoduleProxy)
103
157
  continue;
104
158
  }
105
159
  }
106
- [exportedModulesConstants addEntriesFromDictionary:[_swiftInteropBridge exportedModulesConstants]];
107
160
 
108
161
  // Also add `exportedMethodsNames`
109
162
  NSMutableDictionary<const NSString *, NSMutableArray<NSMutableDictionary<const NSString *, id> *> *> *exportedMethodsNamesAccumulator = [NSMutableDictionary dictionary];
@@ -120,10 +173,7 @@ RCT_EXPORT_MODULE(NativeUnimoduleProxy)
120
173
  }];
121
174
  [self assignExportedMethodsKeys:exportedMethodsNamesAccumulator[exportedModuleName] forModuleName:exportedModuleName];
122
175
  }
123
-
124
- // Add entries from Swift modules
125
- [exportedMethodsNamesAccumulator addEntriesFromDictionary:[_swiftInteropBridge exportedFunctionNames]];
126
-
176
+
127
177
  // Also, add `viewManagersMetadata` for sanity check and testing purposes -- with names we know what managers to mock on UIManager
128
178
  NSArray<EXViewManager *> *viewManagers = [_exModuleRegistry getAllViewManagers];
129
179
  NSMutableDictionary<NSString *, NSDictionary *> *viewManagersMetadata = [[NSMutableDictionary alloc] initWithCapacity:[viewManagers count]];
@@ -133,20 +183,29 @@ RCT_EXPORT_MODULE(NativeUnimoduleProxy)
133
183
  @"propsNames": [[viewManager getPropsNames] allKeys]
134
184
  };
135
185
  }
186
+
187
+ EXModulesProxyConfig *config = [[EXModulesProxyConfig alloc] initWithConstants:exportedModulesConstants
188
+ methodNames:exportedMethodsNamesAccumulator
189
+ viewManagers:viewManagersMetadata];
190
+ // decorate legacy config with sweet expo-modules config
191
+ [config addEntriesFromConfig:[_appContext expoModulesConfig]];
192
+
193
+ _nativeModulesConfig = config;
194
+ return config;
195
+ }
136
196
 
137
- // Add entries from Swift view managers
138
- [viewManagersMetadata addEntriesFromDictionary:[_swiftInteropBridge viewManagersMetadata]];
139
-
140
- NSMutableDictionary <NSString *, id> *constantsAccumulator = [NSMutableDictionary dictionary];
141
- constantsAccumulator[viewManagersMetadataKeyPath] = viewManagersMetadata;
142
- constantsAccumulator[exportedConstantsKeyPath] = exportedModulesConstants;
143
- constantsAccumulator[exportedMethodsNamesKeyPath] = exportedMethodsNamesAccumulator;
144
-
145
- return constantsAccumulator;
197
+ - (nonnull NSDictionary *)constantsToExport
198
+ {
199
+ return [self.nativeModulesConfig toDictionary];
146
200
  }
147
201
 
148
202
  - (void)setBridge:(RCTBridge *)bridge
149
203
  {
204
+ ExpoBridgeModule* expoBridgeModule = [bridge moduleForClass:ExpoBridgeModule.class];
205
+ [expoBridgeModule legacyProxyDidSetBridgeWithLegacyModulesProxy:self
206
+ legacyModuleRegistry:_exModuleRegistry];
207
+ _appContext = [expoBridgeModule appContext];
208
+
150
209
  if (!_bridge) {
151
210
  // The `setBridge` can be called during module setup or after. Registering more modules
152
211
  // during setup causes a crash due to mutating `_moduleDataByID` while it's being enumerated.
@@ -159,16 +218,17 @@ RCT_EXPORT_MODULE(NativeUnimoduleProxy)
159
218
  });
160
219
  }
161
220
  }
162
- [_swiftInteropBridge setReactBridge:bridge];
163
221
  _bridge = bridge;
164
222
  }
165
223
 
166
224
  RCT_EXPORT_METHOD(callMethod:(NSString *)moduleName methodNameOrKey:(id)methodNameOrKey arguments:(NSArray *)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
167
225
  {
168
- if ([_swiftInteropBridge hasModule:moduleName]) {
169
- [_swiftInteropBridge callFunction:methodNameOrKey onModule:moduleName withArgs:arguments resolve:resolve reject:reject];
226
+ // Backwards compatibility for the new architecture
227
+ if ([_appContext hasModule:moduleName]) {
228
+ [_appContext callFunction:methodNameOrKey onModule:moduleName withArgs:arguments resolve:resolve reject:reject];
170
229
  return;
171
230
  }
231
+
172
232
  EXExportedModule *module = [_exModuleRegistry getExportedModuleForName:moduleName];
173
233
  if (module == nil) {
174
234
  NSString *reason = [NSString stringWithFormat:@"No exported module was found for name '%@'. Are you sure all the packages are linked correctly?", moduleName];
@@ -201,42 +261,6 @@ RCT_EXPORT_METHOD(callMethod:(NSString *)moduleName methodNameOrKey:(id)methodNa
201
261
  });
202
262
  }
203
263
 
204
- - (id)callMethodSync:(NSString *)moduleName methodName:(NSString *)methodName arguments:(NSArray *)arguments
205
- {
206
- if ([_swiftInteropBridge hasModule:moduleName]) {
207
- return [_swiftInteropBridge callFunctionSync:methodName onModule:moduleName withArgs:arguments];
208
- }
209
- return (id)kCFNull;
210
- }
211
-
212
- #pragma mark - Statics
213
-
214
- + (ModulesProvider *)getExpoModulesProvider
215
- {
216
- // Dynamically gets the modules provider class.
217
- // NOTE: This needs to be versioned in Expo Go.
218
- Class generatedExpoModulesProvider;
219
-
220
- // [0] When ExpoModulesCore is built as separated framework/module,
221
- // we should explicitly load main bundle's `ExpoModulesProvider` class.
222
- NSString *bundleName = NSBundle.mainBundle.infoDictionary[@"CFBundleName"];
223
- if (bundleName != nil) {
224
- generatedExpoModulesProvider = NSClassFromString([NSString stringWithFormat:@"%@.ExpoModulesProvider", bundleName]);
225
- if (generatedExpoModulesProvider != nil) {
226
- return [generatedExpoModulesProvider new];
227
- }
228
- }
229
-
230
- // [1] Fallback to load `ExpoModulesProvider` class from the current module.
231
- generatedExpoModulesProvider = NSClassFromString(@"ExpoModulesProvider");
232
- if (generatedExpoModulesProvider != nil) {
233
- return [generatedExpoModulesProvider new];
234
- }
235
-
236
- // [2] Fallback to load `ModulesProvider` if `ExpoModulesProvider` was not generated
237
- return [ModulesProvider new];
238
- }
239
-
240
264
  #pragma mark - Privates
241
265
 
242
266
  - (void)registerExpoModulesInBridge:(RCTBridge *)bridge
@@ -250,7 +274,7 @@ RCT_EXPORT_METHOD(callMethod:(NSString *)moduleName methodNameOrKey:(id)methodNa
250
274
  NSMutableSet *visitedSweetModules = [NSMutableSet new];
251
275
 
252
276
  // Add dynamic wrappers for view modules written in Sweet API.
253
- for (ViewModuleWrapper *swiftViewModule in [_swiftInteropBridge getViewManagers]) {
277
+ for (ViewModuleWrapper *swiftViewModule in [_appContext getViewManagers]) {
254
278
  Class wrappedViewModuleClass = [self registerComponentData:swiftViewModule inBridge:bridge];
255
279
  [additionalModuleClasses addObject:wrappedViewModuleClass];
256
280
  [visitedSweetModules addObject:swiftViewModule.name];
@@ -300,7 +324,7 @@ RCT_EXPORT_METHOD(callMethod:(NSString *)moduleName methodNameOrKey:(id)methodNa
300
324
 
301
325
  // Get the instance of `EXReactEventEmitter` bridge module and give it access to the interop bridge.
302
326
  EXReactNativeEventEmitter *eventEmitter = [bridge moduleForClass:[EXReactNativeEventEmitter class]];
303
- [eventEmitter setSwiftInteropBridge:_swiftInteropBridge];
327
+ [eventEmitter setAppContext:_appContext];
304
328
 
305
329
  // As the last step, when the registry is owned,
306
330
  // register the event emitter and initialize the registry.
@@ -405,19 +429,4 @@ RCT_EXPORT_METHOD(callMethod:(NSString *)moduleName methodNameOrKey:(id)methodNa
405
429
  }
406
430
  }
407
431
 
408
- /**
409
- Installs ExpoModules host object in the runtime that the current bridge operates on.
410
- */
411
- - (void)installExpoModulesHostObject
412
- {
413
- facebook::jsi::Runtime *jsiRuntime = [_bridge respondsToSelector:@selector(runtime)] ? reinterpret_cast<facebook::jsi::Runtime *>(_bridge.runtime) : nullptr;
414
-
415
- if (jsiRuntime) {
416
- EXJavaScriptRuntime *runtime = [[EXJavaScriptRuntime alloc] initWithRuntime:jsiRuntime callInvoker:_bridge.jsCallInvoker];
417
-
418
- [EXJavaScriptRuntimeManager installExpoModulesToRuntime:runtime withSwiftInterop:_swiftInteropBridge];
419
- [_swiftInteropBridge setRuntime:runtime];
420
- }
421
- }
422
-
423
432
  @end
@@ -0,0 +1,17 @@
1
+ import Foundation
2
+
3
+ public class NativeModulesProxyModule: Module {
4
+ public static let moduleName = "NativeModulesProxy"
5
+
6
+ public func definition() -> ModuleDefinition {
7
+ Name(Self.moduleName)
8
+
9
+ Constants { () -> [String: Any?] in
10
+ guard let config = self.appContext?.legacyModulesProxy?.nativeModulesConfig else {
11
+ // TODO: Throw, but what?
12
+ return [:]
13
+ }
14
+ return config.toDictionary()
15
+ }
16
+ }
17
+ }
@@ -9,10 +9,10 @@
9
9
 
10
10
  // Swift compatibility headers (e.g. `ExpoModulesCore-Swift.h`) are not available in headers,
11
11
  // so we use class forward declaration here. Swift header must be imported in the `.m` file.
12
- @class SwiftInteropBridge;
12
+ @class EXAppContext;
13
13
 
14
14
  @interface EXReactNativeEventEmitter : RCTEventEmitter <EXInternalModule, EXBridgeModule, EXModuleRegistryConsumer, EXEventEmitterService>
15
15
 
16
- @property (nonatomic, strong) SwiftInteropBridge *swiftInteropBridge;
16
+ @property (nonatomic, strong) EXAppContext *appContext;
17
17
 
18
18
  @end
@@ -44,8 +44,9 @@
44
44
  {
45
45
  NSMutableSet<NSString *> *eventsAccumulator = [NSMutableSet set];
46
46
 
47
- if (_swiftInteropBridge) {
48
- [eventsAccumulator addObjectsFromArray:[_swiftInteropBridge getSupportedEvents]];
47
+ // Backwards compatibility for the new architecture
48
+ if (_appContext) {
49
+ [eventsAccumulator addObjectsFromArray:[_appContext getSupportedEvents]];
49
50
  }
50
51
  for (EXExportedModule *exportedModule in [_exModuleRegistry getAllExportedModules]) {
51
52
  if ([exportedModule conformsToProtocol:@protocol(EXEventEmitter)]) {
@@ -60,10 +61,12 @@ RCT_EXPORT_METHOD(addProxiedListener:(NSString *)moduleName eventName:(NSString
60
61
  {
61
62
  [self addListener:eventName];
62
63
 
63
- if ([_swiftInteropBridge hasModule:moduleName]) {
64
- [_swiftInteropBridge modifyEventListenersCount:moduleName count:1];
64
+ // Backwards compatibility for the new architecture
65
+ if ([_appContext hasModule:moduleName]) {
66
+ [_appContext modifyEventListenersCount:moduleName count:1];
65
67
  return;
66
68
  }
69
+
67
70
  // Validate module
68
71
  EXExportedModule *module = [_exModuleRegistry getExportedModuleForName:moduleName];
69
72
 
@@ -101,10 +104,12 @@ RCT_EXPORT_METHOD(removeProxiedListeners:(NSString *)moduleName count:(double)co
101
104
  {
102
105
  [self removeListeners:count];
103
106
 
104
- if ([_swiftInteropBridge hasModule:moduleName]) {
105
- [_swiftInteropBridge modifyEventListenersCount:moduleName count:-count];
107
+ // Backwards compatibility for the new architecture
108
+ if ([_appContext hasModule:moduleName]) {
109
+ [_appContext modifyEventListenersCount:moduleName count:-count];
106
110
  return;
107
111
  }
112
+
108
113
  // Validate module
109
114
  EXExportedModule *module = [_exModuleRegistry getExportedModuleForName:moduleName];
110
115