expo-modules-core 0.6.4 → 0.7.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.
- package/CHANGELOG.md +20 -0
- package/README.md +1 -1
- package/android/build.gradle +5 -5
- package/android/src/main/java/expo/modules/kotlin/AppContext.kt +11 -1
- package/android/src/main/java/expo/modules/kotlin/DynamicExtenstions.kt +5 -3
- package/android/src/main/java/expo/modules/kotlin/KPromiseWrapper.kt +8 -2
- package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +13 -4
- package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +7 -6
- package/android/src/main/java/expo/modules/kotlin/ModuleRegistry.kt +6 -1
- package/android/src/main/java/expo/modules/kotlin/Promise.kt +1 -1
- package/android/src/main/java/expo/modules/kotlin/callbacks/Callback.kt +5 -0
- package/android/src/main/java/expo/modules/kotlin/callbacks/ViewCallback.kt +28 -0
- package/android/src/main/java/expo/modules/kotlin/callbacks/ViewCallbackDelegate.kt +27 -0
- package/android/src/main/java/expo/modules/kotlin/defaultmodules/ErrorManagerModule.kt +25 -0
- package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +68 -8
- package/android/src/main/java/expo/modules/kotlin/exception/ExceptionDecorator.kt +11 -0
- package/android/src/main/java/expo/modules/kotlin/methods/AnyMethod.kt +13 -14
- package/android/src/main/java/expo/modules/kotlin/modules/DefinitionMarker.kt +4 -0
- package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +3 -2
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +44 -4
- package/android/src/main/java/expo/modules/kotlin/records/Record.kt +39 -0
- package/android/src/main/java/expo/modules/kotlin/records/RecordTypeConverter.kt +14 -7
- package/android/src/main/java/expo/modules/kotlin/types/ArrayTypeConverter.kt +11 -5
- package/android/src/main/java/expo/modules/kotlin/types/ListTypeConverter.kt +10 -4
- package/android/src/main/java/expo/modules/kotlin/types/MapTypeConverter.kt +12 -6
- package/android/src/main/java/expo/modules/kotlin/types/PairTypeConverter.kt +29 -13
- package/android/src/main/java/expo/modules/kotlin/types/TypeConverter.kt +2 -1
- package/android/src/main/java/expo/modules/kotlin/views/CallbacksDefinition.kt +3 -0
- package/android/src/main/java/expo/modules/kotlin/views/GroupViewManagerWrapper.kt +22 -0
- package/android/src/main/java/expo/modules/kotlin/views/SimpleViewManagerWrapper.kt +22 -0
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinition.kt +27 -2
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +29 -1
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerWrapperDelegate.kt +59 -2
- package/build/EventEmitter.d.ts +1 -0
- package/build/EventEmitter.d.ts.map +1 -0
- package/build/NativeModulesProxy.d.ts +1 -0
- package/build/NativeModulesProxy.d.ts.map +1 -0
- package/build/NativeModulesProxy.native.d.ts +1 -0
- package/build/NativeModulesProxy.native.d.ts.map +1 -0
- package/build/NativeModulesProxy.types.d.ts +1 -0
- package/build/NativeModulesProxy.types.d.ts.map +1 -0
- package/build/NativeViewManagerAdapter.d.ts +1 -0
- package/build/NativeViewManagerAdapter.d.ts.map +1 -0
- package/build/NativeViewManagerAdapter.native.d.ts +1 -0
- package/build/NativeViewManagerAdapter.native.d.ts.map +1 -0
- package/build/PermissionsHook.d.ts +1 -0
- package/build/PermissionsHook.d.ts.map +1 -0
- package/build/PermissionsInterface.d.ts +1 -0
- package/build/PermissionsInterface.d.ts.map +1 -0
- package/build/Platform.d.ts +1 -0
- package/build/Platform.d.ts.map +1 -0
- package/build/SyntheticPlatformEmitter.d.ts +1 -0
- package/build/SyntheticPlatformEmitter.d.ts.map +1 -0
- package/build/SyntheticPlatformEmitter.web.d.ts +1 -0
- package/build/SyntheticPlatformEmitter.web.d.ts.map +1 -0
- package/build/deprecate.d.ts +1 -0
- package/build/deprecate.d.ts.map +1 -0
- package/build/environment/browser.d.ts +1 -0
- package/build/environment/browser.d.ts.map +1 -0
- package/build/environment/browser.web.d.ts +1 -0
- package/build/environment/browser.web.d.ts.map +1 -0
- package/build/errors/CodedError.d.ts +1 -0
- package/build/errors/CodedError.d.ts.map +1 -0
- package/build/errors/UnavailabilityError.d.ts +1 -0
- package/build/errors/UnavailabilityError.d.ts.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/requireNativeModule.d.ts +16 -0
- package/build/requireNativeModule.d.ts.map +1 -0
- package/build/requireNativeModule.js +18 -0
- package/build/requireNativeModule.js.map +1 -0
- package/build/sweet/NativeErrorManager.d.ts +3 -0
- package/build/sweet/NativeErrorManager.d.ts.map +1 -0
- package/build/sweet/NativeErrorManager.js +3 -0
- package/build/sweet/NativeErrorManager.js.map +1 -0
- package/build/sweet/setUpErrorManager.fx.d.ts +2 -0
- package/build/sweet/setUpErrorManager.fx.d.ts.map +1 -0
- package/build/sweet/setUpErrorManager.fx.js +11 -0
- package/build/sweet/setUpErrorManager.fx.js.map +1 -0
- package/ios/AppDelegates/ExpoAppDelegate.swift +18 -10
- package/ios/JSI/ExpoModulesHostObject.h +33 -0
- package/ios/JSI/ExpoModulesHostObject.mm +40 -0
- package/ios/JSI/ExpoModulesProxySpec.h +4 -0
- package/ios/JSI/ExpoModulesProxySpec.mm +1 -3
- package/ios/JSI/JSIConversions.h +2 -0
- package/ios/JSI/JSIConversions.mm +9 -0
- package/ios/JSI/JSIInstaller.h +10 -0
- package/ios/JSI/JSIInstaller.mm +14 -2
- package/ios/JSI/JavaScriptObject.h +60 -0
- package/ios/JSI/JavaScriptObject.mm +93 -0
- package/ios/JSI/JavaScriptRuntime.h +54 -0
- package/ios/JSI/JavaScriptRuntime.mm +102 -0
- package/ios/ModuleRegistryAdapter/EXModuleRegistryAdapter.m +2 -12
- package/ios/NativeModulesProxy/EXComponentDataCompatibleWrapper.h +16 -0
- package/ios/NativeModulesProxy/EXComponentDataCompatibleWrapper.m +28 -0
- package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +90 -66
- package/ios/RCTComponentData+Privates.h +12 -0
- package/ios/ReactDelegates/ExpoReactDelegate.swift +2 -2
- package/ios/ReactDelegates/ExpoReactDelegateHandler.swift +3 -3
- package/ios/ReactDelegates/ModulePriorities.swift +1 -1
- package/ios/Swift/AppContext.swift +38 -4
- package/ios/Swift/Arguments/ArgumentType.swift +4 -0
- package/ios/Swift/Arguments/Convertibles.swift +13 -13
- package/ios/Swift/Arguments/Types/EnumArgumentType.swift +11 -17
- package/ios/Swift/Arguments/Types/PromiseArgumentType.swift +1 -1
- package/ios/Swift/Arguments/Types/RawArgumentType.swift +2 -2
- package/ios/Swift/Conversions.swift +51 -56
- package/ios/Swift/EventListener.swift +8 -10
- package/ios/Swift/Events/Callback.swift +66 -0
- package/ios/Swift/Events/Event.swift +43 -0
- package/ios/Swift/Exceptions/ChainableException.swift +51 -0
- package/ios/Swift/{CodedError.swift → Exceptions/CodedError.swift} +1 -12
- package/ios/Swift/Exceptions/Exception.swift +62 -0
- package/ios/Swift/Exceptions/ExceptionOrigin.swift +28 -0
- package/ios/Swift/Exceptions/GenericException.swift +20 -0
- package/ios/Swift/Exceptions/UnexpectedException.swift +16 -0
- package/ios/Swift/Functions/AnyFunction.swift +11 -1
- package/ios/Swift/Functions/ConcreteFunction.swift +37 -16
- package/ios/Swift/JavaScriptUtils.swift +43 -0
- package/ios/Swift/ModuleHolder.swift +53 -14
- package/ios/Swift/ModuleRegistry.swift +4 -1
- package/ios/Swift/Modules/AnyModule.swift +0 -1
- package/ios/Swift/Modules/ModuleDefinition.swift +4 -13
- package/ios/Swift/Modules/ModuleDefinitionBuilder.swift +0 -1
- package/ios/Swift/Modules/ModuleDefinitionComponents.swift +0 -188
- package/ios/Swift/ModulesProvider.swift +0 -1
- package/ios/Swift/Objects/ObjectDefinition.swift +30 -0
- package/ios/Swift/Objects/ObjectDefinitionComponents.swift +208 -0
- package/ios/Swift/Promise.swift +8 -3
- package/ios/Swift/Records/AnyField.swift +7 -0
- package/ios/Swift/Records/Field.swift +24 -19
- package/ios/Swift/Records/FieldOption.swift +1 -1
- package/ios/Swift/Records/Record.swift +12 -4
- package/ios/Swift/SwiftInteropBridge.swift +39 -10
- package/ios/Swift/Views/AnyViewProp.swift +1 -1
- package/ios/Swift/Views/ComponentData.swift +95 -0
- package/ios/Swift/Views/ConcreteViewProp.swift +6 -8
- package/ios/Swift/Views/ViewFactory.swift +1 -1
- package/ios/Swift/Views/ViewManagerDefinition.swift +23 -2
- package/ios/Swift/Views/ViewManagerDefinitionBuilder.swift +0 -1
- package/ios/Swift/Views/ViewManagerDefinitionComponents.swift +26 -0
- package/ios/Swift/Views/ViewModuleWrapper.swift +5 -2
- package/ios/Tests/ArgumentTypeSpec.swift +3 -4
- package/ios/Tests/ConstantsSpec.swift +4 -4
- package/ios/Tests/ConvertiblesSpec.swift +33 -33
- package/ios/Tests/ExceptionsSpec.swift +112 -0
- package/ios/Tests/FunctionSpec.swift +20 -22
- package/ios/Tests/FunctionWithConvertiblesSpec.swift +2 -2
- package/ios/Tests/Mocks/ModuleMocks.swift +1 -1
- package/ios/Tests/Mocks/ModulesProviderMock.swift +0 -1
- package/ios/Tests/ModuleEventListenersSpec.swift +1 -1
- package/ios/Tests/RecordSpec.swift +7 -17
- package/package.json +3 -3
- package/src/index.ts +4 -0
- package/src/requireNativeModule.ts +29 -0
- package/src/sweet/NativeErrorManager.ts +2 -0
- package/src/sweet/setUpErrorManager.fx.ts +12 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyntheticPlatformEmitter.web.d.ts","sourceRoot":"","sources":["../src/SyntheticPlatformEmitter.web.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,oFAAoF,CAAC"}
|
package/build/deprecate.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecate.d.ts","sourceRoot":"","sources":["../src/deprecate.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;CACrB,GACL,IAAI,CAgCN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/environment/browser.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,QAAQ,CAAC;AACpC,eAAO,MAAM,oBAAoB,QAAQ,CAAC;AAC1C,eAAO,MAAM,cAAc,QAAQ,CAAC;AAEpC,eAAO,IAAI,gBAAgB,EAAE,OAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.web.d.ts","sourceRoot":"","sources":["../../src/environment/browser.web.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,MAAM;QACd,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC;KAC9D;CACF;AAID,eAAO,MAAM,cAAc,SAAoE,CAAC;AAChG,eAAO,MAAM,oBAAoB,SACoC,CAAC;AACtE,eAAO,MAAM,cAAc,SAAoC,CAAC;AAChE,eAAO,MAAM,gBAAgB,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodedError.d.ts","sourceRoot":"","sources":["../../src/errors/CodedError.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,CAAC;gBAEC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnavailabilityError.d.ts","sourceRoot":"","sources":["../../src/errors/UnavailabilityError.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,UAAU;gBACrC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAMrD"}
|
package/build/index.d.ts
CHANGED
|
@@ -7,11 +7,14 @@ import Platform from './Platform';
|
|
|
7
7
|
import SyntheticPlatformEmitter from './SyntheticPlatformEmitter';
|
|
8
8
|
import { CodedError } from './errors/CodedError';
|
|
9
9
|
import { UnavailabilityError } from './errors/UnavailabilityError';
|
|
10
|
+
import './sweet/setUpErrorManager.fx';
|
|
10
11
|
export { default as deprecate } from './deprecate';
|
|
11
12
|
export { DeviceEventEmitter, EventEmitter, NativeModulesProxy, ProxyNativeModule, Platform, Subscription, SyntheticPlatformEmitter, requireNativeViewManager, CodedError, UnavailabilityError, };
|
|
13
|
+
export * from './requireNativeModule';
|
|
12
14
|
/**
|
|
13
15
|
* @deprecated renamed to `DeviceEventEmitter`
|
|
14
16
|
*/
|
|
15
17
|
export declare const RCTDeviceEventEmitter: import("react-native").DeviceEventEmitterStatic;
|
|
16
18
|
export * from './PermissionsInterface';
|
|
17
19
|
export * from './PermissionsHook';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,8BAA8B,CAAC;AAEtC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,QAAQ,EACR,YAAY,EACZ,wBAAwB,EACxB,wBAAwB,EAExB,UAAU,EACV,mBAAmB,GACpB,CAAC;AAEF,cAAc,uBAAuB,CAAC;AAEtC;;GAEG;AACH,eAAO,MAAM,qBAAqB,iDAAqB,CAAC;AAExD,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -6,10 +6,12 @@ import Platform from './Platform';
|
|
|
6
6
|
import SyntheticPlatformEmitter from './SyntheticPlatformEmitter';
|
|
7
7
|
import { CodedError } from './errors/CodedError';
|
|
8
8
|
import { UnavailabilityError } from './errors/UnavailabilityError';
|
|
9
|
+
import './sweet/setUpErrorManager.fx';
|
|
9
10
|
export { default as deprecate } from './deprecate';
|
|
10
11
|
export { DeviceEventEmitter, EventEmitter, NativeModulesProxy, Platform, SyntheticPlatformEmitter, requireNativeViewManager,
|
|
11
12
|
// Errors
|
|
12
13
|
CodedError, UnavailabilityError, };
|
|
14
|
+
export * from './requireNativeModule';
|
|
13
15
|
/**
|
|
14
16
|
* @deprecated renamed to `DeviceEventEmitter`
|
|
15
17
|
*/
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,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,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAElB,QAAQ,EAER,wBAAwB,EACxB,wBAAwB;AACxB,SAAS;AACT,UAAU,EACV,mBAAmB,GACpB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAExD,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC","sourcesContent":["import { DeviceEventEmitter } from 'react-native';\n\nimport { 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';\nimport { CodedError } from './errors/CodedError';\nimport { UnavailabilityError } from './errors/UnavailabilityError';\n\nexport { default as deprecate } from './deprecate';\n\nexport {\n DeviceEventEmitter,\n EventEmitter,\n NativeModulesProxy,\n ProxyNativeModule,\n Platform,\n Subscription,\n SyntheticPlatformEmitter,\n requireNativeViewManager,\n // Errors\n CodedError,\n UnavailabilityError,\n};\n\n/**\n * @deprecated renamed to `DeviceEventEmitter`\n */\nexport const RCTDeviceEventEmitter = DeviceEventEmitter;\n\nexport * from './PermissionsInterface';\nexport * from './PermissionsHook';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,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,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,8BAA8B,CAAC;AAEtC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAElB,QAAQ,EAER,wBAAwB,EACxB,wBAAwB;AACxB,SAAS;AACT,UAAU,EACV,mBAAmB,GACpB,CAAC;AAEF,cAAc,uBAAuB,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAExD,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC","sourcesContent":["import { DeviceEventEmitter } from 'react-native';\n\nimport { 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';\nimport { CodedError } from './errors/CodedError';\nimport { UnavailabilityError } from './errors/UnavailabilityError';\n\nimport './sweet/setUpErrorManager.fx';\n\nexport { default as deprecate } from './deprecate';\n\nexport {\n DeviceEventEmitter,\n EventEmitter,\n NativeModulesProxy,\n ProxyNativeModule,\n Platform,\n Subscription,\n SyntheticPlatformEmitter,\n requireNativeViewManager,\n // Errors\n CodedError,\n UnavailabilityError,\n};\n\nexport * from './requireNativeModule';\n\n/**\n * @deprecated renamed to `DeviceEventEmitter`\n */\nexport const RCTDeviceEventEmitter = DeviceEventEmitter;\n\nexport * from './PermissionsInterface';\nexport * from './PermissionsHook';\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
var ExpoModules: undefined | {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Imports the native module registered with given name. In the first place it tries to load
|
|
8
|
+
* the module installed through the JSI host object and then falls back to the bridge proxy module.
|
|
9
|
+
* Notice that the modules loaded from the proxy may not support some features like synchronous functions.
|
|
10
|
+
*
|
|
11
|
+
* @param moduleName Name of the requested native module.
|
|
12
|
+
* @returns Object representing the native module.
|
|
13
|
+
* @throws Error when there is no native module with given name.
|
|
14
|
+
*/
|
|
15
|
+
export declare function requireNativeModule<ModuleType = any>(moduleName: string): ModuleType;
|
|
16
|
+
//# sourceMappingURL=requireNativeModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requireNativeModule.d.ts","sourceRoot":"","sources":["../src/requireNativeModule.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,WAAW,EACX,SAAS,GACT;QACE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACP;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,GAAG,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,UAAU,CAQpF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import NativeModulesProxy from './NativeModulesProxy';
|
|
2
|
+
/**
|
|
3
|
+
* Imports the native module registered with given name. In the first place it tries to load
|
|
4
|
+
* the module installed through the JSI host object and then falls back to the bridge proxy module.
|
|
5
|
+
* Notice that the modules loaded from the proxy may not support some features like synchronous functions.
|
|
6
|
+
*
|
|
7
|
+
* @param moduleName Name of the requested native module.
|
|
8
|
+
* @returns Object representing the native module.
|
|
9
|
+
* @throws Error when there is no native module with given name.
|
|
10
|
+
*/
|
|
11
|
+
export function requireNativeModule(moduleName) {
|
|
12
|
+
const nativeModule = global.ExpoModules?.[moduleName] ?? NativeModulesProxy[moduleName];
|
|
13
|
+
if (!nativeModule) {
|
|
14
|
+
throw new Error(`Cannot find native module '${moduleName}'`);
|
|
15
|
+
}
|
|
16
|
+
return nativeModule;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=requireNativeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requireNativeModule.js","sourceRoot":"","sources":["../src/requireNativeModule.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAWtD;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAmB,UAAkB;IACtE,MAAM,YAAY,GAChB,MAAM,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,IAAI,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAErE,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,8BAA8B,UAAU,GAAG,CAAC,CAAC;KAC9D;IACD,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import NativeModulesProxy from './NativeModulesProxy';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var ExpoModules:\n | undefined\n | {\n [key: string]: any;\n };\n}\n\n/**\n * Imports the native module registered with given name. In the first place it tries to load\n * the module installed through the JSI host object and then falls back to the bridge proxy module.\n * Notice that the modules loaded from the proxy may not support some features like synchronous functions.\n *\n * @param moduleName Name of the requested native module.\n * @returns Object representing the native module.\n * @throws Error when there is no native module with given name.\n */\nexport function requireNativeModule<ModuleType = any>(moduleName: string): ModuleType {\n const nativeModule: ModuleType =\n global.ExpoModules?.[moduleName] ?? NativeModulesProxy[moduleName];\n\n if (!nativeModule) {\n throw new Error(`Cannot find native module '${moduleName}'`);\n }\n return nativeModule;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeErrorManager.d.ts","sourceRoot":"","sources":["../../src/sweet/NativeErrorManager.ts"],"names":[],"mappings":";AACA,wBAA8D"}
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setUpErrorManager.fx.d.ts","sourceRoot":"","sources":["../../src/sweet/setUpErrorManager.fx.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventEmitter } from '../EventEmitter';
|
|
2
|
+
import Platform from '../Platform';
|
|
3
|
+
import NativeErrorManager from './NativeErrorManager';
|
|
4
|
+
if (__DEV__ && Platform.OS === 'android' && NativeErrorManager) {
|
|
5
|
+
const onNewException = 'ExpoModulesCoreErrorManager.onNewException';
|
|
6
|
+
const eventEmitter = new EventEmitter(NativeErrorManager);
|
|
7
|
+
eventEmitter.addListener(onNewException, ({ message }) => {
|
|
8
|
+
console.error(message);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=setUpErrorManager.fx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setUpErrorManager.fx.js","sourceRoot":"","sources":["../../src/sweet/setUpErrorManager.fx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,IAAI,OAAO,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,IAAI,kBAAkB,EAAE;IAC9D,MAAM,cAAc,GAAG,4CAA4C,CAAC;IACpE,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,kBAAkB,CAAC,CAAC;IAE1D,YAAY,CAAC,WAAW,CAAC,cAAc,EAAE,CAAC,EAAE,OAAO,EAAuB,EAAE,EAAE;QAC5E,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;CACJ","sourcesContent":["import { EventEmitter } from '../EventEmitter';\nimport Platform from '../Platform';\nimport NativeErrorManager from './NativeErrorManager';\n\nif (__DEV__ && Platform.OS === 'android' && NativeErrorManager) {\n const onNewException = 'ExpoModulesCoreErrorManager.onNewException';\n const eventEmitter = new EventEmitter(NativeErrorManager);\n\n eventEmitter.addListener(onNewException, ({ message }: { message: string }) => {\n console.error(message);\n });\n}\n"]}
|
|
@@ -20,24 +20,24 @@ open class ExpoAppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
20
20
|
|
|
21
21
|
// MARK: - Initializing the App
|
|
22
22
|
|
|
23
|
-
open func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey
|
|
23
|
+
open func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
|
24
24
|
let parsedSubscribers = subscribers.filter {
|
|
25
25
|
$0.responds(to: #selector(application(_:willFinishLaunchingWithOptions:)))
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
// If we can't find a subscriber that implements `willFinishLaunchingWithOptions`, we will delegate the decision if we can handel the passed URL to
|
|
29
29
|
// the `didFinishLaunchingWithOptions` method by returning `true` here.
|
|
30
30
|
// You can read more about how iOS handles deep links here: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623112-application#discussion
|
|
31
|
-
if
|
|
32
|
-
return true
|
|
31
|
+
if parsedSubscribers.isEmpty {
|
|
32
|
+
return true
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
return parsedSubscribers.reduce(false) { result, subscriber in
|
|
36
36
|
return subscriber.application!(application, willFinishLaunchingWithOptions: launchOptions) || result
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
open func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey
|
|
40
|
+
open func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
|
41
41
|
return subscribers.reduce(false) { result, subscriber in
|
|
42
42
|
return subscriber.application?(application, didFinishLaunchingWithOptions: launchOptions) ?? false || result
|
|
43
43
|
}
|
|
@@ -107,7 +107,11 @@ open class ExpoAppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
107
107
|
subscribers.forEach { $0.application?(application, didFailToRegisterForRemoteNotificationsWithError: error) }
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
open func application(
|
|
110
|
+
open func application(
|
|
111
|
+
_ application: UIApplication,
|
|
112
|
+
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
|
|
113
|
+
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
|
|
114
|
+
) {
|
|
111
115
|
let selector = #selector(application(_:didReceiveRemoteNotification:fetchCompletionHandler:))
|
|
112
116
|
let subs = subscribers.filter { $0.responds(to: selector) }
|
|
113
117
|
var subscribersLeft = subs.count
|
|
@@ -143,7 +147,11 @@ open class ExpoAppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
143
147
|
}
|
|
144
148
|
}
|
|
145
149
|
|
|
146
|
-
open func application(
|
|
150
|
+
open func application(
|
|
151
|
+
_ application: UIApplication,
|
|
152
|
+
continue userActivity: NSUserActivity,
|
|
153
|
+
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
|
|
154
|
+
) -> Bool {
|
|
147
155
|
let selector = #selector(application(_:continue:restorationHandler:))
|
|
148
156
|
let subs = subscribers.filter { $0.responds(to: selector) }
|
|
149
157
|
var subscribersLeft = subs.count
|
|
@@ -238,7 +246,7 @@ open class ExpoAppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
238
246
|
|
|
239
247
|
// MARK: - Opening a URL-Specified Resource
|
|
240
248
|
|
|
241
|
-
open func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey
|
|
249
|
+
open func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
|
|
242
250
|
return subscribers.contains { subscriber in
|
|
243
251
|
return subscriber.application?(app, open: url, options: options) ?? false
|
|
244
252
|
}
|
|
@@ -283,7 +291,7 @@ open class ExpoAppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
283
291
|
fatalError("Expo modules provider must implement `ModulesProviderProtocol`.")
|
|
284
292
|
}
|
|
285
293
|
provider.getReactDelegateHandlers()
|
|
286
|
-
.sorted {
|
|
294
|
+
.sorted { tuple1, tuple2 -> Bool in
|
|
287
295
|
return ModulePriorities.get(tuple1.packageName) > ModulePriorities.get(tuple2.packageName)
|
|
288
296
|
}
|
|
289
297
|
.forEach { handlerTuple in
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2022-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
#ifdef __cplusplus
|
|
4
|
+
|
|
5
|
+
#import <vector>
|
|
6
|
+
#import <jsi/jsi.h>
|
|
7
|
+
|
|
8
|
+
namespace jsi = facebook::jsi;
|
|
9
|
+
|
|
10
|
+
@class SwiftInteropBridge;
|
|
11
|
+
|
|
12
|
+
namespace expo {
|
|
13
|
+
|
|
14
|
+
class JSI_EXPORT ExpoModulesHostObject : public jsi::HostObject {
|
|
15
|
+
public:
|
|
16
|
+
ExpoModulesHostObject(SwiftInteropBridge *interopBridge);
|
|
17
|
+
|
|
18
|
+
virtual ~ExpoModulesHostObject();
|
|
19
|
+
|
|
20
|
+
jsi::Value get(jsi::Runtime &, const jsi::PropNameID &name) override;
|
|
21
|
+
|
|
22
|
+
void set(jsi::Runtime &, const jsi::PropNameID &name, const jsi::Value &value) override;
|
|
23
|
+
|
|
24
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
25
|
+
|
|
26
|
+
private:
|
|
27
|
+
SwiftInteropBridge *swiftInterop;
|
|
28
|
+
|
|
29
|
+
}; // class ExpoModulesHostObject
|
|
30
|
+
|
|
31
|
+
} // namespace expo
|
|
32
|
+
|
|
33
|
+
#endif
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright 2022-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
#import <ExpoModulesCore/ExpoModulesHostObject.h>
|
|
4
|
+
#import <ExpoModulesCore/Swift.h>
|
|
5
|
+
|
|
6
|
+
namespace expo {
|
|
7
|
+
|
|
8
|
+
ExpoModulesHostObject::ExpoModulesHostObject(SwiftInteropBridge *swiftInterop) : swiftInterop(swiftInterop) {}
|
|
9
|
+
|
|
10
|
+
ExpoModulesHostObject::~ExpoModulesHostObject() {
|
|
11
|
+
[swiftInterop setRuntime:nil];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
jsi::Value ExpoModulesHostObject::get(jsi::Runtime &runtime, const jsi::PropNameID &name) {
|
|
15
|
+
NSString *moduleName = [NSString stringWithUTF8String:name.utf8(runtime).c_str()];
|
|
16
|
+
JavaScriptObject *nativeObject = [swiftInterop getNativeModuleObject:moduleName];
|
|
17
|
+
|
|
18
|
+
return nativeObject ? jsi::Value(runtime, *[nativeObject get]) : jsi::Value::undefined();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
void ExpoModulesHostObject::set(jsi::Runtime &runtime, const jsi::PropNameID &name, const jsi::Value &value) {
|
|
22
|
+
std::string message("RuntimeError: Cannot override the host object for expo module '");
|
|
23
|
+
message += name.utf8(runtime);
|
|
24
|
+
message += "'.";
|
|
25
|
+
throw jsi::JSError(runtime, message);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
std::vector<jsi::PropNameID> ExpoModulesHostObject::getPropertyNames(jsi::Runtime &runtime) {
|
|
29
|
+
NSArray<NSString *> *moduleNames = [swiftInterop getModuleNames];
|
|
30
|
+
std::vector<jsi::PropNameID> propertyNames;
|
|
31
|
+
|
|
32
|
+
propertyNames.reserve([moduleNames count]);
|
|
33
|
+
|
|
34
|
+
for (NSString *moduleName in moduleNames) {
|
|
35
|
+
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, [moduleName UTF8String]));
|
|
36
|
+
}
|
|
37
|
+
return propertyNames;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
} // namespace expo
|
|
@@ -12,6 +12,10 @@ using namespace react;
|
|
|
12
12
|
|
|
13
13
|
namespace expo {
|
|
14
14
|
|
|
15
|
+
using PromiseInvocationBlock = void (^)(RCTPromiseResolveBlock resolveWrapper, RCTPromiseRejectBlock rejectWrapper);
|
|
16
|
+
|
|
17
|
+
void callPromiseSetupWithBlock(jsi::Runtime &runtime, std::shared_ptr<CallInvoker> jsInvoker, std::shared_ptr<Promise> promise, PromiseInvocationBlock setupBlock);
|
|
18
|
+
|
|
15
19
|
class JSI_EXPORT ExpoModulesProxySpec : public TurboModule {
|
|
16
20
|
public:
|
|
17
21
|
ExpoModulesProxySpec(std::shared_ptr<CallInvoker> callInvoker, EXNativeModulesProxy *nativeModulesProxy);
|
|
@@ -7,9 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
namespace expo {
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
static void callPromiseSetupWithBlock(jsi::Runtime &runtime, std::shared_ptr<CallInvoker> jsInvoker, std::shared_ptr<Promise> promise, PromiseInvocationBlock setupBlock)
|
|
10
|
+
void callPromiseSetupWithBlock(jsi::Runtime &runtime, std::shared_ptr<CallInvoker> jsInvoker, std::shared_ptr<Promise> promise, PromiseInvocationBlock setupBlock)
|
|
13
11
|
{
|
|
14
12
|
auto weakResolveWrapper = CallbackWrapper::createWeak(promise->resolve_.getFunction(runtime), runtime, jsInvoker);
|
|
15
13
|
auto weakRejectWrapper = CallbackWrapper::createWeak(promise->reject_.getFunction(runtime), runtime, jsInvoker);
|
package/ios/JSI/JSIConversions.h
CHANGED
|
@@ -31,6 +31,8 @@ NSString *convertJSIStringToNSString(jsi::Runtime &runtime, const jsi::String &v
|
|
|
31
31
|
|
|
32
32
|
NSArray *convertJSIArrayToNSArray(jsi::Runtime &runtime, const jsi::Array &value, std::shared_ptr<CallInvoker> jsInvoker);
|
|
33
33
|
|
|
34
|
+
NSArray *convertJSIValuesToNSArray(jsi::Runtime &runtime, const jsi::Value *values, size_t count, std::shared_ptr<CallInvoker> jsInvoker);
|
|
35
|
+
|
|
34
36
|
NSDictionary *convertJSIObjectToNSDictionary(jsi::Runtime &runtime, const jsi::Object &value, std::shared_ptr<CallInvoker> jsInvoker);
|
|
35
37
|
|
|
36
38
|
id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, std::shared_ptr<CallInvoker> jsInvoker);
|
|
@@ -86,6 +86,15 @@ NSArray *convertJSIArrayToNSArray(jsi::Runtime &runtime, const jsi::Array &value
|
|
|
86
86
|
return [result copy];
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
NSArray *convertJSIValuesToNSArray(jsi::Runtime &runtime, const jsi::Value *values, size_t count, std::shared_ptr<CallInvoker> jsInvoker)
|
|
90
|
+
{
|
|
91
|
+
NSMutableArray *result = [NSMutableArray arrayWithCapacity:count];
|
|
92
|
+
for (int i = 0; i < count; i++) {
|
|
93
|
+
result[i] = convertJSIValueToObjCObject(runtime, values[i], jsInvoker);
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
89
98
|
NSDictionary *convertJSIObjectToNSDictionary(jsi::Runtime &runtime, const jsi::Object &value, std::shared_ptr<CallInvoker> jsInvoker)
|
|
90
99
|
{
|
|
91
100
|
jsi::Array propertyNames = value.getPropertyNames(runtime);
|
package/ios/JSI/JSIInstaller.h
CHANGED
|
@@ -17,3 +17,13 @@ void installRuntimeObjects(jsi::Runtime &runtime, std::shared_ptr<CallInvoker> c
|
|
|
17
17
|
} // namespace expo
|
|
18
18
|
|
|
19
19
|
#endif
|
|
20
|
+
|
|
21
|
+
#import <ExpoModulesCore/JavaScriptRuntime.h>
|
|
22
|
+
|
|
23
|
+
@class SwiftInteropBridge;
|
|
24
|
+
|
|
25
|
+
@interface JavaScriptRuntimeManager : NSObject
|
|
26
|
+
|
|
27
|
+
+ (void)installExpoModulesToRuntime:(nonnull JavaScriptRuntime *)runtime withSwiftInterop:(nonnull SwiftInteropBridge *)swiftInterop;
|
|
28
|
+
|
|
29
|
+
@end
|
package/ios/JSI/JSIInstaller.mm
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
#import <ExpoModulesCore/JSIInstaller.h>
|
|
4
4
|
#import <ExpoModulesCore/ExpoModulesProxySpec.h>
|
|
5
|
+
#import <ExpoModulesCore/ExpoModulesHostObject.h>
|
|
6
|
+
#import <ExpoModulesCore/Swift.h>
|
|
5
7
|
|
|
6
8
|
using namespace facebook;
|
|
7
9
|
using namespace react;
|
|
8
10
|
|
|
9
|
-
//using PromiseInvocationBlock = void (^)(RCTPromiseResolveBlock resolveWrapper, RCTPromiseRejectBlock rejectWrapper);
|
|
10
|
-
|
|
11
11
|
namespace expo {
|
|
12
12
|
|
|
13
13
|
void installRuntimeObjects(jsi::Runtime &runtime, std::shared_ptr<CallInvoker> callInvoker, EXNativeModulesProxy *nativeModulesProxy)
|
|
@@ -20,3 +20,15 @@ void installRuntimeObjects(jsi::Runtime &runtime, std::shared_ptr<CallInvoker> c
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
} // namespace expo
|
|
23
|
+
|
|
24
|
+
@implementation JavaScriptRuntimeManager
|
|
25
|
+
|
|
26
|
+
+ (void)installExpoModulesToRuntime:(nonnull JavaScriptRuntime *)runtime withSwiftInterop:(nonnull SwiftInteropBridge *)swiftInterop
|
|
27
|
+
{
|
|
28
|
+
std::shared_ptr<expo::ExpoModulesHostObject> hostObjectPtr = std::make_shared<expo::ExpoModulesHostObject>(swiftInterop);
|
|
29
|
+
JavaScriptObject *global = [runtime global];
|
|
30
|
+
|
|
31
|
+
global[@"ExpoModules"] = [runtime createHostObject:hostObjectPtr];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@end
|
|
@@ -0,0 +1,60 @@
|
|
|
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 JavaScriptRuntime;
|
|
17
|
+
|
|
18
|
+
@interface JavaScriptObject : NSObject
|
|
19
|
+
|
|
20
|
+
// Some parts of the interface must be hidden for Swift – it can't import any C++ code.
|
|
21
|
+
#ifdef __cplusplus
|
|
22
|
+
- (nonnull instancetype)initWith:(std::shared_ptr<jsi::Object>)jsObjectPtr
|
|
23
|
+
runtime:(nonnull JavaScriptRuntime *)runtime;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
Returns the pointer to the underlying object.
|
|
27
|
+
*/
|
|
28
|
+
- (nonnull jsi::Object *)get;
|
|
29
|
+
#endif // __cplusplus
|
|
30
|
+
|
|
31
|
+
#pragma mark - Subscripting
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
Subscript getter. Supports only values convertible to Foundation types, otherwise `nil` is returned.
|
|
35
|
+
*/
|
|
36
|
+
- (nullable id)objectForKeyedSubscript:(nonnull NSString *)key;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
Subscript setter. Only `JavaScriptObject` and Foundation object convertible to JSI values can be used as a value,
|
|
40
|
+
otherwise the property is set to `undefined`.
|
|
41
|
+
*/
|
|
42
|
+
- (void)setObject:(nullable id)obj forKeyedSubscript:(nonnull NSString *)key;
|
|
43
|
+
|
|
44
|
+
#pragma mark - Functions
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
Sets given function block on the object as a host function returning a promise.
|
|
48
|
+
*/
|
|
49
|
+
- (void)setAsyncFunction:(nonnull NSString *)key
|
|
50
|
+
argsCount:(NSInteger)argsCount
|
|
51
|
+
block:(nonnull JSAsyncFunctionBlock)block;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
Sets given synchronous function block as a host function on the object.
|
|
55
|
+
*/
|
|
56
|
+
- (void)setSyncFunction:(nonnull NSString *)name
|
|
57
|
+
argsCount:(NSInteger)argsCount
|
|
58
|
+
block:(nonnull JSSyncFunctionBlock)block;
|
|
59
|
+
|
|
60
|
+
@end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Copyright 2022-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
#import <ExpoModulesCore/JSIConversions.h>
|
|
4
|
+
#import <ExpoModulesCore/JavaScriptObject.h>
|
|
5
|
+
#import <ExpoModulesCore/JavaScriptRuntime.h>
|
|
6
|
+
#import <ExpoModulesCore/ExpoModulesProxySpec.h>
|
|
7
|
+
|
|
8
|
+
@implementation JavaScriptObject {
|
|
9
|
+
/**
|
|
10
|
+
Pointer to the `JavaScriptRuntime` wrapper.
|
|
11
|
+
|
|
12
|
+
\note It must be weak because only then the original runtime can be safely deallocated
|
|
13
|
+
when the JS engine wants to without unsetting it on each created object.
|
|
14
|
+
*/
|
|
15
|
+
__weak JavaScriptRuntime *_runtime;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
Shared pointer to the original JSI object that is being wrapped by `JavaScriptObject` class.
|
|
19
|
+
*/
|
|
20
|
+
std::shared_ptr<jsi::Object> _jsObjectPtr;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (nonnull instancetype)initWith:(std::shared_ptr<jsi::Object>)jsObjectPtr
|
|
24
|
+
runtime:(nonnull JavaScriptRuntime *)runtime
|
|
25
|
+
{
|
|
26
|
+
if (self = [super init]) {
|
|
27
|
+
_runtime = runtime;
|
|
28
|
+
_jsObjectPtr = jsObjectPtr;
|
|
29
|
+
}
|
|
30
|
+
return self;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (nonnull jsi::Object *)get
|
|
34
|
+
{
|
|
35
|
+
return _jsObjectPtr.get();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#pragma mark - Subscripting
|
|
39
|
+
|
|
40
|
+
- (nullable id)objectForKeyedSubscript:(nonnull NSString *)key
|
|
41
|
+
{
|
|
42
|
+
auto runtime = [_runtime get];
|
|
43
|
+
auto callInvoker = [_runtime callInvoker];
|
|
44
|
+
|
|
45
|
+
if (runtime && callInvoker) {
|
|
46
|
+
auto value = _jsObjectPtr->getProperty(*runtime, [key UTF8String]);
|
|
47
|
+
return expo::convertJSIValueToObjCObject(*runtime, value, callInvoker);
|
|
48
|
+
}
|
|
49
|
+
return nil;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
- (void)setObject:(nullable id)obj forKeyedSubscript:(nonnull NSString *)key
|
|
53
|
+
{
|
|
54
|
+
auto runtime = [_runtime get];
|
|
55
|
+
|
|
56
|
+
if (!runtime) {
|
|
57
|
+
NSLog(@"Cannot set '%@' property when the JavaScript runtime is no longer available.", key);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if ([obj isKindOfClass:[JavaScriptObject class]]) {
|
|
61
|
+
_jsObjectPtr->setProperty(*runtime, [key UTF8String], *[obj get]);
|
|
62
|
+
} else {
|
|
63
|
+
_jsObjectPtr->setProperty(*runtime, [key UTF8String], expo::convertObjCObjectToJSIValue(*runtime, obj));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#pragma mark - Functions
|
|
68
|
+
|
|
69
|
+
- (void)setAsyncFunction:(nonnull NSString *)name
|
|
70
|
+
argsCount:(NSInteger)argsCount
|
|
71
|
+
block:(nonnull JSAsyncFunctionBlock)block
|
|
72
|
+
{
|
|
73
|
+
if (!_runtime) {
|
|
74
|
+
NSLog(@"Cannot set '%@' async function when the JavaScript runtime is no longer available.", name);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
jsi::Function function = [_runtime createAsyncFunction:name argsCount:argsCount block:block];
|
|
78
|
+
_jsObjectPtr->setProperty(*[_runtime get], [name UTF8String], function);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
- (void)setSyncFunction:(nonnull NSString *)name
|
|
82
|
+
argsCount:(NSInteger)argsCount
|
|
83
|
+
block:(nonnull JSSyncFunctionBlock)block
|
|
84
|
+
{
|
|
85
|
+
if (!_runtime) {
|
|
86
|
+
NSLog(@"Cannot set '%@' sync function when the JavaScript runtime is no longer available.", name);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
jsi::Function function = [_runtime createSyncFunction:name argsCount:argsCount block:block];
|
|
90
|
+
_jsObjectPtr->setProperty(*[_runtime get], [name UTF8String], function);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@end
|