expo-modules-core 0.6.5 → 0.9.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 +57 -0
- package/README.md +1 -1
- package/android/ExpoModulesCorePlugin.gradle +15 -0
- package/android/build.gradle +31 -15
- package/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java +5 -5
- package/android/src/main/java/expo/modules/adapters/react/services/UIManagerModuleWrapper.java +13 -0
- package/android/src/main/java/expo/modules/core/ViewManager.java +9 -0
- package/android/src/main/java/expo/modules/core/interfaces/JavaScriptContextProvider.java +4 -0
- package/android/src/main/java/expo/modules/core/interfaces/ReactActivityHandler.java +37 -1
- package/android/src/main/java/expo/modules/core/interfaces/ReactNativeHostHandler.java +30 -0
- package/android/src/main/java/expo/modules/core/interfaces/services/UIManager.java +2 -0
- package/android/src/main/java/expo/modules/kotlin/AppContext.kt +23 -5
- package/android/src/main/java/expo/modules/kotlin/DynamicExtenstions.kt +5 -3
- package/android/src/main/java/expo/modules/kotlin/KPromiseWrapper.kt +3 -8
- package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +24 -9
- package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +12 -7
- package/android/src/main/java/expo/modules/kotlin/ModuleRegistry.kt +23 -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 +39 -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/events/EventEmitter.kt +13 -0
- package/android/src/main/java/expo/modules/kotlin/events/KModuleEventEmitterWrapper.kt +102 -0
- package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +93 -9
- package/android/src/main/java/expo/modules/kotlin/exception/ExceptionDecorator.kt +11 -0
- package/android/src/main/java/expo/modules/kotlin/{methods/AnyMethod.kt → functions/AnyFunction.kt} +18 -18
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +15 -0
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +170 -0
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromise.kt +15 -0
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncSuspendFunction.kt +36 -0
- package/android/src/main/java/expo/modules/kotlin/modules/DefinitionMarker.kt +4 -0
- package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +17 -2
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +416 -43
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionData.kt +2 -2
- package/android/src/main/java/expo/modules/kotlin/records/FieldValidator.kt +139 -0
- package/android/src/main/java/expo/modules/kotlin/records/RecordTypeConverter.kt +71 -15
- package/android/src/main/java/expo/modules/kotlin/records/Required.kt +5 -0
- package/android/src/main/java/expo/modules/kotlin/records/ValidationBinder.kt +110 -0
- package/android/src/main/java/expo/modules/kotlin/records/Validators.kt +61 -0
- package/android/src/main/java/expo/modules/kotlin/types/ArrayTypeConverter.kt +11 -5
- package/android/src/main/java/expo/modules/kotlin/types/JSTypeConverter.kt +35 -0
- package/android/src/main/java/expo/modules/kotlin/types/JSTypeConverterHelper.kt +148 -0
- 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/types/TypeConverterProvider.kt +9 -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 +71 -0
- package/android/src/main/java/expo/modules/kotlin/views/SimpleViewManagerWrapper.kt +22 -0
- package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinition.kt +18 -0
- package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinitionBuilder.kt +114 -0
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinition.kt +30 -2
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +81 -2
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerWrapperDelegate.kt +62 -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 -4
- package/build/NativeModulesProxy.native.d.ts.map +1 -0
- package/build/NativeModulesProxy.native.js +1 -14
- package/build/NativeModulesProxy.native.js.map +1 -1
- package/build/NativeModulesProxy.types.d.ts +1 -3
- package/build/NativeModulesProxy.types.d.ts.map +1 -0
- package/build/NativeModulesProxy.types.js.map +1 -1
- 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/NativeViewManagerAdapter.native.js +9 -33
- package/build/NativeViewManagerAdapter.native.js.map +1 -1
- 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/EXAppDelegatesLoader.m +4 -8
- package/ios/AppDelegates/ExpoAppDelegate.swift +22 -20
- package/ios/EXAppDefines.h +1 -0
- package/ios/EXAppDefines.m +6 -0
- package/ios/EXUtilities.h +2 -0
- package/ios/EXUtilities.m +12 -0
- package/ios/ExpoModulesCore.h +4 -0
- package/ios/ExpoModulesCore.podspec +4 -2
- package/ios/Interfaces/FileSystem/EXFileSystemInterface.h +1 -1
- package/ios/Interfaces/TaskManager/EXTaskServiceInterface.h +1 -0
- package/ios/JSI/{JSIConversions.h → EXJSIConversions.h} +5 -0
- package/ios/JSI/{JSIConversions.mm → EXJSIConversions.mm} +21 -1
- package/ios/JSI/{JSIInstaller.h → EXJSIInstaller.h} +10 -0
- package/ios/JSI/EXJSIInstaller.mm +17 -0
- package/ios/JSI/EXJSIUtils.h +19 -0
- package/ios/JSI/EXJSIUtils.mm +89 -0
- package/ios/JSI/EXJavaScriptObject.h +97 -0
- package/ios/JSI/EXJavaScriptObject.mm +121 -0
- package/ios/JSI/EXJavaScriptRuntime.h +73 -0
- package/ios/JSI/EXJavaScriptRuntime.mm +153 -0
- package/ios/JSI/EXJavaScriptValue.h +57 -0
- package/ios/JSI/EXJavaScriptValue.mm +166 -0
- package/ios/JSI/ExpoModulesHostObject.h +33 -0
- package/ios/JSI/ExpoModulesHostObject.mm +41 -0
- package/ios/JSI/JavaScriptRuntime.swift +32 -0
- package/ios/JSI/JavaScriptValue.swift +94 -0
- package/ios/ModuleRegistryAdapter/EXModuleRegistryAdapter.m +3 -23
- package/ios/NativeModulesProxy/EXNativeModulesProxy.h +2 -2
- package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +101 -75
- package/ios/RCTComponentData+Privates.h +12 -0
- package/ios/ReactDelegates/EXReactCompatibleHelpers.h +18 -0
- package/ios/ReactDelegates/EXReactCompatibleHelpers.m +19 -0
- package/ios/ReactDelegates/ExpoReactDelegate.swift +3 -3
- package/ios/ReactDelegates/ExpoReactDelegateHandler.swift +4 -4
- package/ios/ReactDelegates/ModulePriorities.swift +1 -1
- package/ios/Swift/AppContext.swift +57 -4
- package/ios/Swift/Arguments/AnyArgumentType.swift +1 -1
- 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 +16 -1
- package/ios/Swift/Functions/AsyncFunctionComponent.swift +182 -0
- package/ios/Swift/Functions/ConcreteFunction.swift +52 -59
- package/ios/Swift/Functions/SyncFunctionComponent.swift +181 -0
- package/ios/Swift/JavaScriptUtils.swift +99 -0
- package/ios/Swift/ModuleHolder.swift +69 -18
- 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 +54 -220
- package/ios/Swift/ModulesProvider.swift +3 -11
- package/ios/Swift/Objects/ObjectDefinition.swift +30 -0
- package/ios/Swift/Objects/ObjectDefinitionComponents.swift +257 -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 +53 -15
- package/ios/Swift/Views/AnyViewProp.swift +1 -1
- package/ios/Swift/Views/ComponentData.swift +96 -0
- package/ios/Swift/Views/ConcreteViewProp.swift +6 -8
- package/ios/Swift/Views/ExpoView.swift +8 -0
- 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 +49 -0
- package/ios/Swift/Views/ViewModuleWrapper.swift +5 -2
- package/ios/Swift.h +5 -0
- package/ios/Tests/ArgumentTypeSpec.swift +5 -7
- package/ios/Tests/ConstantsSpec.swift +6 -7
- package/ios/Tests/ConvertiblesSpec.swift +35 -36
- package/ios/Tests/ExceptionsSpec.swift +111 -0
- package/ios/Tests/ExpoModulesSpec.swift +75 -0
- package/ios/Tests/FunctionSpec.swift +21 -25
- package/ios/Tests/FunctionWithConvertiblesSpec.swift +4 -5
- package/ios/Tests/JavaScriptObjectSpec.swift +97 -0
- package/ios/Tests/JavaScriptRuntimeSpec.swift +94 -0
- package/ios/Tests/Mocks/ModuleMocks.swift +1 -1
- package/ios/Tests/Mocks/ModulesProviderMock.swift +0 -1
- package/ios/Tests/ModuleEventListenersSpec.swift +16 -17
- package/ios/Tests/ModuleRegistrySpec.swift +2 -3
- package/ios/Tests/RecordSpec.swift +9 -20
- package/package.json +3 -3
- package/src/NativeModulesProxy.native.ts +2 -22
- package/src/NativeModulesProxy.types.ts +0 -8
- package/src/NativeViewManagerAdapter.native.tsx +12 -28
- 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
- package/android/src/main/java/expo/modules/kotlin/events/KEventEmitterWrapper.kt +0 -26
- package/android/src/main/java/expo/modules/kotlin/methods/Method.kt +0 -14
- package/android/src/main/java/expo/modules/kotlin/methods/PromiseMethod.kt +0 -15
- package/ios/JSI/ExpoModulesProxySpec.h +0 -24
- package/ios/JSI/ExpoModulesProxySpec.mm +0 -135
- package/ios/JSI/JSIInstaller.mm +0 -22
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { NativeModules } from 'react-native';
|
|
2
2
|
|
|
3
|
-
import { ProxyNativeModule
|
|
4
|
-
|
|
5
|
-
// `ExpoModulesProxy` is not declared in TypeScript yet. It's installed via JSI.
|
|
6
|
-
declare namespace global {
|
|
7
|
-
const ExpoModulesProxy: TurboNativeModuleProxy;
|
|
8
|
-
}
|
|
3
|
+
import { ProxyNativeModule } from './NativeModulesProxy.types';
|
|
9
4
|
|
|
10
5
|
const NativeProxy = NativeModules.NativeUnimoduleProxy;
|
|
11
6
|
const modulesConstantsKey = 'modulesConstants';
|
|
@@ -13,16 +8,6 @@ const exportedMethodsKey = 'exportedMethods';
|
|
|
13
8
|
|
|
14
9
|
const NativeModulesProxy: { [moduleName: string]: ProxyNativeModule } = {};
|
|
15
10
|
|
|
16
|
-
// Keep it opt-in for now. It's too risky without proper and thorough testing.
|
|
17
|
-
let canUseExpoTurboModules = false;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Sets whether to use a TurboModule version of the proxy.
|
|
21
|
-
*/
|
|
22
|
-
export function useExpoTurboModules(state: boolean = true) {
|
|
23
|
-
canUseExpoTurboModules = state;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
11
|
if (NativeProxy) {
|
|
27
12
|
Object.keys(NativeProxy[exportedMethodsKey]).forEach((moduleName) => {
|
|
28
13
|
NativeModulesProxy[moduleName] = NativeProxy[modulesConstantsKey][moduleName] || {};
|
|
@@ -38,12 +23,7 @@ if (NativeProxy) {
|
|
|
38
23
|
)
|
|
39
24
|
);
|
|
40
25
|
}
|
|
41
|
-
|
|
42
|
-
if (canUseExpoTurboModules && global.ExpoModulesProxy) {
|
|
43
|
-
return global.ExpoModulesProxy.callMethodAsync(moduleName, methodInfo.name, args);
|
|
44
|
-
} else {
|
|
45
|
-
return NativeProxy.callMethod(moduleName, key, args);
|
|
46
|
-
}
|
|
26
|
+
return NativeProxy.callMethod(moduleName, key, args);
|
|
47
27
|
};
|
|
48
28
|
});
|
|
49
29
|
|
|
@@ -3,11 +3,3 @@ export type ProxyNativeModule = {
|
|
|
3
3
|
addListener: (eventName: string) => void;
|
|
4
4
|
removeListeners: (count: number) => void;
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
export type TurboNativeModuleProxy = {
|
|
8
|
-
callMethodAsync: <ReturnType>(
|
|
9
|
-
moduleName: string,
|
|
10
|
-
methodName: string,
|
|
11
|
-
args: any[]
|
|
12
|
-
) => Promise<ReturnType>;
|
|
13
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { NativeModules,
|
|
2
|
+
import { NativeModules, requireNativeComponent } from 'react-native';
|
|
3
3
|
|
|
4
4
|
// To make the transition from React Native's `requireNativeComponent` to Expo's
|
|
5
5
|
// `requireNativeViewManager` as easy as possible, `requireNativeViewManager` is a drop-in
|
|
@@ -10,11 +10,6 @@ import { NativeModules, UIManager, ViewPropTypes, requireNativeComponent } from
|
|
|
10
10
|
// passed to React Native's View (ex: style, testID) and custom view props, which are passed to the
|
|
11
11
|
// adapter view component in a prop called `proxiedProperties`.
|
|
12
12
|
|
|
13
|
-
// NOTE: React Native is moving away from runtime PropTypes and may remove ViewPropTypes, in which
|
|
14
|
-
// case we will need another way to separate standard React Native view props from other props,
|
|
15
|
-
// which we proxy through the adapter
|
|
16
|
-
const ViewPropTypesKeys = Object.keys(ViewPropTypes);
|
|
17
|
-
|
|
18
13
|
type NativeExpoComponentProps = {
|
|
19
14
|
proxiedProperties: object;
|
|
20
15
|
};
|
|
@@ -23,14 +18,14 @@ type NativeExpoComponentProps = {
|
|
|
23
18
|
* A drop-in replacement for `requireNativeComponent`.
|
|
24
19
|
*/
|
|
25
20
|
export function requireNativeViewManager<P = any>(viewName: string): React.ComponentType<P> {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
|
|
21
|
+
const { viewManagersMetadata } = NativeModules.NativeUnimoduleProxy;
|
|
22
|
+
const viewManagerConfig = viewManagersMetadata?.[viewName];
|
|
23
|
+
|
|
24
|
+
if (__DEV__ && !viewManagerConfig) {
|
|
25
|
+
const exportedViewManagerNames = Object.keys(viewManagersMetadata).join(', ');
|
|
26
|
+
console.warn(
|
|
27
|
+
`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}].`
|
|
28
|
+
);
|
|
34
29
|
}
|
|
35
30
|
|
|
36
31
|
// Set up the React Native native component, which is an adapter to the universal module's view
|
|
@@ -38,23 +33,12 @@ export function requireNativeViewManager<P = any>(viewName: string): React.Compo
|
|
|
38
33
|
const reactNativeViewName = `ViewManagerAdapter_${viewName}`;
|
|
39
34
|
const ReactNativeComponent =
|
|
40
35
|
requireNativeComponent<NativeExpoComponentProps>(reactNativeViewName);
|
|
41
|
-
const
|
|
42
|
-
? UIManager.getViewManagerConfig(reactNativeViewName)
|
|
43
|
-
: UIManager[reactNativeViewName]) || {
|
|
44
|
-
NativeProps: {},
|
|
45
|
-
directEventTypes: {},
|
|
46
|
-
};
|
|
47
|
-
const reactNativeComponentPropNames = [
|
|
48
|
-
'children',
|
|
49
|
-
...ViewPropTypesKeys,
|
|
50
|
-
...Object.keys(reactNativeUIConfiguration.NativeProps),
|
|
51
|
-
...Object.keys(reactNativeUIConfiguration.directEventTypes),
|
|
52
|
-
];
|
|
36
|
+
const proxiedPropsNames = viewManagerConfig?.propsNames ?? [];
|
|
53
37
|
|
|
54
38
|
// Define a component for universal-module authors to access their native view manager
|
|
55
39
|
function NativeComponentAdapter(props, ref) {
|
|
56
|
-
const nativeProps =
|
|
57
|
-
const proxiedProps =
|
|
40
|
+
const nativeProps = omit(props, proxiedPropsNames);
|
|
41
|
+
const proxiedProps = pick(props, proxiedPropsNames);
|
|
58
42
|
return <ReactNativeComponent {...nativeProps} proxiedProperties={proxiedProps} ref={ref} />;
|
|
59
43
|
}
|
|
60
44
|
NativeComponentAdapter.displayName = `Adapter<${viewName}>`;
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,8 @@ import SyntheticPlatformEmitter from './SyntheticPlatformEmitter';
|
|
|
9
9
|
import { CodedError } from './errors/CodedError';
|
|
10
10
|
import { UnavailabilityError } from './errors/UnavailabilityError';
|
|
11
11
|
|
|
12
|
+
import './sweet/setUpErrorManager.fx';
|
|
13
|
+
|
|
12
14
|
export { default as deprecate } from './deprecate';
|
|
13
15
|
|
|
14
16
|
export {
|
|
@@ -25,6 +27,8 @@ export {
|
|
|
25
27
|
UnavailabilityError,
|
|
26
28
|
};
|
|
27
29
|
|
|
30
|
+
export * from './requireNativeModule';
|
|
31
|
+
|
|
28
32
|
/**
|
|
29
33
|
* @deprecated renamed to `DeviceEventEmitter`
|
|
30
34
|
*/
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import NativeModulesProxy from './NativeModulesProxy';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
// eslint-disable-next-line no-var
|
|
5
|
+
var ExpoModules:
|
|
6
|
+
| undefined
|
|
7
|
+
| {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Imports the native module registered with given name. In the first place it tries to load
|
|
14
|
+
* the module installed through the JSI host object and then falls back to the bridge proxy module.
|
|
15
|
+
* Notice that the modules loaded from the proxy may not support some features like synchronous functions.
|
|
16
|
+
*
|
|
17
|
+
* @param moduleName Name of the requested native module.
|
|
18
|
+
* @returns Object representing the native module.
|
|
19
|
+
* @throws Error when there is no native module with given name.
|
|
20
|
+
*/
|
|
21
|
+
export function requireNativeModule<ModuleType = any>(moduleName: string): ModuleType {
|
|
22
|
+
const nativeModule: ModuleType =
|
|
23
|
+
global.ExpoModules?.[moduleName] ?? NativeModulesProxy[moduleName];
|
|
24
|
+
|
|
25
|
+
if (!nativeModule) {
|
|
26
|
+
throw new Error(`Cannot find native module '${moduleName}'`);
|
|
27
|
+
}
|
|
28
|
+
return nativeModule;
|
|
29
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EventEmitter } from '../EventEmitter';
|
|
2
|
+
import Platform from '../Platform';
|
|
3
|
+
import NativeErrorManager from './NativeErrorManager';
|
|
4
|
+
|
|
5
|
+
if (__DEV__ && Platform.OS === 'android' && NativeErrorManager) {
|
|
6
|
+
const onNewException = 'ExpoModulesCoreErrorManager.onNewException';
|
|
7
|
+
const eventEmitter = new EventEmitter(NativeErrorManager);
|
|
8
|
+
|
|
9
|
+
eventEmitter.addListener(onNewException, ({ message }: { message: string }) => {
|
|
10
|
+
console.error(message);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
package expo.modules.kotlin.events
|
|
2
|
-
|
|
3
|
-
import android.os.Bundle
|
|
4
|
-
import expo.modules.core.interfaces.services.EventEmitter
|
|
5
|
-
import expo.modules.kotlin.ModuleHolder
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* In Swift, we check if the event is supported. Otherwise, we can't send such event through the bridge.
|
|
9
|
-
* However, in Kotlin this is unnecessary, but to make our API consistent, we added similar check.
|
|
10
|
-
* But because of that, we had to create a wrapper for EventEmitter.
|
|
11
|
-
*/
|
|
12
|
-
class KEventEmitterWrapper(
|
|
13
|
-
private val moduleHolder: ModuleHolder,
|
|
14
|
-
private val legacyEventEmitter: EventEmitter
|
|
15
|
-
) : EventEmitter by legacyEventEmitter {
|
|
16
|
-
override fun emit(eventName: String, eventBody: Bundle?) {
|
|
17
|
-
require(
|
|
18
|
-
moduleHolder
|
|
19
|
-
.definition
|
|
20
|
-
.eventsDefinition
|
|
21
|
-
?.names
|
|
22
|
-
?.contains(eventName) == true
|
|
23
|
-
) { "Unsupported event: $eventName." }
|
|
24
|
-
legacyEventEmitter.emit(eventName, eventBody)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
package expo.modules.kotlin.methods
|
|
2
|
-
|
|
3
|
-
import expo.modules.kotlin.Promise
|
|
4
|
-
import expo.modules.kotlin.types.AnyType
|
|
5
|
-
|
|
6
|
-
class Method(
|
|
7
|
-
name: String,
|
|
8
|
-
argsType: Array<AnyType>,
|
|
9
|
-
private val body: (args: Array<out Any?>) -> Any?
|
|
10
|
-
) : AnyMethod(name, argsType) {
|
|
11
|
-
override fun callImplementation(args: Array<out Any?>, promise: Promise) {
|
|
12
|
-
promise.resolve(body(args))
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
package expo.modules.kotlin.methods
|
|
2
|
-
|
|
3
|
-
import expo.modules.kotlin.Promise
|
|
4
|
-
import expo.modules.kotlin.types.AnyType
|
|
5
|
-
|
|
6
|
-
class PromiseMethod(
|
|
7
|
-
name: String,
|
|
8
|
-
argsType: Array<AnyType>,
|
|
9
|
-
private val body: (args: Array<out Any?>, promise: Promise) -> Unit
|
|
10
|
-
) : AnyMethod(name, argsType) {
|
|
11
|
-
|
|
12
|
-
override fun callImplementation(args: Array<out Any?>, promise: Promise) {
|
|
13
|
-
body(args, promise)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
2
|
-
|
|
3
|
-
#ifdef __cplusplus
|
|
4
|
-
|
|
5
|
-
#import <jsi/jsi.h>
|
|
6
|
-
#import <ReactCommon/RCTTurboModule.h>
|
|
7
|
-
|
|
8
|
-
#import <ExpoModulesCore/EXNativeModulesProxy.h>
|
|
9
|
-
|
|
10
|
-
using namespace facebook;
|
|
11
|
-
using namespace react;
|
|
12
|
-
|
|
13
|
-
namespace expo {
|
|
14
|
-
|
|
15
|
-
class JSI_EXPORT ExpoModulesProxySpec : public TurboModule {
|
|
16
|
-
public:
|
|
17
|
-
ExpoModulesProxySpec(std::shared_ptr<CallInvoker> callInvoker, EXNativeModulesProxy *nativeModulesProxy);
|
|
18
|
-
|
|
19
|
-
EXNativeModulesProxy *nativeModulesProxy;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
} // namespace expo
|
|
23
|
-
|
|
24
|
-
#endif
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
2
|
-
|
|
3
|
-
#import <React/RCTUtils.h>
|
|
4
|
-
|
|
5
|
-
#import <ExpoModulesCore/JSIConversions.h>
|
|
6
|
-
#import <ExpoModulesCore/ExpoModulesProxySpec.h>
|
|
7
|
-
|
|
8
|
-
namespace expo {
|
|
9
|
-
|
|
10
|
-
using PromiseInvocationBlock = void (^)(RCTPromiseResolveBlock resolveWrapper, RCTPromiseRejectBlock rejectWrapper);
|
|
11
|
-
|
|
12
|
-
static void callPromiseSetupWithBlock(jsi::Runtime &runtime, std::shared_ptr<CallInvoker> jsInvoker, std::shared_ptr<Promise> promise, PromiseInvocationBlock setupBlock)
|
|
13
|
-
{
|
|
14
|
-
auto weakResolveWrapper = CallbackWrapper::createWeak(promise->resolve_.getFunction(runtime), runtime, jsInvoker);
|
|
15
|
-
auto weakRejectWrapper = CallbackWrapper::createWeak(promise->reject_.getFunction(runtime), runtime, jsInvoker);
|
|
16
|
-
|
|
17
|
-
__block BOOL resolveWasCalled = NO;
|
|
18
|
-
__block BOOL rejectWasCalled = NO;
|
|
19
|
-
|
|
20
|
-
RCTPromiseResolveBlock resolveBlock = ^(id result) {
|
|
21
|
-
if (rejectWasCalled) {
|
|
22
|
-
throw std::runtime_error("Tried to resolve a promise after it's already been rejected.");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (resolveWasCalled) {
|
|
26
|
-
throw std::runtime_error("Tried to resolve a promise more than once.");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
auto strongResolveWrapper = weakResolveWrapper.lock();
|
|
30
|
-
auto strongRejectWrapper = weakRejectWrapper.lock();
|
|
31
|
-
if (!strongResolveWrapper || !strongRejectWrapper) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
strongResolveWrapper->jsInvoker().invokeAsync([weakResolveWrapper, weakRejectWrapper, result]() {
|
|
36
|
-
auto strongResolveWrapper2 = weakResolveWrapper.lock();
|
|
37
|
-
auto strongRejectWrapper2 = weakRejectWrapper.lock();
|
|
38
|
-
if (!strongResolveWrapper2 || !strongRejectWrapper2) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
jsi::Runtime &rt = strongResolveWrapper2->runtime();
|
|
43
|
-
jsi::Value arg = convertObjCObjectToJSIValue(rt, result);
|
|
44
|
-
strongResolveWrapper2->callback().call(rt, arg);
|
|
45
|
-
|
|
46
|
-
strongResolveWrapper2->destroy();
|
|
47
|
-
strongRejectWrapper2->destroy();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
resolveWasCalled = YES;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
RCTPromiseRejectBlock rejectBlock = ^(NSString *code, NSString *message, NSError *error) {
|
|
54
|
-
if (resolveWasCalled) {
|
|
55
|
-
throw std::runtime_error("Tried to reject a promise after it's already been resolved.");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (rejectWasCalled) {
|
|
59
|
-
throw std::runtime_error("Tried to reject a promise more than once.");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
auto strongResolveWrapper = weakResolveWrapper.lock();
|
|
63
|
-
auto strongRejectWrapper = weakRejectWrapper.lock();
|
|
64
|
-
if (!strongResolveWrapper || !strongRejectWrapper) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
NSDictionary *jsError = RCTJSErrorFromCodeMessageAndNSError(code, message, error);
|
|
69
|
-
strongRejectWrapper->jsInvoker().invokeAsync([weakResolveWrapper, weakRejectWrapper, jsError]() {
|
|
70
|
-
auto strongResolveWrapper2 = weakResolveWrapper.lock();
|
|
71
|
-
auto strongRejectWrapper2 = weakRejectWrapper.lock();
|
|
72
|
-
if (!strongResolveWrapper2 || !strongRejectWrapper2) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
jsi::Runtime &rt = strongRejectWrapper2->runtime();
|
|
77
|
-
jsi::Value arg = convertNSDictionaryToJSIObject(rt, jsError);
|
|
78
|
-
strongRejectWrapper2->callback().call(rt, arg);
|
|
79
|
-
|
|
80
|
-
strongResolveWrapper2->destroy();
|
|
81
|
-
strongRejectWrapper2->destroy();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
rejectWasCalled = YES;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
setupBlock(resolveBlock, rejectBlock);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
static jsi::Value __hostFunction_ExpoModulesProxySpec_callMethodAsync(jsi::Runtime &runtime, TurboModule &turboModule, const jsi::Value *args, size_t count)
|
|
91
|
-
{
|
|
92
|
-
auto expoModulesProxy = static_cast<ExpoModulesProxySpec *>(&turboModule);
|
|
93
|
-
|
|
94
|
-
// The function that is invoked as a setup of the JS `Promise`.
|
|
95
|
-
auto promiseSetupFunc = [expoModulesProxy, args](jsi::Runtime &runtime, std::shared_ptr<Promise> promise) {
|
|
96
|
-
callPromiseSetupWithBlock(runtime, expoModulesProxy->jsInvoker_, promise, ^(RCTPromiseResolveBlock resolver, RCTPromiseRejectBlock rejecter) {
|
|
97
|
-
NSString *moduleName = convertJSIStringToNSString(runtime, args[0].getString(runtime));
|
|
98
|
-
NSString *methodName = convertJSIStringToNSString(runtime, args[1].getString(runtime));
|
|
99
|
-
NSArray *arguments = convertJSIArrayToNSArray(runtime, args[2].getObject(runtime).asArray(runtime), expoModulesProxy->jsInvoker_);
|
|
100
|
-
|
|
101
|
-
[expoModulesProxy->nativeModulesProxy callMethod:moduleName
|
|
102
|
-
methodNameOrKey:methodName
|
|
103
|
-
arguments:arguments
|
|
104
|
-
resolver:resolver
|
|
105
|
-
rejecter:rejecter];
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return createPromiseAsJSIValue(runtime, promiseSetupFunc);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
static jsi::Value __hostFunction_ExpoModulesProxySpec_callMethodSync(jsi::Runtime &runtime, TurboModule &turboModule, const jsi::Value *args, size_t count)
|
|
113
|
-
{
|
|
114
|
-
auto expoModulesProxy = static_cast<ExpoModulesProxySpec *>(&turboModule);
|
|
115
|
-
NSString *moduleName = convertJSIStringToNSString(runtime, args[0].getString(runtime));
|
|
116
|
-
NSString *methodName = convertJSIStringToNSString(runtime, args[1].getString(runtime));
|
|
117
|
-
NSArray *arguments = convertJSIArrayToNSArray(runtime, args[2].getObject(runtime).asArray(runtime), expoModulesProxy->jsInvoker_);
|
|
118
|
-
|
|
119
|
-
id result = [expoModulesProxy->nativeModulesProxy callMethodSync:moduleName
|
|
120
|
-
methodName:methodName
|
|
121
|
-
arguments:arguments];
|
|
122
|
-
|
|
123
|
-
return convertObjCObjectToJSIValue(runtime, result);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
ExpoModulesProxySpec::ExpoModulesProxySpec(std::shared_ptr<CallInvoker> callInvoker, EXNativeModulesProxy *nativeModulesProxy) :
|
|
127
|
-
TurboModule("ExpoModulesProxy", callInvoker),
|
|
128
|
-
nativeModulesProxy(nativeModulesProxy)
|
|
129
|
-
{
|
|
130
|
-
methodMap_["callMethodAsync"] = MethodMetadata {3, __hostFunction_ExpoModulesProxySpec_callMethodAsync};
|
|
131
|
-
|
|
132
|
-
methodMap_["callMethodSync"] = MethodMetadata {3, __hostFunction_ExpoModulesProxySpec_callMethodSync};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
} // namespace expo
|
package/ios/JSI/JSIInstaller.mm
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
2
|
-
|
|
3
|
-
#import <ExpoModulesCore/JSIInstaller.h>
|
|
4
|
-
#import <ExpoModulesCore/ExpoModulesProxySpec.h>
|
|
5
|
-
|
|
6
|
-
using namespace facebook;
|
|
7
|
-
using namespace react;
|
|
8
|
-
|
|
9
|
-
//using PromiseInvocationBlock = void (^)(RCTPromiseResolveBlock resolveWrapper, RCTPromiseRejectBlock rejectWrapper);
|
|
10
|
-
|
|
11
|
-
namespace expo {
|
|
12
|
-
|
|
13
|
-
void installRuntimeObjects(jsi::Runtime &runtime, std::shared_ptr<CallInvoker> callInvoker, EXNativeModulesProxy *nativeModulesProxy)
|
|
14
|
-
{
|
|
15
|
-
auto expoModulesProxyModule = std::make_shared<ExpoModulesProxySpec>(callInvoker, nativeModulesProxy);
|
|
16
|
-
|
|
17
|
-
runtime
|
|
18
|
-
.global()
|
|
19
|
-
.setProperty(runtime, "ExpoModulesProxy", jsi::Object::createFromHostObject(runtime, expoModulesProxyModule));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
} // namespace expo
|