expo-modules-core 0.9.2 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -3
- package/README.md +3 -3
- package/android/CMakeLists.txt +163 -0
- package/android/build.gradle +343 -5
- package/android/src/main/cpp/CachedReferencesRegistry.cpp +65 -0
- package/android/src/main/cpp/CachedReferencesRegistry.h +80 -0
- package/android/src/main/cpp/Exceptions.cpp +22 -0
- package/android/src/main/cpp/Exceptions.h +38 -0
- package/android/src/main/cpp/ExpoModulesHostObject.cpp +47 -0
- package/android/src/main/cpp/ExpoModulesHostObject.h +32 -0
- package/android/src/main/cpp/JNIFunctionBody.cpp +44 -0
- package/android/src/main/cpp/JNIFunctionBody.h +50 -0
- package/android/src/main/cpp/JNIInjector.cpp +23 -0
- package/android/src/main/cpp/JSIInteropModuleRegistry.cpp +122 -0
- package/android/src/main/cpp/JSIInteropModuleRegistry.h +96 -0
- package/android/src/main/cpp/JSIObjectWrapper.h +33 -0
- package/android/src/main/cpp/JSITypeConverter.h +84 -0
- package/android/src/main/cpp/JavaScriptModuleObject.cpp +219 -0
- package/android/src/main/cpp/JavaScriptModuleObject.h +144 -0
- package/android/src/main/cpp/JavaScriptObject.cpp +125 -0
- package/android/src/main/cpp/JavaScriptObject.h +131 -0
- package/android/src/main/cpp/JavaScriptRuntime.cpp +127 -0
- package/android/src/main/cpp/JavaScriptRuntime.h +87 -0
- package/android/src/main/cpp/JavaScriptValue.cpp +172 -0
- package/android/src/main/cpp/JavaScriptValue.h +78 -0
- package/android/src/main/cpp/MethodMetadata.cpp +340 -0
- package/android/src/main/cpp/MethodMetadata.h +131 -0
- package/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java +2 -0
- package/android/src/main/java/expo/modules/core/errors/ContextDestroyedException.kt +7 -0
- package/android/src/main/java/expo/modules/interfaces/permissions/Permissions.java +30 -0
- package/android/src/main/java/expo/modules/kotlin/AppContext.kt +98 -3
- package/android/src/main/java/expo/modules/kotlin/ConcatIterator.kt +18 -0
- package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +15 -12
- package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +45 -3
- package/android/src/main/java/expo/modules/kotlin/activityaware/AppCompatActivityAware.kt +49 -0
- package/android/src/main/java/expo/modules/kotlin/activityaware/AppCompatActivityAwareHelper.kt +43 -0
- package/android/src/main/java/expo/modules/kotlin/activityaware/OnActivityAvailableListener.kt +18 -0
- package/android/src/main/java/expo/modules/kotlin/activityresult/ActivityResultsManager.kt +99 -0
- package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultCaller.kt +25 -0
- package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultContract.kt +27 -0
- package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultFallbackCallback.kt +17 -0
- package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultLauncher.kt +30 -0
- package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultRegistry.kt +358 -0
- package/android/src/main/java/expo/modules/kotlin/activityresult/DataPersistor.kt +135 -0
- package/android/src/main/java/expo/modules/kotlin/defaultmodules/ErrorManagerModule.kt +2 -2
- package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +13 -0
- package/android/src/main/java/expo/modules/kotlin/exception/ExceptionDecorator.kt +2 -0
- package/android/src/main/java/expo/modules/kotlin/functions/AnyFunction.kt +53 -15
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +35 -7
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +13 -121
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionComponent.kt +21 -0
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromiseComponent.kt +21 -0
- package/android/src/main/java/expo/modules/kotlin/functions/SuspendFunctionComponent.kt +63 -0
- package/android/src/main/java/expo/modules/kotlin/functions/SyncFunctionComponent.kt +36 -0
- package/android/src/main/java/expo/modules/kotlin/jni/CppType.kt +19 -0
- package/android/src/main/java/expo/modules/kotlin/jni/JNIFunctionBody.kt +39 -0
- package/android/src/main/java/expo/modules/kotlin/jni/JSIInteropModuleRegistry.kt +89 -0
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptModuleObject.kt +46 -0
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptObject.kt +113 -0
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptValue.kt +35 -0
- package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +16 -6
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +5 -500
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionData.kt +30 -5
- package/android/src/main/java/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +271 -0
- package/android/src/main/java/expo/modules/kotlin/objects/ObjectDefinitionData.kt +21 -0
- package/android/src/main/java/expo/modules/kotlin/objects/PropertyComponent.kt +54 -0
- package/android/src/main/java/expo/modules/kotlin/objects/PropertyComponentBuilder.kt +32 -0
- package/android/src/main/java/expo/modules/kotlin/providers/AppContextProvider.kt +14 -0
- package/android/src/main/java/expo/modules/kotlin/providers/CurrentActivityProvider.kt +22 -0
- package/android/src/main/java/expo/modules/kotlin/records/RecordTypeConverter.kt +19 -2
- package/android/src/main/java/expo/modules/kotlin/types/AnyType.kt +3 -2
- package/android/src/main/java/expo/modules/kotlin/types/AnyTypeConverter.kt +36 -0
- package/android/src/main/java/expo/modules/kotlin/types/ArrayTypeConverter.kt +7 -2
- package/android/src/main/java/expo/modules/kotlin/types/BasicTypeConverters.kt +68 -20
- package/android/src/main/java/expo/modules/kotlin/types/EnumTypeConverter.kt +50 -22
- package/android/src/main/java/expo/modules/kotlin/types/ListTypeConverter.kt +18 -2
- package/android/src/main/java/expo/modules/kotlin/types/MapTypeConverter.kt +18 -2
- package/android/src/main/java/expo/modules/kotlin/types/PairTypeConverter.kt +17 -2
- package/android/src/main/java/expo/modules/kotlin/types/TypeConverter.kt +43 -3
- package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +12 -0
- package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinitionBuilder.kt +0 -41
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +0 -33
- package/build/NativeModulesProxy.native.d.ts.map +1 -1
- package/build/NativeModulesProxy.native.js +9 -3
- package/build/NativeModulesProxy.native.js.map +1 -1
- package/build/PermissionsInterface.d.ts +29 -0
- package/build/PermissionsInterface.d.ts.map +1 -1
- package/build/PermissionsInterface.js +9 -0
- package/build/PermissionsInterface.js.map +1 -1
- package/ios/AppDelegates/EXAppDelegatesLoader.m +1 -2
- package/ios/ExpoModulesCore.podspec +3 -2
- package/ios/JSI/EXJSIConversions.mm +6 -0
- package/ios/JSI/EXJSIInstaller.h +15 -21
- package/ios/JSI/EXJSIInstaller.mm +39 -3
- package/ios/JSI/EXJSIUtils.h +48 -3
- package/ios/JSI/EXJSIUtils.mm +88 -4
- package/ios/JSI/EXJavaScriptObject.h +11 -18
- package/ios/JSI/EXJavaScriptObject.mm +37 -18
- package/ios/JSI/EXJavaScriptRuntime.h +43 -9
- package/ios/JSI/EXJavaScriptRuntime.mm +70 -27
- package/ios/JSI/EXJavaScriptTypedArray.h +30 -0
- package/ios/JSI/EXJavaScriptTypedArray.mm +29 -0
- package/ios/JSI/EXJavaScriptValue.h +3 -2
- package/ios/JSI/EXJavaScriptValue.mm +17 -20
- package/ios/JSI/EXJavaScriptWeakObject.h +23 -0
- package/ios/JSI/EXJavaScriptWeakObject.mm +53 -0
- package/ios/JSI/EXObjectDeallocator.h +27 -0
- package/ios/JSI/ExpoModulesHostObject.h +3 -3
- package/ios/JSI/ExpoModulesHostObject.mm +4 -4
- package/ios/JSI/JavaScriptRuntime.swift +38 -1
- package/ios/JSI/JavaScriptValue.swift +7 -0
- package/ios/JSI/TypedArray.cpp +67 -0
- package/ios/JSI/TypedArray.h +46 -0
- package/ios/ModuleRegistryAdapter/EXModuleRegistryAdapter.m +0 -11
- package/ios/NativeModulesProxy/EXNativeModulesProxy.h +17 -10
- package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +86 -77
- package/ios/NativeModulesProxy/NativeModulesProxyModule.swift +17 -0
- package/ios/Services/EXReactNativeEventEmitter.h +2 -2
- package/ios/Services/EXReactNativeEventEmitter.m +11 -6
- package/ios/Swift/AppContext.swift +206 -28
- package/ios/Swift/Arguments/AnyArgument.swift +18 -0
- package/ios/Swift/Arguments/{Types/EnumArgumentType.swift → EnumArgument.swift} +2 -17
- package/ios/Swift/Classes/ClassComponent.swift +95 -0
- package/ios/Swift/Classes/ClassComponentElement.swift +33 -0
- package/ios/Swift/Classes/ClassComponentElementsBuilder.swift +34 -0
- package/ios/Swift/Classes/ClassComponentFactories.swift +96 -0
- package/ios/Swift/DynamicTypes/AnyDynamicType.swift +44 -0
- package/ios/Swift/DynamicTypes/DynamicArrayType.swift +56 -0
- package/ios/Swift/DynamicTypes/DynamicConvertibleType.swift +27 -0
- package/ios/Swift/DynamicTypes/DynamicEnumType.swift +27 -0
- package/ios/Swift/DynamicTypes/DynamicOptionalType.swift +63 -0
- package/ios/Swift/DynamicTypes/DynamicRawType.swift +33 -0
- package/ios/Swift/DynamicTypes/DynamicSharedObjectType.swift +37 -0
- package/ios/Swift/DynamicTypes/DynamicType.swift +39 -0
- package/ios/Swift/DynamicTypes/DynamicTypedArrayType.swift +46 -0
- package/ios/Swift/Exceptions/ChainableException.swift +3 -3
- package/ios/Swift/Exceptions/CodedError.swift +1 -1
- package/ios/Swift/Exceptions/Exception.swift +8 -6
- package/ios/Swift/Exceptions/UnexpectedException.swift +2 -1
- package/ios/Swift/ExpoBridgeModule.m +5 -0
- package/ios/Swift/ExpoBridgeModule.swift +79 -0
- package/ios/Swift/Functions/AnyFunction.swift +33 -31
- package/ios/Swift/Functions/AsyncFunctionComponent.swift +196 -59
- package/ios/Swift/Functions/SyncFunctionComponent.swift +142 -58
- package/ios/Swift/JavaScriptUtils.swift +32 -57
- package/ios/Swift/Logging/LogHandlers.swift +39 -0
- package/ios/Swift/Logging/LogType.swift +62 -0
- package/ios/Swift/Logging/Logger.swift +201 -0
- package/ios/Swift/ModuleHolder.swift +19 -54
- package/ios/Swift/ModuleRegistry.swift +7 -1
- package/ios/Swift/Modules/AnyModule.swift +3 -3
- package/ios/Swift/ModulesProvider.swift +2 -0
- package/ios/Swift/Objects/JavaScriptObjectBuilder.swift +37 -0
- package/ios/Swift/Objects/ObjectDefinition.swift +74 -1
- package/ios/Swift/Objects/ObjectDefinitionComponents.swift +77 -68
- package/ios/Swift/Objects/PropertyComponent.swift +147 -0
- package/ios/Swift/Promise.swift +17 -4
- package/ios/Swift/Records/Field.swift +2 -2
- package/ios/Swift/SharedObjects/SharedObject.swift +20 -0
- package/ios/Swift/SharedObjects/SharedObjectRegistry.swift +129 -0
- package/ios/Swift/TypedArrays/AnyTypedArray.swift +11 -0
- package/ios/Swift/TypedArrays/ConcreteTypedArrays.swift +56 -0
- package/ios/Swift/TypedArrays/GenericTypedArray.swift +49 -0
- package/ios/Swift/TypedArrays/TypedArray.swift +80 -0
- package/ios/Swift/Utilities.swift +28 -0
- package/ios/Swift/Views/ConcreteViewProp.swift +3 -3
- package/ios/Swift/Views/ViewManagerDefinitionComponents.swift +2 -2
- package/ios/Tests/ClassComponentSpec.swift +210 -0
- package/ios/Tests/DynamicTypeSpec.swift +336 -0
- package/ios/Tests/EnumArgumentSpec.swift +48 -0
- package/ios/Tests/ExpoModulesSpec.swift +17 -3
- package/ios/Tests/FunctionSpec.swift +167 -118
- package/ios/Tests/Mocks/ModuleMocks.swift +1 -1
- package/ios/Tests/PropertyComponentSpec.swift +95 -0
- package/ios/Tests/SharedObjectRegistrySpec.swift +109 -0
- package/ios/Tests/TypedArraysSpec.swift +136 -0
- package/package.json +2 -2
- package/src/NativeModulesProxy.native.ts +13 -3
- package/src/PermissionsInterface.ts +29 -0
- package/src/ts-declarations/ExpoModules.d.ts +7 -0
- package/tsconfig.json +1 -1
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromise.kt +0 -15
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncSuspendFunction.kt +0 -36
- package/ios/Swift/Arguments/AnyArgumentType.swift +0 -13
- package/ios/Swift/Arguments/ArgumentType.swift +0 -28
- package/ios/Swift/Arguments/Types/ArrayArgumentType.swift +0 -42
- package/ios/Swift/Arguments/Types/ConvertibleArgumentType.swift +0 -16
- package/ios/Swift/Arguments/Types/OptionalArgumentType.swift +0 -49
- package/ios/Swift/Arguments/Types/PromiseArgumentType.swift +0 -15
- package/ios/Swift/Arguments/Types/RawArgumentType.swift +0 -25
- package/ios/Swift/Functions/ConcreteFunction.swift +0 -103
- package/ios/Swift/SwiftInteropBridge.swift +0 -155
- package/ios/Tests/ArgumentTypeSpec.swift +0 -143
|
@@ -6,159 +6,51 @@ package expo.modules.kotlin.functions
|
|
|
6
6
|
import expo.modules.kotlin.types.toAnyType
|
|
7
7
|
import kotlin.reflect.typeOf
|
|
8
8
|
|
|
9
|
-
class AsyncFunctionBuilder(val name: String) {
|
|
9
|
+
class AsyncFunctionBuilder(@PublishedApi internal val name: String) {
|
|
10
10
|
@PublishedApi
|
|
11
|
-
internal var
|
|
12
|
-
|
|
13
|
-
@Deprecated(
|
|
14
|
-
message = "The 'suspendBody' component was renamed to 'SuspendBody'.",
|
|
15
|
-
replaceWith = ReplaceWith("SuspendBody(block)")
|
|
16
|
-
)
|
|
17
|
-
inline fun <reified R> suspendBody(crossinline block: suspend () -> R) = SuspendBody(block)
|
|
11
|
+
internal var functionBuilder: SuspendFunctionComponentBuilder? = null
|
|
18
12
|
|
|
19
13
|
inline fun <reified R> SuspendBody(crossinline block: suspend () -> R) {
|
|
20
|
-
|
|
14
|
+
functionBuilder = SuspendFunctionComponentBuilder(name, arrayOf()) { block() }
|
|
21
15
|
}
|
|
22
16
|
|
|
23
|
-
@Deprecated(
|
|
24
|
-
message = "The 'suspendBody' component was renamed to 'SuspendBody'.",
|
|
25
|
-
replaceWith = ReplaceWith("SuspendBody(block)")
|
|
26
|
-
)
|
|
27
|
-
inline fun <reified R, reified P0> suspendBody(crossinline block: suspend (p0: P0) -> R) = SuspendBody(block)
|
|
28
|
-
|
|
29
17
|
inline fun <reified R, reified P0> SuspendBody(crossinline block: suspend (p0: P0) -> R) {
|
|
30
|
-
|
|
18
|
+
functionBuilder = SuspendFunctionComponentBuilder(name, arrayOf(typeOf<P0>().toAnyType())) { block(it[0] as P0) }
|
|
31
19
|
}
|
|
32
20
|
|
|
33
|
-
@Deprecated(
|
|
34
|
-
message = "The 'suspendBody' component was renamed to 'SuspendBody'.",
|
|
35
|
-
replaceWith = ReplaceWith("SuspendBody(block)")
|
|
36
|
-
)
|
|
37
|
-
inline fun <reified R, reified P0, reified P1> suspendBody(crossinline block: suspend (p0: P0, p1: P1) -> R) = SuspendBody(block)
|
|
38
|
-
|
|
39
21
|
inline fun <reified R, reified P0, reified P1> SuspendBody(crossinline block: suspend (p0: P0, p1: P1) -> R) {
|
|
40
|
-
|
|
22
|
+
functionBuilder = SuspendFunctionComponentBuilder(name, arrayOf(typeOf<P0>().toAnyType())) { block(it[0] as P0, it[0] as P1) }
|
|
41
23
|
}
|
|
42
24
|
|
|
43
|
-
@Deprecated(
|
|
44
|
-
message = "The 'suspendBody' component was renamed to 'SuspendBody'.",
|
|
45
|
-
replaceWith = ReplaceWith("SuspendBody(block)")
|
|
46
|
-
)
|
|
47
|
-
inline fun <reified R, reified P0, reified P1, reified P2> suspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2) -> R) = SuspendBody(block)
|
|
48
|
-
|
|
49
25
|
inline fun <reified R, reified P0, reified P1, reified P2> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2) -> R) {
|
|
50
|
-
|
|
26
|
+
functionBuilder = SuspendFunctionComponentBuilder(name, arrayOf(typeOf<P0>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2) }
|
|
51
27
|
}
|
|
52
28
|
|
|
53
|
-
@Deprecated(
|
|
54
|
-
message = "The 'suspendBody' component was renamed to 'SuspendBody'.",
|
|
55
|
-
replaceWith = ReplaceWith("SuspendBody(block)")
|
|
56
|
-
)
|
|
57
|
-
inline fun <reified R, reified P0, reified P1, reified P2, reified P3> suspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3) -> R) = SuspendBody(block)
|
|
58
|
-
|
|
59
29
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3) -> R) {
|
|
60
|
-
|
|
30
|
+
functionBuilder = SuspendFunctionComponentBuilder(name, arrayOf(typeOf<P0>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }
|
|
61
31
|
}
|
|
62
32
|
|
|
63
|
-
@Deprecated(
|
|
64
|
-
message = "The 'suspendBody' component was renamed to 'SuspendBody'.",
|
|
65
|
-
replaceWith = ReplaceWith("SuspendBody(block)")
|
|
66
|
-
)
|
|
67
|
-
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> suspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R) = SuspendBody(block)
|
|
68
|
-
|
|
69
33
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R) {
|
|
70
|
-
|
|
34
|
+
functionBuilder = SuspendFunctionComponentBuilder(name, arrayOf(typeOf<P0>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }
|
|
71
35
|
}
|
|
72
36
|
|
|
73
|
-
@Deprecated(
|
|
74
|
-
message = "The 'suspendBody' component was renamed to 'SuspendBody'.",
|
|
75
|
-
replaceWith = ReplaceWith("SuspendBody(block)")
|
|
76
|
-
)
|
|
77
|
-
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> suspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R) = SuspendBody(block)
|
|
78
|
-
|
|
79
37
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R) {
|
|
80
|
-
|
|
38
|
+
functionBuilder = SuspendFunctionComponentBuilder(name, arrayOf(typeOf<P0>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }
|
|
81
39
|
}
|
|
82
40
|
|
|
83
|
-
@Deprecated(
|
|
84
|
-
message = "The 'suspendBody' component was renamed to 'SuspendBody'.",
|
|
85
|
-
replaceWith = ReplaceWith("SuspendBody(block)")
|
|
86
|
-
)
|
|
87
|
-
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> suspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R) = SuspendBody(block)
|
|
88
|
-
|
|
89
41
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R) {
|
|
90
|
-
|
|
42
|
+
functionBuilder = SuspendFunctionComponentBuilder(name, arrayOf(typeOf<P0>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }
|
|
91
43
|
}
|
|
92
44
|
|
|
93
|
-
@Deprecated(
|
|
94
|
-
message = "The 'suspendBody' component was renamed to 'SuspendBody'.",
|
|
95
|
-
replaceWith = ReplaceWith("SuspendBody(block)")
|
|
96
|
-
)
|
|
97
|
-
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> suspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R) = SuspendBody(block)
|
|
98
|
-
|
|
99
45
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> SuspendBody(crossinline block: suspend (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R) {
|
|
100
|
-
|
|
46
|
+
functionBuilder = SuspendFunctionComponentBuilder(name, arrayOf(typeOf<P0>().toAnyType())) { block(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }
|
|
101
47
|
}
|
|
102
48
|
|
|
103
|
-
internal fun build():
|
|
104
|
-
return
|
|
49
|
+
internal fun build(): SuspendFunctionComponentBuilder {
|
|
50
|
+
return requireNotNull(functionBuilder)
|
|
105
51
|
}
|
|
106
52
|
}
|
|
107
53
|
|
|
108
|
-
@Deprecated(
|
|
109
|
-
message = "The 'coroutine' component was renamed to 'Coroutine'.",
|
|
110
|
-
replaceWith = ReplaceWith("Coroutine(block)")
|
|
111
|
-
)
|
|
112
|
-
inline infix fun <reified R> AsyncFunctionBuilder.coroutine(crossinline block: suspend () -> R) = Coroutine(block)
|
|
113
|
-
|
|
114
|
-
@Deprecated(
|
|
115
|
-
message = "The 'coroutine' component was renamed to 'Coroutine'.",
|
|
116
|
-
replaceWith = ReplaceWith("Coroutine(block)")
|
|
117
|
-
)
|
|
118
|
-
inline infix fun <reified R, reified P0> AsyncFunctionBuilder.coroutine(crossinline block: suspend (P0) -> R) = Coroutine(block)
|
|
119
|
-
|
|
120
|
-
@Deprecated(
|
|
121
|
-
message = "The 'coroutine' component was renamed to 'Coroutine'.",
|
|
122
|
-
replaceWith = ReplaceWith("Coroutine(block)")
|
|
123
|
-
)
|
|
124
|
-
inline infix fun <reified R, reified P0, reified P1> AsyncFunctionBuilder.coroutine(crossinline block: suspend (P0, P1) -> R) = Coroutine(block)
|
|
125
|
-
|
|
126
|
-
@Deprecated(
|
|
127
|
-
message = "The 'coroutine' component was renamed to 'Coroutine'.",
|
|
128
|
-
replaceWith = ReplaceWith("Coroutine(block)")
|
|
129
|
-
)
|
|
130
|
-
inline infix fun <reified R, reified P0, reified P1, reified P2> AsyncFunctionBuilder.coroutine(crossinline block: suspend (P0, P1, P2) -> R) = Coroutine(block)
|
|
131
|
-
|
|
132
|
-
@Deprecated(
|
|
133
|
-
message = "The 'coroutine' component was renamed to 'Coroutine'.",
|
|
134
|
-
replaceWith = ReplaceWith("Coroutine(block)")
|
|
135
|
-
)
|
|
136
|
-
inline infix fun <reified R, reified P0, reified P1, reified P2, reified P3> AsyncFunctionBuilder.coroutine(crossinline block: suspend (P0, P1, P2, P3) -> R) = Coroutine(block)
|
|
137
|
-
|
|
138
|
-
@Deprecated(
|
|
139
|
-
message = "The 'coroutine' component was renamed to 'Coroutine'.",
|
|
140
|
-
replaceWith = ReplaceWith("Coroutine(block)")
|
|
141
|
-
)
|
|
142
|
-
inline infix fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> AsyncFunctionBuilder.coroutine(crossinline block: suspend (P0, P1, P2, P3, P4) -> R) = Coroutine(block)
|
|
143
|
-
|
|
144
|
-
@Deprecated(
|
|
145
|
-
message = "The 'coroutine' component was renamed to 'Coroutine'.",
|
|
146
|
-
replaceWith = ReplaceWith("Coroutine(block)")
|
|
147
|
-
)
|
|
148
|
-
inline infix fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> AsyncFunctionBuilder.coroutine(crossinline block: suspend (P0, P1, P2, P3, P4, P5) -> R) = Coroutine(block)
|
|
149
|
-
|
|
150
|
-
@Deprecated(
|
|
151
|
-
message = "The 'coroutine' component was renamed to 'Coroutine'.",
|
|
152
|
-
replaceWith = ReplaceWith("Coroutine(block)")
|
|
153
|
-
)
|
|
154
|
-
inline infix fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> AsyncFunctionBuilder.coroutine(crossinline block: suspend (P0, P1, P2, P3, P4, P5, P6) -> R) = Coroutine(block)
|
|
155
|
-
|
|
156
|
-
@Deprecated(
|
|
157
|
-
message = "The 'coroutine' component was renamed to 'Coroutine'.",
|
|
158
|
-
replaceWith = ReplaceWith("Coroutine(block)")
|
|
159
|
-
)
|
|
160
|
-
inline infix fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> AsyncFunctionBuilder.coroutine(crossinline block: suspend (P0, P1, P2, P3, P4, P5, P6, P7) -> R) = Coroutine(block)
|
|
161
|
-
|
|
162
54
|
inline infix fun <reified R> AsyncFunctionBuilder.Coroutine(crossinline block: suspend () -> R) = SuspendBody(block)
|
|
163
55
|
inline infix fun <reified R, reified P0> AsyncFunctionBuilder.Coroutine(crossinline block: suspend (P0) -> R) = SuspendBody(block)
|
|
164
56
|
inline infix fun <reified R, reified P0, reified P1> AsyncFunctionBuilder.Coroutine(crossinline block: suspend (P0, P1) -> R) = SuspendBody(block)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package expo.modules.kotlin.functions
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableArray
|
|
4
|
+
import expo.modules.kotlin.Promise
|
|
5
|
+
import expo.modules.kotlin.exception.CodedException
|
|
6
|
+
import expo.modules.kotlin.types.AnyType
|
|
7
|
+
|
|
8
|
+
class AsyncFunctionComponent(
|
|
9
|
+
name: String,
|
|
10
|
+
desiredArgsTypes: Array<AnyType>,
|
|
11
|
+
private val body: (args: Array<out Any?>) -> Any?
|
|
12
|
+
) : AsyncFunction(name, desiredArgsTypes) {
|
|
13
|
+
@Throws(CodedException::class)
|
|
14
|
+
override fun call(args: ReadableArray, promise: Promise) {
|
|
15
|
+
promise.resolve(body(convertArgs(args)))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override fun call(args: Array<Any?>, promise: Promise) {
|
|
19
|
+
promise.resolve(body(convertArgs(args)))
|
|
20
|
+
}
|
|
21
|
+
}
|
package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromiseComponent.kt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package expo.modules.kotlin.functions
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableArray
|
|
4
|
+
import expo.modules.kotlin.Promise
|
|
5
|
+
import expo.modules.kotlin.exception.CodedException
|
|
6
|
+
import expo.modules.kotlin.types.AnyType
|
|
7
|
+
|
|
8
|
+
class AsyncFunctionWithPromiseComponent(
|
|
9
|
+
name: String,
|
|
10
|
+
desiredArgsTypes: Array<AnyType>,
|
|
11
|
+
private val body: (args: Array<out Any?>, promise: Promise) -> Unit
|
|
12
|
+
) : AsyncFunction(name, desiredArgsTypes) {
|
|
13
|
+
@Throws(CodedException::class)
|
|
14
|
+
override fun call(args: ReadableArray, promise: Promise) {
|
|
15
|
+
body(convertArgs(args), promise)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override fun call(args: Array<Any?>, promise: Promise) {
|
|
19
|
+
body(convertArgs(args), promise)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
package expo.modules.kotlin.functions
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableArray
|
|
4
|
+
import expo.modules.kotlin.ModuleHolder
|
|
5
|
+
import expo.modules.kotlin.Promise
|
|
6
|
+
import expo.modules.kotlin.exception.CodedException
|
|
7
|
+
import expo.modules.kotlin.exception.FunctionCallException
|
|
8
|
+
import expo.modules.kotlin.exception.UnexpectedException
|
|
9
|
+
import expo.modules.kotlin.exception.exceptionDecorator
|
|
10
|
+
import expo.modules.kotlin.types.AnyType
|
|
11
|
+
import kotlinx.coroutines.CoroutineScope
|
|
12
|
+
import kotlinx.coroutines.isActive
|
|
13
|
+
import kotlinx.coroutines.launch
|
|
14
|
+
import java.lang.ref.WeakReference
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* We can't construct a `SuspendFunctionComponent` in the build phase, because it has to have access to module coroutine scope.
|
|
18
|
+
* So we create another builder to store needed information and build it later - during the holder initialization.
|
|
19
|
+
*/
|
|
20
|
+
class SuspendFunctionComponentBuilder(
|
|
21
|
+
internal val name: String,
|
|
22
|
+
private val desiredArgsTypes: Array<AnyType>,
|
|
23
|
+
private val body: suspend CoroutineScope.(args: Array<out Any?>) -> Any?,
|
|
24
|
+
) {
|
|
25
|
+
fun build(moduleHolder: ModuleHolder) =
|
|
26
|
+
SuspendFunctionComponent(name, desiredArgsTypes, WeakReference(moduleHolder), body)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class SuspendFunctionComponent(
|
|
30
|
+
name: String,
|
|
31
|
+
desiredArgsTypes: Array<AnyType>,
|
|
32
|
+
private val moduleHolderRef: WeakReference<ModuleHolder>,
|
|
33
|
+
private val body: suspend CoroutineScope.(args: Array<out Any?>) -> Any?
|
|
34
|
+
) : AsyncFunction(name, desiredArgsTypes) {
|
|
35
|
+
@Throws(CodedException::class)
|
|
36
|
+
override fun call(args: ReadableArray, promise: Promise) {
|
|
37
|
+
callWithConvertedArguments(convertArgs(args), promise)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override fun call(args: Array<Any?>, promise: Promise) {
|
|
41
|
+
callWithConvertedArguments(convertArgs(args), promise)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private fun callWithConvertedArguments(convertedArgs: Array<out Any?>, promise: Promise) {
|
|
45
|
+
val holder = moduleHolderRef.get() ?: return
|
|
46
|
+
val scope = holder.module.coroutineScopeDelegate.value
|
|
47
|
+
|
|
48
|
+
scope.launch {
|
|
49
|
+
try {
|
|
50
|
+
val result = exceptionDecorator({ cause -> FunctionCallException(name, holder.name, cause) }) {
|
|
51
|
+
body.invoke(scope, convertedArgs)
|
|
52
|
+
}
|
|
53
|
+
if (isActive) {
|
|
54
|
+
promise.resolve(result)
|
|
55
|
+
}
|
|
56
|
+
} catch (e: CodedException) {
|
|
57
|
+
promise.reject(e)
|
|
58
|
+
} catch (e: Throwable) {
|
|
59
|
+
promise.reject(UnexpectedException(e))
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package expo.modules.kotlin.functions
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.ReadableArray
|
|
5
|
+
import expo.modules.kotlin.AppContext
|
|
6
|
+
import expo.modules.kotlin.exception.CodedException
|
|
7
|
+
import expo.modules.kotlin.jni.JavaScriptModuleObject
|
|
8
|
+
import expo.modules.kotlin.types.AnyType
|
|
9
|
+
import expo.modules.kotlin.types.JSTypeConverter
|
|
10
|
+
|
|
11
|
+
class SyncFunctionComponent(
|
|
12
|
+
name: String,
|
|
13
|
+
desiredArgsTypes: Array<AnyType>,
|
|
14
|
+
private val body: (args: Array<out Any?>) -> Any?
|
|
15
|
+
) : AnyFunction(name, desiredArgsTypes) {
|
|
16
|
+
@Throws(CodedException::class)
|
|
17
|
+
fun call(args: ReadableArray): Any? {
|
|
18
|
+
return body(convertArgs(args))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fun call(args: Array<Any?>): Any? {
|
|
22
|
+
return body(convertArgs(args))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override fun attachToJSObject(appContext: AppContext, jsObject: JavaScriptModuleObject) {
|
|
26
|
+
jsObject.registerSyncFunction(
|
|
27
|
+
name,
|
|
28
|
+
argsCount,
|
|
29
|
+
getCppRequiredTypes()
|
|
30
|
+
) { args ->
|
|
31
|
+
val result = call(args)
|
|
32
|
+
val convertedResult = JSTypeConverter.convertToJSValue(result)
|
|
33
|
+
return@registerSyncFunction Arguments.fromJavaArgs(arrayOf(convertedResult))
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package expo.modules.kotlin.jni
|
|
2
|
+
|
|
3
|
+
private var nextValue = 0
|
|
4
|
+
|
|
5
|
+
private fun nextValue(): Int = (1 shl nextValue).also { nextValue++ }
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Enum that represents Cpp types. Objects of those types can be obtained via JNI.
|
|
9
|
+
*/
|
|
10
|
+
enum class CppType(val value: Int) {
|
|
11
|
+
NONE(0),
|
|
12
|
+
DOUBLE(nextValue()),
|
|
13
|
+
BOOLEAN(nextValue()),
|
|
14
|
+
STRING(nextValue()),
|
|
15
|
+
JS_OBJECT(nextValue()),
|
|
16
|
+
JS_VALUE(nextValue()),
|
|
17
|
+
READABLE_ARRAY(nextValue()),
|
|
18
|
+
READABLE_MAP(nextValue());
|
|
19
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package expo.modules.kotlin.jni
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableNativeArray
|
|
4
|
+
import expo.modules.core.interfaces.DoNotStrip
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* It's a wrapper for a promise-less function that will be invoked from JS.
|
|
8
|
+
* This interface is intended to be passed to cpp code.
|
|
9
|
+
* If you want to modify it, please don't forget to change the corresponding jni::JavaClass.
|
|
10
|
+
*/
|
|
11
|
+
@DoNotStrip
|
|
12
|
+
fun interface JNIFunctionBody {
|
|
13
|
+
/**
|
|
14
|
+
* Invokes the Kotlin part of the JNI function.
|
|
15
|
+
*
|
|
16
|
+
* We used a [com.facebook.react.bridge.ReadableNativeArray] to communicate with CPP, because
|
|
17
|
+
* right now it's the only object which is recognizable by those two worlds.
|
|
18
|
+
* In the future, we may want to swap it for something else.
|
|
19
|
+
*/
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
fun invoke(args: Array<Any?>): ReadableNativeArray?
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* It's a wrapper for a promise function that will be invoked from JS.
|
|
26
|
+
* This interface is intended to be passed to cpp code.
|
|
27
|
+
* If you want to modify it, please don't forget to change the corresponding jni::JavaClass.
|
|
28
|
+
*/
|
|
29
|
+
@DoNotStrip
|
|
30
|
+
fun interface JNIAsyncFunctionBody {
|
|
31
|
+
/**
|
|
32
|
+
* Invokes the Kotlin part of the JNI function.
|
|
33
|
+
*
|
|
34
|
+
* Note: that the `bridgePromise` has type of [Any], but it should be an instance of [com.facebook.react.bridge.Promise].
|
|
35
|
+
* This is dictated by the fact that [com.facebook.react.bridge.Promise] isn't a hybrid object of jni::HybridClass.
|
|
36
|
+
*/
|
|
37
|
+
@DoNotStrip
|
|
38
|
+
fun invoke(args: Array<Any?>, bridgePromise: Any)
|
|
39
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
package expo.modules.kotlin.jni
|
|
2
|
+
|
|
3
|
+
import com.facebook.jni.HybridData
|
|
4
|
+
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
|
|
5
|
+
import expo.modules.core.interfaces.DoNotStrip
|
|
6
|
+
import expo.modules.kotlin.AppContext
|
|
7
|
+
import expo.modules.kotlin.exception.JavaScriptEvaluateException
|
|
8
|
+
import java.lang.ref.WeakReference
|
|
9
|
+
|
|
10
|
+
@Suppress("KotlinJniMissingFunction")
|
|
11
|
+
@DoNotStrip
|
|
12
|
+
class JSIInteropModuleRegistry(appContext: AppContext) {
|
|
13
|
+
private val appContextHolder = WeakReference(appContext)
|
|
14
|
+
|
|
15
|
+
// Has to be called "mHybridData" - fbjni uses it via reflection
|
|
16
|
+
@DoNotStrip
|
|
17
|
+
private val mHybridData = initHybrid()
|
|
18
|
+
|
|
19
|
+
private external fun initHybrid(): HybridData
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Initializes the `ExpoModulesHostObject` and adds it to the global object.
|
|
23
|
+
*/
|
|
24
|
+
external fun installJSI(
|
|
25
|
+
jsRuntimePointer: Long,
|
|
26
|
+
jsInvokerHolder: CallInvokerHolderImpl,
|
|
27
|
+
nativeInvokerHolder: CallInvokerHolderImpl
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Initializes the test runtime. Shouldn't be used in the production.
|
|
32
|
+
*/
|
|
33
|
+
external fun installJSIForTests()
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Evaluates given JavaScript source code.
|
|
37
|
+
* @throws JavaScriptEvaluateException if the input format is unknown or evaluation causes an error
|
|
38
|
+
*/
|
|
39
|
+
@Throws(JavaScriptEvaluateException::class)
|
|
40
|
+
external fun evaluateScript(script: String): JavaScriptValue
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns the runtime global object
|
|
44
|
+
*/
|
|
45
|
+
external fun global(): JavaScriptObject
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns a new instance of [JavaScriptObject]
|
|
49
|
+
*/
|
|
50
|
+
external fun createObject(): JavaScriptObject
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Drains the JavaScript VM internal Microtask (a.k.a. event loop) queue.
|
|
54
|
+
*/
|
|
55
|
+
external fun drainJSEventLoop()
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns a `JavaScriptModuleObject` that is a bridge between [expo.modules.kotlin.modules.Module]
|
|
59
|
+
* and HostObject exported via JSI.
|
|
60
|
+
*
|
|
61
|
+
* This function will be called from the CPP implementation.
|
|
62
|
+
* It doesn't make sense to call it from Kotlin.
|
|
63
|
+
*/
|
|
64
|
+
@Suppress("unused")
|
|
65
|
+
@DoNotStrip
|
|
66
|
+
fun getJavaScriptModuleObject(name: String): JavaScriptModuleObject? {
|
|
67
|
+
return appContextHolder.get()?.registry?.getModuleHolder(name)?.jsObject
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Returns an array that contains names of available modules.
|
|
72
|
+
*/
|
|
73
|
+
@Suppress("unused")
|
|
74
|
+
@DoNotStrip
|
|
75
|
+
fun getJavaScriptModulesName(): Array<String> {
|
|
76
|
+
return appContextHolder.get()?.registry?.registry?.keys?.toTypedArray() ?: emptyArray()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Throws(Throwable::class)
|
|
80
|
+
protected fun finalize() {
|
|
81
|
+
mHybridData.resetNative()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
companion object {
|
|
85
|
+
init {
|
|
86
|
+
System.loadLibrary("expo-modules-core")
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package expo.modules.kotlin.jni
|
|
2
|
+
|
|
3
|
+
import com.facebook.jni.HybridData
|
|
4
|
+
import com.facebook.react.bridge.NativeMap
|
|
5
|
+
import expo.modules.core.interfaces.DoNotStrip
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A class to communicate with CPP part of the [expo.modules.kotlin.modules.Module] class.
|
|
9
|
+
* Used to register exported JSI functions.
|
|
10
|
+
* The lifetime of instances of this class should be in sync with the lifetime of the bridge.
|
|
11
|
+
* All exported functions/objects will have a reference to the `JavaScriptModuleObject`,
|
|
12
|
+
* so it must outlive the current RN context.
|
|
13
|
+
*/
|
|
14
|
+
@Suppress("KotlinJniMissingFunction")
|
|
15
|
+
@DoNotStrip
|
|
16
|
+
class JavaScriptModuleObject {
|
|
17
|
+
// Has to be called "mHybridData" - fbjni uses it via reflection
|
|
18
|
+
@DoNotStrip
|
|
19
|
+
private val mHybridData = initHybrid()
|
|
20
|
+
|
|
21
|
+
private external fun initHybrid(): HybridData
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Exports constants
|
|
25
|
+
*/
|
|
26
|
+
external fun exportConstants(constants: NativeMap)
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Register a promise-less function on the CPP module representation.
|
|
30
|
+
* After calling this function, user can access the exported function in the JS code.
|
|
31
|
+
*/
|
|
32
|
+
external fun registerSyncFunction(name: String, args: Int, desiredTypes: IntArray, body: JNIFunctionBody)
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Register a promise function on the CPP module representation.
|
|
36
|
+
* After calling this function, user can access the exported function in the JS code.
|
|
37
|
+
*/
|
|
38
|
+
external fun registerAsyncFunction(name: String, args: Int, desiredTypes: IntArray, body: JNIAsyncFunctionBody)
|
|
39
|
+
|
|
40
|
+
external fun registerProperty(name: String, desiredType: Int, getter: JNIFunctionBody?, setter: JNIFunctionBody?)
|
|
41
|
+
|
|
42
|
+
@Throws(Throwable::class)
|
|
43
|
+
protected fun finalize() {
|
|
44
|
+
mHybridData.resetNative()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
package expo.modules.kotlin.jni
|
|
2
|
+
|
|
3
|
+
import com.facebook.jni.HybridData
|
|
4
|
+
import expo.modules.core.interfaces.DoNotStrip
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A Kotlin representation of jsi::Object.
|
|
8
|
+
* Should be used only on the runtime thread.
|
|
9
|
+
*/
|
|
10
|
+
@Suppress("KotlinJniMissingFunction")
|
|
11
|
+
@DoNotStrip
|
|
12
|
+
class JavaScriptObject @DoNotStrip private constructor(@DoNotStrip private val mHybridData: HybridData) {
|
|
13
|
+
/**
|
|
14
|
+
* The property descriptor options for the property being defined or modified.
|
|
15
|
+
*/
|
|
16
|
+
enum class PropertyDescriptor(val value: Int) {
|
|
17
|
+
/**
|
|
18
|
+
* If set, the type of this property descriptor may be changed and if the property may be deleted from the corresponding object.
|
|
19
|
+
*/
|
|
20
|
+
Configurable(1 shl 0),
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* If set, the property shows up during enumeration of the properties on the corresponding object.
|
|
24
|
+
*/
|
|
25
|
+
Enumerable(1 shl 1),
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* If set, the value associated with the property may be changed with an assignment operator.
|
|
29
|
+
*/
|
|
30
|
+
Writable(1 shl 2),
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
external fun hasProperty(name: String): Boolean
|
|
34
|
+
external fun getProperty(name: String): JavaScriptValue
|
|
35
|
+
external fun getPropertyNames(): Array<String>
|
|
36
|
+
|
|
37
|
+
private external fun setBoolProperty(name: String, value: Boolean)
|
|
38
|
+
private external fun setDoubleProperty(name: String, value: Double)
|
|
39
|
+
private external fun setStringProperty(name: String, value: String?)
|
|
40
|
+
private external fun setJSValueProperty(name: String, value: JavaScriptValue?)
|
|
41
|
+
private external fun setJSObjectProperty(name: String, value: JavaScriptObject?)
|
|
42
|
+
private external fun unsetProperty(name: String)
|
|
43
|
+
|
|
44
|
+
private external fun defineBoolProperty(name: String, value: Boolean, options: Int)
|
|
45
|
+
private external fun defineDoubleProperty(name: String, value: Double, options: Int)
|
|
46
|
+
private external fun defineStringProperty(name: String, value: String?, options: Int)
|
|
47
|
+
private external fun defineJSValueProperty(name: String, value: JavaScriptValue?, options: Int)
|
|
48
|
+
private external fun defineJSObjectProperty(name: String, value: JavaScriptObject?, options: Int)
|
|
49
|
+
|
|
50
|
+
fun setProperty(name: String, value: Boolean) = setBoolProperty(name, value)
|
|
51
|
+
fun setProperty(name: String, value: Int) = setDoubleProperty(name, value.toDouble())
|
|
52
|
+
fun setProperty(name: String, value: Double) = setDoubleProperty(name, value)
|
|
53
|
+
fun setProperty(name: String, value: String?) = setStringProperty(name, value)
|
|
54
|
+
fun setProperty(name: String, value: JavaScriptValue?) = setJSValueProperty(name, value)
|
|
55
|
+
fun setProperty(name: String, value: JavaScriptObject?) = setJSObjectProperty(name, value)
|
|
56
|
+
|
|
57
|
+
// Needed to handle untyped null value
|
|
58
|
+
// Without it setProperty(name, null) won't work
|
|
59
|
+
fun setProperty(name: String, `null`: Nothing?) = unsetProperty(name)
|
|
60
|
+
|
|
61
|
+
fun defineProperty(
|
|
62
|
+
name: String,
|
|
63
|
+
value: Boolean,
|
|
64
|
+
options: List<PropertyDescriptor> = emptyList()
|
|
65
|
+
) = defineBoolProperty(name, value, options.toCppOptions())
|
|
66
|
+
|
|
67
|
+
fun defineProperty(
|
|
68
|
+
name: String,
|
|
69
|
+
value: Int,
|
|
70
|
+
options: List<PropertyDescriptor> = emptyList()
|
|
71
|
+
) = defineDoubleProperty(name, value.toDouble(), options.toCppOptions())
|
|
72
|
+
|
|
73
|
+
fun defineProperty(
|
|
74
|
+
name: String,
|
|
75
|
+
value: Double,
|
|
76
|
+
options: List<PropertyDescriptor> = emptyList()
|
|
77
|
+
) = defineDoubleProperty(name, value, options.toCppOptions())
|
|
78
|
+
|
|
79
|
+
fun defineProperty(
|
|
80
|
+
name: String,
|
|
81
|
+
value: String?,
|
|
82
|
+
options: List<PropertyDescriptor> = emptyList()
|
|
83
|
+
) = defineStringProperty(name, value, options.toCppOptions())
|
|
84
|
+
|
|
85
|
+
fun defineProperty(
|
|
86
|
+
name: String,
|
|
87
|
+
value: JavaScriptValue?,
|
|
88
|
+
options: List<PropertyDescriptor> = emptyList()
|
|
89
|
+
) = defineJSValueProperty(name, value, options.toCppOptions())
|
|
90
|
+
|
|
91
|
+
fun defineProperty(
|
|
92
|
+
name: String,
|
|
93
|
+
value: JavaScriptObject?,
|
|
94
|
+
options: List<PropertyDescriptor> = emptyList()
|
|
95
|
+
) = defineJSObjectProperty(name, value, options.toCppOptions())
|
|
96
|
+
|
|
97
|
+
// Needed to handle untyped null value
|
|
98
|
+
fun defineProperty(
|
|
99
|
+
name: String,
|
|
100
|
+
`null`: Nothing?,
|
|
101
|
+
options: List<PropertyDescriptor> = emptyList()
|
|
102
|
+
) = defineJSObjectProperty(name, null, options.toCppOptions())
|
|
103
|
+
|
|
104
|
+
@Throws(Throwable::class)
|
|
105
|
+
protected fun finalize() {
|
|
106
|
+
mHybridData.resetNative()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private fun List<JavaScriptObject.PropertyDescriptor>.toCppOptions(): Int =
|
|
111
|
+
fold(0) { acc, current ->
|
|
112
|
+
acc or current.value
|
|
113
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package expo.modules.kotlin.jni
|
|
2
|
+
|
|
3
|
+
import com.facebook.jni.HybridData
|
|
4
|
+
import expo.modules.core.interfaces.DoNotStrip
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A Kotlin representation of jsi::Value.
|
|
8
|
+
* Should be used only on the runtime thread.
|
|
9
|
+
*/
|
|
10
|
+
@Suppress("KotlinJniMissingFunction")
|
|
11
|
+
@DoNotStrip
|
|
12
|
+
class JavaScriptValue @DoNotStrip private constructor(@DoNotStrip private val mHybridData: HybridData) {
|
|
13
|
+
external fun kind(): String
|
|
14
|
+
|
|
15
|
+
external fun isNull(): Boolean
|
|
16
|
+
external fun isUndefined(): Boolean
|
|
17
|
+
external fun isBool(): Boolean
|
|
18
|
+
external fun isNumber(): Boolean
|
|
19
|
+
external fun isString(): Boolean
|
|
20
|
+
external fun isSymbol(): Boolean
|
|
21
|
+
external fun isFunction(): Boolean
|
|
22
|
+
external fun isArray(): Boolean
|
|
23
|
+
external fun isObject(): Boolean
|
|
24
|
+
|
|
25
|
+
external fun getBool(): Boolean
|
|
26
|
+
external fun getDouble(): Double
|
|
27
|
+
external fun getString(): String
|
|
28
|
+
external fun getObject(): JavaScriptObject
|
|
29
|
+
external fun getArray(): Array<JavaScriptValue>
|
|
30
|
+
|
|
31
|
+
@Throws(Throwable::class)
|
|
32
|
+
protected fun finalize() {
|
|
33
|
+
mHybridData.resetNative()
|
|
34
|
+
}
|
|
35
|
+
}
|