expo-modules-core 0.9.0 → 0.10.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 +25 -0
- package/android/CMakeLists.txt +154 -0
- package/android/build.gradle +293 -5
- 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 +29 -0
- package/android/src/main/cpp/JNIFunctionBody.h +50 -0
- package/android/src/main/cpp/JNIInjector.cpp +19 -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 +138 -0
- package/android/src/main/cpp/JavaScriptModuleObject.h +122 -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 +230 -0
- package/android/src/main/cpp/MethodMetadata.h +92 -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 +49 -1
- 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 +39 -3
- 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 +19 -14
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +29 -7
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +13 -13
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionComponent.kt +18 -0
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromiseComponent.kt +18 -0
- package/android/src/main/java/expo/modules/kotlin/functions/SuspendFunctionComponent.kt +56 -0
- package/android/src/main/java/expo/modules/kotlin/functions/SyncFunctionComponent.kt +28 -0
- package/android/src/main/java/expo/modules/kotlin/jni/CppType.kt +18 -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 +44 -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 +15 -5
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +65 -111
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionData.kt +35 -2
- 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/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 +5 -0
- 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/ios/AppDelegates/EXAppDelegatesLoader.m +1 -2
- package/ios/ExpoModulesCore.podspec +1 -1
- 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 +47 -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 +88 -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 +208 -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/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 +65 -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 +198 -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 +12 -3
- 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/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
|
@@ -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
|
+
}
|
|
@@ -3,24 +3,34 @@ package expo.modules.kotlin.modules
|
|
|
3
3
|
import android.os.Bundle
|
|
4
4
|
import expo.modules.core.errors.ModuleDestroyedException
|
|
5
5
|
import expo.modules.kotlin.AppContext
|
|
6
|
+
import expo.modules.kotlin.providers.AppContextProvider
|
|
6
7
|
import kotlinx.coroutines.CoroutineScope
|
|
7
8
|
import kotlinx.coroutines.cancel
|
|
8
9
|
|
|
9
|
-
abstract class Module {
|
|
10
|
+
abstract class Module : AppContextProvider {
|
|
11
|
+
|
|
12
|
+
// region AppContextProvider
|
|
13
|
+
|
|
10
14
|
@Suppress("PropertyName")
|
|
11
15
|
internal var _appContext: AppContext? = null
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
val appContext: AppContext
|
|
17
|
+
override val appContext: AppContext
|
|
16
18
|
get() = requireNotNull(_appContext) { "The module wasn't created! You can't access the app context." }
|
|
17
19
|
|
|
20
|
+
// endregion
|
|
21
|
+
|
|
22
|
+
private val moduleEventEmitter by lazy { appContext.eventEmitter(this) }
|
|
23
|
+
|
|
18
24
|
@Suppress("PropertyName")
|
|
19
25
|
@PublishedApi
|
|
20
26
|
internal lateinit var coroutineScopeDelegate: Lazy<CoroutineScope>
|
|
21
27
|
val coroutineScope get() = coroutineScopeDelegate.value
|
|
22
28
|
|
|
23
|
-
fun sendEvent(name: String, body: Bundle?) {
|
|
29
|
+
fun sendEvent(name: String, body: Bundle? = Bundle.EMPTY) {
|
|
30
|
+
moduleEventEmitter?.emit(name, body)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fun sendEvent(name: String, body: Map<String, Any?>?) {
|
|
24
34
|
moduleEventEmitter?.emit(name, body)
|
|
25
35
|
}
|
|
26
36
|
|
|
@@ -24,10 +24,11 @@ import expo.modules.kotlin.events.EventListenerWithSenderAndPayload
|
|
|
24
24
|
import expo.modules.kotlin.events.EventName
|
|
25
25
|
import expo.modules.kotlin.events.EventsDefinition
|
|
26
26
|
import expo.modules.kotlin.events.OnActivityResultPayload
|
|
27
|
-
import expo.modules.kotlin.functions.AnyFunction
|
|
28
27
|
import expo.modules.kotlin.functions.AsyncFunction
|
|
29
|
-
import expo.modules.kotlin.functions.AsyncFunctionWithPromise
|
|
30
28
|
import expo.modules.kotlin.functions.AsyncFunctionBuilder
|
|
29
|
+
import expo.modules.kotlin.functions.AsyncFunctionComponent
|
|
30
|
+
import expo.modules.kotlin.functions.AsyncFunctionWithPromiseComponent
|
|
31
|
+
import expo.modules.kotlin.functions.SyncFunctionComponent
|
|
31
32
|
import expo.modules.kotlin.types.toAnyType
|
|
32
33
|
import expo.modules.kotlin.views.ViewManagerDefinition
|
|
33
34
|
import expo.modules.kotlin.views.ViewManagerDefinitionBuilder
|
|
@@ -41,7 +42,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
41
42
|
private var functionBuilders = mutableListOf<AsyncFunctionBuilder>()
|
|
42
43
|
|
|
43
44
|
@PublishedApi
|
|
44
|
-
internal var
|
|
45
|
+
internal var syncFunctions = mutableMapOf<String, SyncFunctionComponent>()
|
|
46
|
+
|
|
47
|
+
@PublishedApi
|
|
48
|
+
internal var asyncFunctions = mutableMapOf<String, AsyncFunction>()
|
|
45
49
|
|
|
46
50
|
@PublishedApi
|
|
47
51
|
internal var viewManagerDefinition: ViewManagerDefinition? = null
|
|
@@ -55,7 +59,9 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
55
59
|
return ModuleDefinitionData(
|
|
56
60
|
requireNotNull(moduleName),
|
|
57
61
|
constantsProvider,
|
|
58
|
-
|
|
62
|
+
syncFunctions,
|
|
63
|
+
asyncFunctions,
|
|
64
|
+
functionBuilders.map { it.build() },
|
|
59
65
|
viewManagerDefinition,
|
|
60
66
|
eventListeners,
|
|
61
67
|
eventsDefinition
|
|
@@ -101,146 +107,94 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
101
107
|
constantsProvider = { constants.toMap() }
|
|
102
108
|
}
|
|
103
109
|
|
|
104
|
-
@
|
|
105
|
-
|
|
106
|
-
replaceWith = ReplaceWith("AsyncFunction(name, body)")
|
|
107
|
-
)
|
|
108
|
-
@JvmName("functionWithoutArgs")
|
|
109
|
-
inline fun function(
|
|
110
|
+
@JvmName("FunctionWithoutArgs")
|
|
111
|
+
inline fun Function(
|
|
110
112
|
name: String,
|
|
111
113
|
crossinline body: () -> Any?
|
|
112
114
|
) {
|
|
113
|
-
|
|
115
|
+
SyncFunctionComponent(name, arrayOf()) { body() }.also {
|
|
116
|
+
syncFunctions[name] = it
|
|
117
|
+
}
|
|
114
118
|
}
|
|
115
119
|
|
|
116
|
-
|
|
117
|
-
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
118
|
-
replaceWith = ReplaceWith("AsyncFunction(name, body)")
|
|
119
|
-
)
|
|
120
|
-
inline fun <reified R> function(
|
|
120
|
+
inline fun <reified R> Function(
|
|
121
121
|
name: String,
|
|
122
122
|
crossinline body: () -> R
|
|
123
123
|
) {
|
|
124
|
-
|
|
124
|
+
SyncFunctionComponent(name, arrayOf()) { body() }.also {
|
|
125
|
+
syncFunctions[name] = it
|
|
126
|
+
}
|
|
125
127
|
}
|
|
126
128
|
|
|
127
|
-
|
|
128
|
-
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
129
|
-
replaceWith = ReplaceWith("AsyncFunction(name, body)")
|
|
130
|
-
)
|
|
131
|
-
inline fun <reified R, reified P0> function(
|
|
129
|
+
inline fun <reified R, reified P0> Function(
|
|
132
130
|
name: String,
|
|
133
131
|
crossinline body: (p0: P0) -> R
|
|
134
132
|
) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
} else {
|
|
138
|
-
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }
|
|
133
|
+
SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }.also {
|
|
134
|
+
syncFunctions[name] = it
|
|
139
135
|
}
|
|
140
136
|
}
|
|
141
137
|
|
|
142
|
-
|
|
143
|
-
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
144
|
-
replaceWith = ReplaceWith("AsyncFunction(name, body)")
|
|
145
|
-
)
|
|
146
|
-
inline fun <reified R, reified P0, reified P1> function(
|
|
138
|
+
inline fun <reified R, reified P0, reified P1> Function(
|
|
147
139
|
name: String,
|
|
148
140
|
crossinline body: (p0: P0, p1: P1) -> R
|
|
149
141
|
) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
} else {
|
|
153
|
-
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }
|
|
142
|
+
SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }.also {
|
|
143
|
+
syncFunctions[name] = it
|
|
154
144
|
}
|
|
155
145
|
}
|
|
156
146
|
|
|
157
|
-
|
|
158
|
-
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
159
|
-
replaceWith = ReplaceWith("AsyncFunction(name, body)")
|
|
160
|
-
)
|
|
161
|
-
inline fun <reified R, reified P0, reified P1, reified P2> function(
|
|
147
|
+
inline fun <reified R, reified P0, reified P1, reified P2> Function(
|
|
162
148
|
name: String,
|
|
163
149
|
crossinline body: (p0: P0, p1: P1, p2: P2) -> R
|
|
164
150
|
) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
} else {
|
|
168
|
-
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }
|
|
151
|
+
SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }.also {
|
|
152
|
+
syncFunctions[name] = it
|
|
169
153
|
}
|
|
170
154
|
}
|
|
171
155
|
|
|
172
|
-
@Deprecated(
|
|
173
|
-
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
174
|
-
replaceWith = ReplaceWith("AsyncFunction(name, body)")
|
|
175
|
-
)
|
|
176
156
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3> function(
|
|
177
157
|
name: String,
|
|
178
158
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
|
|
179
159
|
) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
} else {
|
|
183
|
-
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }
|
|
160
|
+
SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }.also {
|
|
161
|
+
syncFunctions[name] = it
|
|
184
162
|
}
|
|
185
163
|
}
|
|
186
164
|
|
|
187
|
-
@Deprecated(
|
|
188
|
-
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
189
|
-
replaceWith = ReplaceWith("AsyncFunction(name, body)")
|
|
190
|
-
)
|
|
191
165
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> function(
|
|
192
166
|
name: String,
|
|
193
167
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
|
|
194
168
|
) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
} else {
|
|
198
|
-
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }
|
|
169
|
+
SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }.also {
|
|
170
|
+
syncFunctions[name] = it
|
|
199
171
|
}
|
|
200
172
|
}
|
|
201
173
|
|
|
202
|
-
|
|
203
|
-
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
204
|
-
replaceWith = ReplaceWith("AsyncFunction(name, body)")
|
|
205
|
-
)
|
|
206
|
-
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> function(
|
|
174
|
+
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> Function(
|
|
207
175
|
name: String,
|
|
208
176
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
|
|
209
177
|
) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
} else {
|
|
213
|
-
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }
|
|
178
|
+
SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }.also {
|
|
179
|
+
syncFunctions[name] = it
|
|
214
180
|
}
|
|
215
181
|
}
|
|
216
182
|
|
|
217
|
-
@Deprecated(
|
|
218
|
-
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
219
|
-
replaceWith = ReplaceWith("AsyncFunction(name, body)")
|
|
220
|
-
)
|
|
221
183
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> function(
|
|
222
184
|
name: String,
|
|
223
185
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
|
|
224
186
|
) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
} else {
|
|
228
|
-
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { body(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) }
|
|
187
|
+
SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { body(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) }.also {
|
|
188
|
+
syncFunctions[name] = it
|
|
229
189
|
}
|
|
230
190
|
}
|
|
231
191
|
|
|
232
|
-
@Deprecated(
|
|
233
|
-
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
234
|
-
replaceWith = ReplaceWith("AsyncFunction(name, body)")
|
|
235
|
-
)
|
|
236
192
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> function(
|
|
237
193
|
name: String,
|
|
238
194
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
|
|
239
195
|
) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
} else {
|
|
243
|
-
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { body(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) }
|
|
196
|
+
SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { body(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) }.also {
|
|
197
|
+
syncFunctions[name] = it
|
|
244
198
|
}
|
|
245
199
|
}
|
|
246
200
|
|
|
@@ -259,7 +213,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
259
213
|
name: String,
|
|
260
214
|
crossinline body: () -> Any?
|
|
261
215
|
) {
|
|
262
|
-
|
|
216
|
+
asyncFunctions[name] = AsyncFunctionComponent(name, arrayOf()) { body() }
|
|
263
217
|
}
|
|
264
218
|
|
|
265
219
|
@Deprecated(
|
|
@@ -275,7 +229,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
275
229
|
name: String,
|
|
276
230
|
crossinline body: () -> R
|
|
277
231
|
) {
|
|
278
|
-
|
|
232
|
+
asyncFunctions[name] = AsyncFunctionComponent(name, arrayOf()) { body() }
|
|
279
233
|
}
|
|
280
234
|
|
|
281
235
|
@Deprecated(
|
|
@@ -291,10 +245,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
291
245
|
name: String,
|
|
292
246
|
crossinline body: (p0: P0) -> R
|
|
293
247
|
) {
|
|
294
|
-
|
|
295
|
-
|
|
248
|
+
asyncFunctions[name] = if (P0::class == Promise::class) {
|
|
249
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf()) { _, promise -> body(promise as P0) }
|
|
296
250
|
} else {
|
|
297
|
-
|
|
251
|
+
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }
|
|
298
252
|
}
|
|
299
253
|
}
|
|
300
254
|
|
|
@@ -311,10 +265,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
311
265
|
name: String,
|
|
312
266
|
crossinline body: (p0: P0, p1: P1) -> R
|
|
313
267
|
) {
|
|
314
|
-
|
|
315
|
-
|
|
268
|
+
asyncFunctions[name] = if (P1::class == Promise::class) {
|
|
269
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType())) { args, promise -> body(args[0] as P0, promise as P1) }
|
|
316
270
|
} else {
|
|
317
|
-
|
|
271
|
+
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }
|
|
318
272
|
}
|
|
319
273
|
}
|
|
320
274
|
|
|
@@ -331,10 +285,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
331
285
|
name: String,
|
|
332
286
|
crossinline body: (p0: P0, p1: P1, p2: P2) -> R
|
|
333
287
|
) {
|
|
334
|
-
|
|
335
|
-
|
|
288
|
+
asyncFunctions[name] = if (P2::class == Promise::class) {
|
|
289
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, promise as P2) }
|
|
336
290
|
} else {
|
|
337
|
-
|
|
291
|
+
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }
|
|
338
292
|
}
|
|
339
293
|
}
|
|
340
294
|
|
|
@@ -351,10 +305,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
351
305
|
name: String,
|
|
352
306
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
|
|
353
307
|
) {
|
|
354
|
-
|
|
355
|
-
|
|
308
|
+
asyncFunctions[name] = if (P3::class == Promise::class) {
|
|
309
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, promise as P3) }
|
|
356
310
|
} else {
|
|
357
|
-
|
|
311
|
+
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }
|
|
358
312
|
}
|
|
359
313
|
}
|
|
360
314
|
|
|
@@ -371,10 +325,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
371
325
|
name: String,
|
|
372
326
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
|
|
373
327
|
) {
|
|
374
|
-
|
|
375
|
-
|
|
328
|
+
asyncFunctions[name] = if (P4::class == Promise::class) {
|
|
329
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, promise as P4) }
|
|
376
330
|
} else {
|
|
377
|
-
|
|
331
|
+
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }
|
|
378
332
|
}
|
|
379
333
|
}
|
|
380
334
|
|
|
@@ -391,10 +345,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
391
345
|
name: String,
|
|
392
346
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
|
|
393
347
|
) {
|
|
394
|
-
|
|
395
|
-
|
|
348
|
+
asyncFunctions[name] = if (P5::class == Promise::class) {
|
|
349
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, promise as P5) }
|
|
396
350
|
} else {
|
|
397
|
-
|
|
351
|
+
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }
|
|
398
352
|
}
|
|
399
353
|
}
|
|
400
354
|
|
|
@@ -411,10 +365,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
411
365
|
name: String,
|
|
412
366
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
|
|
413
367
|
) {
|
|
414
|
-
|
|
415
|
-
|
|
368
|
+
asyncFunctions[name] = if (P6::class == Promise::class) {
|
|
369
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, promise as P6) }
|
|
416
370
|
} else {
|
|
417
|
-
|
|
371
|
+
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { body(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) }
|
|
418
372
|
}
|
|
419
373
|
}
|
|
420
374
|
|
|
@@ -431,10 +385,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
|
|
|
431
385
|
name: String,
|
|
432
386
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
|
|
433
387
|
) {
|
|
434
|
-
|
|
435
|
-
|
|
388
|
+
asyncFunctions[name] = if (P7::class == Promise::class) {
|
|
389
|
+
AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, args[6] as P6, promise as P7) }
|
|
436
390
|
} else {
|
|
437
|
-
|
|
391
|
+
AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { body(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) }
|
|
438
392
|
}
|
|
439
393
|
}
|
|
440
394
|
|
|
@@ -1,16 +1,49 @@
|
|
|
1
1
|
package expo.modules.kotlin.modules
|
|
2
2
|
|
|
3
|
+
import expo.modules.kotlin.ConcatIterator
|
|
4
|
+
import expo.modules.kotlin.ModuleHolder
|
|
3
5
|
import expo.modules.kotlin.events.EventListener
|
|
4
6
|
import expo.modules.kotlin.events.EventName
|
|
5
7
|
import expo.modules.kotlin.events.EventsDefinition
|
|
6
|
-
import expo.modules.kotlin.functions.
|
|
8
|
+
import expo.modules.kotlin.functions.AsyncFunction
|
|
9
|
+
import expo.modules.kotlin.functions.SuspendFunctionComponentBuilder
|
|
10
|
+
import expo.modules.kotlin.functions.SyncFunctionComponent
|
|
7
11
|
import expo.modules.kotlin.views.ViewManagerDefinition
|
|
8
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Intermediate data used to create a proper [ProcessedModuleDefinition].
|
|
15
|
+
* It contains all, unprocessed data from [ModuleDefinitionBuilder].
|
|
16
|
+
*/
|
|
9
17
|
class ModuleDefinitionData(
|
|
10
18
|
val name: String,
|
|
11
19
|
val constantsProvider: () -> Map<String, Any?>,
|
|
12
|
-
val
|
|
20
|
+
val syncFunctions: Map<String, SyncFunctionComponent>,
|
|
21
|
+
val asyncFunctions: Map<String, AsyncFunction>,
|
|
22
|
+
val suspendFunctionBuilders: List<SuspendFunctionComponentBuilder>,
|
|
13
23
|
val viewManagerDefinition: ViewManagerDefinition? = null,
|
|
14
24
|
val eventListeners: Map<EventName, EventListener> = emptyMap(),
|
|
15
25
|
val eventsDefinition: EventsDefinition? = null
|
|
16
26
|
)
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A final version of the ModuleDefinition.
|
|
30
|
+
* Most values are just copied from [ModuleDefinitionData].
|
|
31
|
+
* However some fields like `asyncFunctions` need to be processed or bound with the [ModuleHolder].
|
|
32
|
+
*/
|
|
33
|
+
class ProcessedModuleDefinition(
|
|
34
|
+
data: ModuleDefinitionData,
|
|
35
|
+
moduleHolder: ModuleHolder
|
|
36
|
+
) {
|
|
37
|
+
val name = data.name
|
|
38
|
+
val constantsProvider = data.constantsProvider
|
|
39
|
+
val syncFunctions = data.syncFunctions
|
|
40
|
+
val asyncFunctions = data.asyncFunctions + data.suspendFunctionBuilders.associate { builder ->
|
|
41
|
+
builder.name to builder.build((moduleHolder))
|
|
42
|
+
}
|
|
43
|
+
val viewManagerDefinition = data.viewManagerDefinition
|
|
44
|
+
val eventListeners = data.eventListeners
|
|
45
|
+
val eventsDefinition = data.eventsDefinition
|
|
46
|
+
|
|
47
|
+
val functions
|
|
48
|
+
get() = ConcatIterator(syncFunctions.values.iterator(), asyncFunctions.values.iterator())
|
|
49
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
package expo.modules.kotlin.providers
|
|
2
|
+
|
|
3
|
+
import expo.modules.kotlin.AppContext
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Provider that allows accessing [AppContext] and all it's public parts (e.g. [AppContext.reactContext]).
|
|
7
|
+
*/
|
|
8
|
+
interface AppContextProvider {
|
|
9
|
+
/**
|
|
10
|
+
* [AppContext] reference. If it's not possible to access the [AppContext], because it's null
|
|
11
|
+
* then it's an invalid situation and should result in throwing descriptive error.
|
|
12
|
+
*/
|
|
13
|
+
val appContext: AppContext
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package expo.modules.kotlin.providers
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactActivity
|
|
4
|
+
import androidx.appcompat.app.AppCompatActivity
|
|
5
|
+
import androidx.fragment.app.FragmentActivity
|
|
6
|
+
import androidx.core.app.ComponentActivity
|
|
7
|
+
import android.app.Activity
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A class that provides the accessor to the [ReactActivity]. It enables accessing
|
|
11
|
+
* AndroidX/Android Jetpack features in Expo libraries coming from all subclassing chain:
|
|
12
|
+
* [AppCompatActivity], [FragmentActivity], [ComponentActivity], [Activity]
|
|
13
|
+
*/
|
|
14
|
+
interface CurrentActivityProvider {
|
|
15
|
+
/**
|
|
16
|
+
* Returns the current [Activity] that should be an instance of [AppCompatActivity].
|
|
17
|
+
* This activity is most likely an instance of [ReactActivity], but it's been decided not to expose
|
|
18
|
+
* `react-native` symbols via `expo-module-core` public API.
|
|
19
|
+
* @returns null if the [Activity] is not yet available (eg. Application has not yet fully started)
|
|
20
|
+
*/
|
|
21
|
+
val currentActivity: AppCompatActivity?
|
|
22
|
+
}
|