expo-modules-core 0.6.4 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/README.md +1 -1
- package/android/ExpoModulesCorePlugin.gradle +15 -0
- package/android/build.gradle +46 -32
- 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 +19 -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 +61 -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 +219 -30
- 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 +64 -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 +42 -1
- 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 +64 -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/AsyncFunction.swift +17 -0
- package/ios/Swift/Functions/ConcreteFunction.swift +43 -17
- package/ios/Swift/JavaScriptUtils.swift +54 -0
- package/ios/Swift/ModuleHolder.swift +66 -16
- 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 +3 -11
- package/ios/Swift/Objects/ObjectDefinition.swift +30 -0
- package/ios/Swift/Objects/ObjectDefinitionComponents.swift +384 -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 +26 -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 +76 -0
- package/ios/Tests/FunctionSpec.swift +22 -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 +3 -4
- 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
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Copyright 2022-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
#import <ExpoModulesCore/EXJSIConversions.h>
|
|
4
|
+
#import <ExpoModulesCore/EXJavaScriptValue.h>
|
|
5
|
+
#import <ExpoModulesCore/EXJavaScriptRuntime.h>
|
|
6
|
+
|
|
7
|
+
@implementation EXJavaScriptValue {
|
|
8
|
+
__weak EXJavaScriptRuntime *_runtime;
|
|
9
|
+
std::shared_ptr<jsi::Value> _value;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
- (nonnull instancetype)initWithRuntime:(nonnull EXJavaScriptRuntime *)runtime
|
|
13
|
+
value:(std::shared_ptr<jsi::Value>)value
|
|
14
|
+
{
|
|
15
|
+
if (self = [super init]) {
|
|
16
|
+
_runtime = runtime;
|
|
17
|
+
_value = value;
|
|
18
|
+
}
|
|
19
|
+
return self;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
- (nonnull jsi::Value *)get
|
|
23
|
+
{
|
|
24
|
+
return _value.get();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#pragma mark - Type checking
|
|
28
|
+
|
|
29
|
+
- (BOOL)isUndefined
|
|
30
|
+
{
|
|
31
|
+
return _value->isUndefined();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
- (BOOL)isNull
|
|
35
|
+
{
|
|
36
|
+
return _value->isNull();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
- (BOOL)isBool
|
|
40
|
+
{
|
|
41
|
+
return _value->isBool();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
- (BOOL)isNumber
|
|
45
|
+
{
|
|
46
|
+
return _value->isNumber();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
- (BOOL)isString
|
|
50
|
+
{
|
|
51
|
+
return _value->isString();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
- (BOOL)isSymbol
|
|
55
|
+
{
|
|
56
|
+
return _value->isSymbol();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
- (BOOL)isObject
|
|
60
|
+
{
|
|
61
|
+
return _value->isObject();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
- (BOOL)isFunction
|
|
65
|
+
{
|
|
66
|
+
if (_value->isObject()) {
|
|
67
|
+
jsi::Runtime *runtime = [_runtime get];
|
|
68
|
+
return _value->getObject(*runtime).isFunction(*runtime);
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
+ (nonnull NSString *)kindOf:(nonnull EXJavaScriptValue *)value
|
|
74
|
+
{
|
|
75
|
+
if ([value isUndefined]) {
|
|
76
|
+
return @"undefined";
|
|
77
|
+
}
|
|
78
|
+
if ([value isNull]) {
|
|
79
|
+
return @"null";
|
|
80
|
+
}
|
|
81
|
+
if ([value isBool]) {
|
|
82
|
+
return @"boolean";
|
|
83
|
+
}
|
|
84
|
+
if ([value isNumber]) {
|
|
85
|
+
return @"number";
|
|
86
|
+
}
|
|
87
|
+
if ([value isString]) {
|
|
88
|
+
return @"string";
|
|
89
|
+
}
|
|
90
|
+
if ([value isFunction]) {
|
|
91
|
+
return @"function";
|
|
92
|
+
}
|
|
93
|
+
assert([value isObject] && "Expecting object.");
|
|
94
|
+
return @"object";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#pragma mark - Type casting
|
|
98
|
+
|
|
99
|
+
- (nullable id)getRaw
|
|
100
|
+
{
|
|
101
|
+
return expo::convertJSIValueToObjCObject(*[_runtime get], *_value, [_runtime callInvoker]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
- (BOOL)getBool
|
|
105
|
+
{
|
|
106
|
+
return _value->getBool();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
- (NSInteger)getInt
|
|
110
|
+
{
|
|
111
|
+
return _value->getNumber();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
- (double)getDouble
|
|
115
|
+
{
|
|
116
|
+
return _value->getNumber();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
- (nonnull NSString *)getString
|
|
120
|
+
{
|
|
121
|
+
jsi::Runtime *runtime = [_runtime get];
|
|
122
|
+
return expo::convertJSIStringToNSString(*runtime, _value->getString(*runtime));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
- (nonnull NSArray<EXJavaScriptValue *> *)getArray
|
|
126
|
+
{
|
|
127
|
+
jsi::Runtime *runtime = [_runtime get];
|
|
128
|
+
jsi::Array jsiArray = _value->getObject(*runtime).getArray(*runtime);
|
|
129
|
+
size_t arraySize = jsiArray.size(*runtime);
|
|
130
|
+
NSMutableArray *result = [NSMutableArray arrayWithCapacity:arraySize];
|
|
131
|
+
|
|
132
|
+
for (size_t i = 0; i < arraySize; i++) {
|
|
133
|
+
jsi::Value item = jsiArray.getValueAtIndex(*runtime, i);
|
|
134
|
+
|
|
135
|
+
if (item.isUndefined() || item.isNull()) {
|
|
136
|
+
[result addObject:(id)kCFNull];
|
|
137
|
+
} else {
|
|
138
|
+
std::shared_ptr<jsi::Value> valuePtr = std::make_shared<jsi::Value>(*runtime, item);
|
|
139
|
+
[result addObject:[[EXJavaScriptValue alloc] initWithRuntime:_runtime value:valuePtr]];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
- (nonnull NSDictionary<NSString *, id> *)getDictionary
|
|
146
|
+
{
|
|
147
|
+
jsi::Runtime *runtime = [_runtime get];
|
|
148
|
+
return expo::convertJSIObjectToNSDictionary(*runtime, _value->getObject(*runtime), [_runtime callInvoker]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
- (nonnull EXJavaScriptObject *)getObject
|
|
152
|
+
{
|
|
153
|
+
jsi::Runtime *runtime = [_runtime get];
|
|
154
|
+
std::shared_ptr<jsi::Object> objectPtr = std::make_shared<jsi::Object>(_value->asObject(*runtime));
|
|
155
|
+
return [[EXJavaScriptObject alloc] initWith:objectPtr runtime:_runtime];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#pragma mark - Helpers
|
|
159
|
+
|
|
160
|
+
- (nonnull NSString *)toString
|
|
161
|
+
{
|
|
162
|
+
jsi::Runtime *runtime = [_runtime get];
|
|
163
|
+
return expo::convertJSIStringToNSString(*runtime, _value->toString(*runtime));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@end
|
|
@@ -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,41 @@
|
|
|
1
|
+
// Copyright 2022-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
#import <ExpoModulesCore/ExpoModulesHostObject.h>
|
|
4
|
+
#import <ExpoModulesCore/EXJavaScriptObject.h>
|
|
5
|
+
#import <ExpoModulesCore/Swift.h>
|
|
6
|
+
|
|
7
|
+
namespace expo {
|
|
8
|
+
|
|
9
|
+
ExpoModulesHostObject::ExpoModulesHostObject(SwiftInteropBridge *swiftInterop) : swiftInterop(swiftInterop) {}
|
|
10
|
+
|
|
11
|
+
ExpoModulesHostObject::~ExpoModulesHostObject() {
|
|
12
|
+
[swiftInterop setRuntime:nil];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
jsi::Value ExpoModulesHostObject::get(jsi::Runtime &runtime, const jsi::PropNameID &name) {
|
|
16
|
+
NSString *moduleName = [NSString stringWithUTF8String:name.utf8(runtime).c_str()];
|
|
17
|
+
EXJavaScriptObject *nativeObject = [swiftInterop getNativeModuleObject:moduleName];
|
|
18
|
+
|
|
19
|
+
return nativeObject ? jsi::Value(runtime, *[nativeObject get]) : jsi::Value::undefined();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void ExpoModulesHostObject::set(jsi::Runtime &runtime, const jsi::PropNameID &name, const jsi::Value &value) {
|
|
23
|
+
std::string message("RuntimeError: Cannot override the host object for expo module '");
|
|
24
|
+
message += name.utf8(runtime);
|
|
25
|
+
message += "'.";
|
|
26
|
+
throw jsi::JSError(runtime, message);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
std::vector<jsi::PropNameID> ExpoModulesHostObject::getPropertyNames(jsi::Runtime &runtime) {
|
|
30
|
+
NSArray<NSString *> *moduleNames = [swiftInterop getModuleNames];
|
|
31
|
+
std::vector<jsi::PropNameID> propertyNames;
|
|
32
|
+
|
|
33
|
+
propertyNames.reserve([moduleNames count]);
|
|
34
|
+
|
|
35
|
+
for (NSString *moduleName in moduleNames) {
|
|
36
|
+
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, [moduleName UTF8String]));
|
|
37
|
+
}
|
|
38
|
+
return propertyNames;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
} // namespace expo
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright 2022-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
public extension JavaScriptRuntime {
|
|
4
|
+
/**
|
|
5
|
+
Evaluates JavaScript code represented as a string.
|
|
6
|
+
|
|
7
|
+
- Parameter source: A string representing a JavaScript expression, statement, or sequence of statements.
|
|
8
|
+
The expression can include variables and properties of existing objects.
|
|
9
|
+
- Returns: The completion value of evaluating the given code represented as `JavaScriptValue`.
|
|
10
|
+
If the completion value is empty, `undefined` is returned.
|
|
11
|
+
- Throws: `JavaScriptEvalException` when evaluated code has invalid syntax or throws an error.
|
|
12
|
+
- Note: It wraps the original `evaluateScript` to better handle and rethrow exceptions.
|
|
13
|
+
*/
|
|
14
|
+
func eval(_ source: String) throws -> JavaScriptValue {
|
|
15
|
+
do {
|
|
16
|
+
var result: JavaScriptValue?
|
|
17
|
+
try EXUtilities.catchException {
|
|
18
|
+
result = self.evaluateScript(source)
|
|
19
|
+
}
|
|
20
|
+
// There is no risk to force unwrapping as long as the `evaluateScript` returns nonnull value.
|
|
21
|
+
return result!
|
|
22
|
+
} catch {
|
|
23
|
+
throw JavaScriptEvalException(error as NSError)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
internal final class JavaScriptEvalException: GenericException<NSError> {
|
|
29
|
+
override var reason: String {
|
|
30
|
+
return param.userInfo["message"] as? String ?? "unknown reason"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Copyright 2022-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Enum with available kinds of values. It's almost the same as a result of "typeof"
|
|
5
|
+
in JavaScript, however `null` has its own kind (typeof null == "object").
|
|
6
|
+
*/
|
|
7
|
+
public enum JavaScriptValueKind: String {
|
|
8
|
+
case undefined
|
|
9
|
+
case null
|
|
10
|
+
case bool
|
|
11
|
+
case number
|
|
12
|
+
case symbol
|
|
13
|
+
case string
|
|
14
|
+
case function
|
|
15
|
+
case object
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public extension JavaScriptValue {
|
|
19
|
+
var kind: JavaScriptValueKind {
|
|
20
|
+
switch true {
|
|
21
|
+
case isUndefined():
|
|
22
|
+
return .undefined
|
|
23
|
+
case isNull():
|
|
24
|
+
return .null
|
|
25
|
+
case isBool():
|
|
26
|
+
return .bool
|
|
27
|
+
case isNumber():
|
|
28
|
+
return .number
|
|
29
|
+
case isSymbol():
|
|
30
|
+
return .symbol
|
|
31
|
+
case isString():
|
|
32
|
+
return .string
|
|
33
|
+
case isFunction():
|
|
34
|
+
return .function
|
|
35
|
+
default:
|
|
36
|
+
return .object
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func asBool() throws -> Bool {
|
|
41
|
+
if isBool() {
|
|
42
|
+
return getBool()
|
|
43
|
+
}
|
|
44
|
+
throw JavaScriptValueConversionException((kind: kind, target: "Bool"))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
func asInt() throws -> Int {
|
|
48
|
+
if isNumber() {
|
|
49
|
+
return getInt()
|
|
50
|
+
}
|
|
51
|
+
throw JavaScriptValueConversionException((kind: kind, target: "Int"))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
func asDouble() throws -> Double {
|
|
55
|
+
if isNumber() {
|
|
56
|
+
return getDouble()
|
|
57
|
+
}
|
|
58
|
+
throw JavaScriptValueConversionException((kind: kind, target: "Double"))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
func asString() throws -> String {
|
|
62
|
+
if isString() {
|
|
63
|
+
return getString()
|
|
64
|
+
}
|
|
65
|
+
throw JavaScriptValueConversionException((kind: kind, target: "String"))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
func asArray() throws -> [JavaScriptValue?] {
|
|
69
|
+
if isObject() {
|
|
70
|
+
return getArray()
|
|
71
|
+
}
|
|
72
|
+
throw JavaScriptValueConversionException((kind: kind, target: "Array"))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
func asDict() throws -> [String: Any] {
|
|
76
|
+
if isObject() {
|
|
77
|
+
return getDictionary()
|
|
78
|
+
}
|
|
79
|
+
throw JavaScriptValueConversionException((kind: kind, target: "Dict"))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func asObject() throws -> JavaScriptObject {
|
|
83
|
+
if isObject() {
|
|
84
|
+
return getObject()
|
|
85
|
+
}
|
|
86
|
+
throw JavaScriptValueConversionException((kind: kind, target: "Object"))
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
internal final class JavaScriptValueConversionException: GenericException<(kind: JavaScriptValueKind, target: String)> {
|
|
91
|
+
override var reason: String {
|
|
92
|
+
"Cannot represent a value of kind '\(param.kind)' as \(param.target)"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
@property (nonatomic, strong) EXModuleRegistryProvider *moduleRegistryProvider;
|
|
15
15
|
@property (nonatomic, strong) EXViewManagerAdapterClassesRegistry *viewManagersClassesRegistry;
|
|
16
|
-
@property (nonatomic, strong, nullable)
|
|
16
|
+
@property (nonatomic, strong, nullable) ModulesProvider *swiftModulesProvider;
|
|
17
17
|
|
|
18
18
|
@end
|
|
19
19
|
|
|
@@ -28,16 +28,6 @@
|
|
|
28
28
|
return self;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
- (instancetype)initWithModuleRegistryProvider:(EXModuleRegistryProvider *)moduleRegistryProvider swiftModulesProviderClass:(nullable Class)swiftModulesProviderClass
|
|
32
|
-
{
|
|
33
|
-
if (self = [self initWithModuleRegistryProvider:moduleRegistryProvider]) {
|
|
34
|
-
if ([swiftModulesProviderClass conformsToProtocol:@protocol(ModulesProviderObjCProtocol)]) {
|
|
35
|
-
_swiftModulesProvider = [swiftModulesProviderClass new];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return self;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
31
|
- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
|
|
42
32
|
{
|
|
43
33
|
return [self extraModulesForModuleRegistry:[_moduleRegistryProvider moduleRegistry]];
|
|
@@ -55,18 +45,9 @@
|
|
|
55
45
|
EXReactNativeEventEmitter *eventEmitter = [EXReactNativeEventEmitter new];
|
|
56
46
|
[moduleRegistry registerInternalModule:eventEmitter];
|
|
57
47
|
|
|
58
|
-
NSMutableSet *exportedSwiftViewModuleNames = [NSMutableSet new];
|
|
59
|
-
|
|
60
|
-
for (ViewModuleWrapper *swiftViewModule in [nativeModulesProxy.swiftInteropBridge getViewManagers]) {
|
|
61
|
-
Class wrappedViewModuleClass = [ViewModuleWrapper createViewModuleWrapperClassWithModule:swiftViewModule];
|
|
62
|
-
[extraModules addObject:[[wrappedViewModuleClass alloc] init]];
|
|
63
|
-
[exportedSwiftViewModuleNames addObject:swiftViewModule.name];
|
|
64
|
-
}
|
|
65
48
|
for (EXViewManager *viewManager in [moduleRegistry getAllViewManagers]) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
[extraModules addObject:[[viewManagerAdapterClass alloc] init]];
|
|
69
|
-
}
|
|
49
|
+
Class viewManagerAdapterClass = [EXViewManagerAdapterClassesRegistry createViewManagerAdapterClassForViewManager:viewManager];
|
|
50
|
+
[extraModules addObject:[[viewManagerAdapterClass alloc] init]];
|
|
70
51
|
}
|
|
71
52
|
|
|
72
53
|
// Silence React Native warning `Base module "%s" does not exist`
|
|
@@ -75,7 +56,6 @@
|
|
|
75
56
|
// subclass EXViewManagerAdapter, so RN expects to find EXViewManagerAdapter
|
|
76
57
|
// exported.
|
|
77
58
|
[extraModules addObject:[[EXViewManagerAdapter alloc] init]];
|
|
78
|
-
[extraModules addObject:[[ViewModuleWrapper alloc] initWithDummy:nil]];
|
|
79
59
|
|
|
80
60
|
// It is possible that among internal modules there are some RCTBridgeModules --
|
|
81
61
|
// let's add them to extraModules here.
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// Swift compatibility headers (e.g. `ExpoModulesCore-Swift.h`) are not available in headers,
|
|
13
13
|
// so we use class forward declaration here. Swift header must be imported in the `.m` file.
|
|
14
14
|
@class SwiftInteropBridge;
|
|
15
|
-
@
|
|
15
|
+
@class ModulesProvider;
|
|
16
16
|
|
|
17
17
|
NS_SWIFT_NAME(NativeModulesProxy)
|
|
18
18
|
@interface EXNativeModulesProxy : NSObject <RCTBridgeModule>
|
|
@@ -25,6 +25,6 @@ NS_SWIFT_NAME(NativeModulesProxy)
|
|
|
25
25
|
- (void)callMethod:(NSString *)moduleName methodNameOrKey:(id)methodNameOrKey arguments:(NSArray *)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
|
|
26
26
|
- (id)callMethodSync:(NSString *)moduleName methodName:(NSString *)methodName arguments:(NSArray *)arguments;
|
|
27
27
|
|
|
28
|
-
+ (
|
|
28
|
+
+ (ModulesProvider *)getExpoModulesProvider;
|
|
29
29
|
|
|
30
30
|
@end
|