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
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
package expo.modules.kotlin.modules
|
|
2
2
|
|
|
3
3
|
import android.os.Bundle
|
|
4
|
+
import expo.modules.core.errors.ModuleDestroyedException
|
|
4
5
|
import expo.modules.kotlin.AppContext
|
|
6
|
+
import kotlinx.coroutines.CoroutineScope
|
|
7
|
+
import kotlinx.coroutines.cancel
|
|
5
8
|
|
|
6
9
|
abstract class Module {
|
|
10
|
+
@Suppress("PropertyName")
|
|
7
11
|
internal var _appContext: AppContext? = null
|
|
8
12
|
|
|
9
13
|
private val moduleEventEmitter by lazy { appContext.eventEmitter(this) }
|
|
@@ -11,14 +15,25 @@ abstract class Module {
|
|
|
11
15
|
val appContext: AppContext
|
|
12
16
|
get() = requireNotNull(_appContext) { "The module wasn't created! You can't access the app context." }
|
|
13
17
|
|
|
18
|
+
@Suppress("PropertyName")
|
|
19
|
+
@PublishedApi
|
|
20
|
+
internal lateinit var coroutineScopeDelegate: Lazy<CoroutineScope>
|
|
21
|
+
val coroutineScope get() = coroutineScopeDelegate.value
|
|
22
|
+
|
|
14
23
|
fun sendEvent(name: String, body: Bundle?) {
|
|
15
24
|
moduleEventEmitter?.emit(name, body)
|
|
16
25
|
}
|
|
17
26
|
|
|
18
27
|
abstract fun definition(): ModuleDefinitionData
|
|
28
|
+
|
|
29
|
+
internal fun cleanUp() {
|
|
30
|
+
if (coroutineScopeDelegate.isInitialized()) {
|
|
31
|
+
coroutineScope.cancel(ModuleDestroyedException())
|
|
32
|
+
}
|
|
33
|
+
}
|
|
19
34
|
}
|
|
20
35
|
|
|
21
36
|
@Suppress("FunctionName")
|
|
22
|
-
inline fun ModuleDefinition(block: ModuleDefinitionBuilder.() -> Unit): ModuleDefinitionData {
|
|
23
|
-
return ModuleDefinitionBuilder().also(block).build()
|
|
37
|
+
inline fun Module.ModuleDefinition(block: ModuleDefinitionBuilder.() -> Unit): ModuleDefinitionData {
|
|
38
|
+
return ModuleDefinitionBuilder(this).also(block).build()
|
|
24
39
|
}
|
|
@@ -23,21 +23,24 @@ import expo.modules.kotlin.events.EventListenerWithSenderAndPayload
|
|
|
23
23
|
import expo.modules.kotlin.events.EventName
|
|
24
24
|
import expo.modules.kotlin.events.EventsDefinition
|
|
25
25
|
import expo.modules.kotlin.events.OnActivityResultPayload
|
|
26
|
-
import expo.modules.kotlin.
|
|
27
|
-
import expo.modules.kotlin.
|
|
28
|
-
import expo.modules.kotlin.
|
|
26
|
+
import expo.modules.kotlin.functions.AnyFunction
|
|
27
|
+
import expo.modules.kotlin.functions.AsyncFunction
|
|
28
|
+
import expo.modules.kotlin.functions.AsyncFunctionWithPromise
|
|
29
|
+
import expo.modules.kotlin.functions.AsyncFunctionBuilder
|
|
29
30
|
import expo.modules.kotlin.types.toAnyType
|
|
30
31
|
import expo.modules.kotlin.views.ViewManagerDefinition
|
|
31
32
|
import expo.modules.kotlin.views.ViewManagerDefinitionBuilder
|
|
32
33
|
import kotlin.reflect.typeOf
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
@DefinitionMarker
|
|
36
|
+
class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null) {
|
|
35
37
|
private var name: String? = null
|
|
36
38
|
private var constantsProvider = { emptyMap<String, Any?>() }
|
|
37
39
|
private var eventsDefinition: EventsDefinition? = null
|
|
40
|
+
private var functionBuilders = mutableListOf<AsyncFunctionBuilder>()
|
|
38
41
|
|
|
39
42
|
@PublishedApi
|
|
40
|
-
internal var methods = mutableMapOf<String,
|
|
43
|
+
internal var methods = mutableMapOf<String, AnyFunction>()
|
|
41
44
|
|
|
42
45
|
@PublishedApi
|
|
43
46
|
internal var viewManagerDefinition: ViewManagerDefinition? = null
|
|
@@ -46,127 +49,292 @@ class ModuleDefinitionBuilder {
|
|
|
46
49
|
internal val eventListeners = mutableMapOf<EventName, EventListener>()
|
|
47
50
|
|
|
48
51
|
fun build(): ModuleDefinitionData {
|
|
52
|
+
val moduleName = name ?: module?.javaClass?.simpleName
|
|
53
|
+
|
|
49
54
|
return ModuleDefinitionData(
|
|
50
|
-
requireNotNull(
|
|
55
|
+
requireNotNull(moduleName),
|
|
51
56
|
constantsProvider,
|
|
52
|
-
methods,
|
|
57
|
+
methods + functionBuilders.associate { it.build() },
|
|
53
58
|
viewManagerDefinition,
|
|
54
59
|
eventListeners,
|
|
55
60
|
eventsDefinition
|
|
56
61
|
)
|
|
57
62
|
}
|
|
58
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Sets the name of the module that is exported to the JavaScript world.
|
|
66
|
+
*/
|
|
59
67
|
fun name(name: String) {
|
|
60
68
|
this.name = name
|
|
61
69
|
}
|
|
62
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Definition function setting the module's constants to export.
|
|
73
|
+
*/
|
|
63
74
|
fun constants(constantsProvider: () -> Map<String, Any?>) {
|
|
64
75
|
this.constantsProvider = constantsProvider
|
|
65
76
|
}
|
|
66
77
|
|
|
67
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Definition of the module's constants to export.
|
|
80
|
+
*/
|
|
81
|
+
fun constants(vararg constants: Pair<String, Any?>) {
|
|
82
|
+
constantsProvider = { constants.toMap() }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Deprecated(
|
|
86
|
+
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
87
|
+
replaceWith = ReplaceWith("asyncFunction(name, body)")
|
|
88
|
+
)
|
|
89
|
+
@JvmName("functionWithoutArgs")
|
|
68
90
|
inline fun function(
|
|
69
91
|
name: String,
|
|
70
92
|
crossinline body: () -> Any?
|
|
71
93
|
) {
|
|
72
|
-
methods[name] =
|
|
94
|
+
methods[name] = AsyncFunction(name, arrayOf()) { body() }
|
|
73
95
|
}
|
|
74
96
|
|
|
97
|
+
@Deprecated(
|
|
98
|
+
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
99
|
+
replaceWith = ReplaceWith("asyncFunction(name, body)")
|
|
100
|
+
)
|
|
75
101
|
inline fun <reified R> function(
|
|
76
102
|
name: String,
|
|
77
103
|
crossinline body: () -> R
|
|
78
104
|
) {
|
|
79
|
-
methods[name] =
|
|
105
|
+
methods[name] = AsyncFunction(name, arrayOf()) { body() }
|
|
80
106
|
}
|
|
81
107
|
|
|
108
|
+
@Deprecated(
|
|
109
|
+
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
110
|
+
replaceWith = ReplaceWith("asyncFunction(name, body)")
|
|
111
|
+
)
|
|
82
112
|
inline fun <reified R, reified P0> function(
|
|
83
113
|
name: String,
|
|
84
114
|
crossinline body: (p0: P0) -> R
|
|
85
115
|
) {
|
|
86
116
|
methods[name] = if (P0::class == Promise::class) {
|
|
87
|
-
|
|
117
|
+
AsyncFunctionWithPromise(name, arrayOf()) { _, promise -> body(promise as P0) }
|
|
88
118
|
} else {
|
|
89
|
-
|
|
119
|
+
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }
|
|
90
120
|
}
|
|
91
121
|
}
|
|
92
122
|
|
|
123
|
+
@Deprecated(
|
|
124
|
+
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
125
|
+
replaceWith = ReplaceWith("asyncFunction(name, body)")
|
|
126
|
+
)
|
|
93
127
|
inline fun <reified R, reified P0, reified P1> function(
|
|
94
128
|
name: String,
|
|
95
129
|
crossinline body: (p0: P0, p1: P1) -> R
|
|
96
130
|
) {
|
|
97
131
|
methods[name] = if (P1::class == Promise::class) {
|
|
98
|
-
|
|
132
|
+
AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType())) { args, promise -> body(args[0] as P0, promise as P1) }
|
|
99
133
|
} else {
|
|
100
|
-
|
|
134
|
+
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }
|
|
101
135
|
}
|
|
102
136
|
}
|
|
103
137
|
|
|
138
|
+
@Deprecated(
|
|
139
|
+
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
140
|
+
replaceWith = ReplaceWith("asyncFunction(name, body)")
|
|
141
|
+
)
|
|
104
142
|
inline fun <reified R, reified P0, reified P1, reified P2> function(
|
|
105
143
|
name: String,
|
|
106
144
|
crossinline body: (p0: P0, p1: P1, p2: P2) -> R
|
|
107
145
|
) {
|
|
108
146
|
methods[name] = if (P2::class == Promise::class) {
|
|
109
|
-
|
|
147
|
+
AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, promise as P2) }
|
|
110
148
|
} else {
|
|
111
|
-
|
|
149
|
+
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) }
|
|
112
150
|
}
|
|
113
151
|
}
|
|
114
152
|
|
|
153
|
+
@Deprecated(
|
|
154
|
+
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
155
|
+
replaceWith = ReplaceWith("asyncFunction(name, body)")
|
|
156
|
+
)
|
|
115
157
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3> function(
|
|
116
158
|
name: String,
|
|
117
159
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
|
|
118
160
|
) {
|
|
119
161
|
methods[name] = if (P3::class == Promise::class) {
|
|
120
|
-
|
|
162
|
+
AsyncFunctionWithPromise(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) }
|
|
121
163
|
} else {
|
|
122
|
-
|
|
164
|
+
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) }
|
|
123
165
|
}
|
|
124
166
|
}
|
|
125
167
|
|
|
168
|
+
@Deprecated(
|
|
169
|
+
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
170
|
+
replaceWith = ReplaceWith("asyncFunction(name, body)")
|
|
171
|
+
)
|
|
126
172
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> function(
|
|
127
173
|
name: String,
|
|
128
174
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
|
|
129
175
|
) {
|
|
130
176
|
methods[name] = if (P4::class == Promise::class) {
|
|
131
|
-
|
|
177
|
+
AsyncFunctionWithPromise(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) }
|
|
132
178
|
} else {
|
|
133
|
-
|
|
179
|
+
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) }
|
|
134
180
|
}
|
|
135
181
|
}
|
|
136
182
|
|
|
183
|
+
@Deprecated(
|
|
184
|
+
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
185
|
+
replaceWith = ReplaceWith("asyncFunction(name, body)")
|
|
186
|
+
)
|
|
137
187
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> function(
|
|
138
188
|
name: String,
|
|
139
189
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
|
|
140
190
|
) {
|
|
141
191
|
methods[name] = if (P5::class == Promise::class) {
|
|
142
|
-
|
|
192
|
+
AsyncFunctionWithPromise(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) }
|
|
143
193
|
} else {
|
|
144
|
-
|
|
194
|
+
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) }
|
|
145
195
|
}
|
|
146
196
|
}
|
|
147
197
|
|
|
198
|
+
@Deprecated(
|
|
199
|
+
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
200
|
+
replaceWith = ReplaceWith("asyncFunction(name, body)")
|
|
201
|
+
)
|
|
148
202
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> function(
|
|
149
203
|
name: String,
|
|
150
204
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
|
|
151
205
|
) {
|
|
152
206
|
methods[name] = if (P6::class == Promise::class) {
|
|
153
|
-
|
|
207
|
+
AsyncFunctionWithPromise(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) }
|
|
154
208
|
} else {
|
|
155
|
-
|
|
209
|
+
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) }
|
|
156
210
|
}
|
|
157
211
|
}
|
|
158
212
|
|
|
213
|
+
@Deprecated(
|
|
214
|
+
message = "The 'function' component was deprecated and will change its behavior in the future.",
|
|
215
|
+
replaceWith = ReplaceWith("asyncFunction(name, body)")
|
|
216
|
+
)
|
|
159
217
|
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> function(
|
|
160
218
|
name: String,
|
|
161
219
|
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
|
|
162
220
|
) {
|
|
163
221
|
methods[name] = if (P7::class == Promise::class) {
|
|
164
|
-
|
|
222
|
+
AsyncFunctionWithPromise(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) }
|
|
223
|
+
} else {
|
|
224
|
+
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) }
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
@JvmName("asyncFunctionWithoutArgs")
|
|
229
|
+
inline fun asyncFunction(
|
|
230
|
+
name: String,
|
|
231
|
+
crossinline body: () -> Any?
|
|
232
|
+
) {
|
|
233
|
+
methods[name] = AsyncFunction(name, arrayOf()) { body() }
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
inline fun <reified R> asyncFunction(
|
|
237
|
+
name: String,
|
|
238
|
+
crossinline body: () -> R
|
|
239
|
+
) {
|
|
240
|
+
methods[name] = AsyncFunction(name, arrayOf()) { body() }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
inline fun <reified R, reified P0> asyncFunction(
|
|
244
|
+
name: String,
|
|
245
|
+
crossinline body: (p0: P0) -> R
|
|
246
|
+
) {
|
|
247
|
+
methods[name] = if (P0::class == Promise::class) {
|
|
248
|
+
AsyncFunctionWithPromise(name, arrayOf()) { _, promise -> body(promise as P0) }
|
|
249
|
+
} else {
|
|
250
|
+
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
inline fun <reified R, reified P0, reified P1> asyncFunction(
|
|
255
|
+
name: String,
|
|
256
|
+
crossinline body: (p0: P0, p1: P1) -> R
|
|
257
|
+
) {
|
|
258
|
+
methods[name] = if (P1::class == Promise::class) {
|
|
259
|
+
AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType())) { args, promise -> body(args[0] as P0, promise as P1) }
|
|
260
|
+
} else {
|
|
261
|
+
AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
inline fun <reified R, reified P0, reified P1, reified P2> asyncFunction(
|
|
266
|
+
name: String,
|
|
267
|
+
crossinline body: (p0: P0, p1: P1, p2: P2) -> R
|
|
268
|
+
) {
|
|
269
|
+
methods[name] = if (P2::class == Promise::class) {
|
|
270
|
+
AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, promise as P2) }
|
|
271
|
+
} else {
|
|
272
|
+
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) }
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
inline fun <reified R, reified P0, reified P1, reified P2, reified P3> asyncFunction(
|
|
277
|
+
name: String,
|
|
278
|
+
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
|
|
279
|
+
) {
|
|
280
|
+
methods[name] = if (P3::class == Promise::class) {
|
|
281
|
+
AsyncFunctionWithPromise(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) }
|
|
282
|
+
} else {
|
|
283
|
+
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) }
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> asyncFunction(
|
|
288
|
+
name: String,
|
|
289
|
+
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
|
|
290
|
+
) {
|
|
291
|
+
methods[name] = if (P4::class == Promise::class) {
|
|
292
|
+
AsyncFunctionWithPromise(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) }
|
|
293
|
+
} else {
|
|
294
|
+
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) }
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> asyncFunction(
|
|
299
|
+
name: String,
|
|
300
|
+
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
|
|
301
|
+
) {
|
|
302
|
+
methods[name] = if (P5::class == Promise::class) {
|
|
303
|
+
AsyncFunctionWithPromise(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) }
|
|
304
|
+
} else {
|
|
305
|
+
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) }
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> asyncFunction(
|
|
310
|
+
name: String,
|
|
311
|
+
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
|
|
312
|
+
) {
|
|
313
|
+
methods[name] = if (P6::class == Promise::class) {
|
|
314
|
+
AsyncFunctionWithPromise(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) }
|
|
315
|
+
} else {
|
|
316
|
+
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) }
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> asyncFunction(
|
|
321
|
+
name: String,
|
|
322
|
+
crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
|
|
323
|
+
) {
|
|
324
|
+
methods[name] = if (P7::class == Promise::class) {
|
|
325
|
+
AsyncFunctionWithPromise(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) }
|
|
165
326
|
} else {
|
|
166
|
-
|
|
327
|
+
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) }
|
|
167
328
|
}
|
|
168
329
|
}
|
|
169
330
|
|
|
331
|
+
fun asyncFunction(
|
|
332
|
+
name: String
|
|
333
|
+
) = AsyncFunctionBuilder(name).also { functionBuilders.add(it) }
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Creates the view manager definition that scopes other view-related definitions.
|
|
337
|
+
*/
|
|
170
338
|
inline fun viewManager(body: ViewManagerDefinitionBuilder.() -> Unit) {
|
|
171
339
|
require(viewManagerDefinition == null) { "The module definition may have exported only one view manager." }
|
|
172
340
|
|
|
@@ -175,22 +343,37 @@ class ModuleDefinitionBuilder {
|
|
|
175
343
|
viewManagerDefinition = viewManagerDefinitionBuilder.build()
|
|
176
344
|
}
|
|
177
345
|
|
|
346
|
+
/**
|
|
347
|
+
* Creates module's lifecycle listener that is called right after the module initialization.
|
|
348
|
+
*/
|
|
178
349
|
inline fun onCreate(crossinline body: () -> Unit) {
|
|
179
350
|
eventListeners[EventName.MODULE_CREATE] = BasicEventListener(EventName.MODULE_CREATE) { body() }
|
|
180
351
|
}
|
|
181
352
|
|
|
353
|
+
/**
|
|
354
|
+
* Creates module's lifecycle listener that is called when the module is about to be deallocated.
|
|
355
|
+
*/
|
|
182
356
|
inline fun onDestroy(crossinline body: () -> Unit) {
|
|
183
357
|
eventListeners[EventName.MODULE_DESTROY] = BasicEventListener(EventName.MODULE_DESTROY) { body() }
|
|
184
358
|
}
|
|
185
359
|
|
|
360
|
+
/**
|
|
361
|
+
* Creates module's lifecycle listener that is called right after the activity is resumed.
|
|
362
|
+
*/
|
|
186
363
|
inline fun onActivityEntersForeground(crossinline body: () -> Unit) {
|
|
187
364
|
eventListeners[EventName.ACTIVITY_ENTERS_FOREGROUND] = BasicEventListener(EventName.ACTIVITY_ENTERS_FOREGROUND) { body() }
|
|
188
365
|
}
|
|
189
366
|
|
|
367
|
+
/**
|
|
368
|
+
* Creates module's lifecycle listener that is called right after the activity is paused.
|
|
369
|
+
*/
|
|
190
370
|
inline fun onActivityEntersBackground(crossinline body: () -> Unit) {
|
|
191
371
|
eventListeners[EventName.ACTIVITY_ENTERS_BACKGROUND] = BasicEventListener(EventName.ACTIVITY_ENTERS_BACKGROUND) { body() }
|
|
192
372
|
}
|
|
193
373
|
|
|
374
|
+
/**
|
|
375
|
+
* Creates module's lifecycle listener that is called right after the activity is destroyed.
|
|
376
|
+
*/
|
|
194
377
|
inline fun onActivityDestroys(crossinline body: () -> Unit) {
|
|
195
378
|
eventListeners[EventName.ACTIVITY_DESTROYS] = BasicEventListener(EventName.ACTIVITY_DESTROYS) { body() }
|
|
196
379
|
}
|
|
@@ -203,23 +386,29 @@ class ModuleDefinitionBuilder {
|
|
|
203
386
|
}
|
|
204
387
|
|
|
205
388
|
/**
|
|
206
|
-
*
|
|
389
|
+
* Creates module's lifecycle listener that is called right after the first event listener is added.
|
|
207
390
|
*/
|
|
208
391
|
inline fun onStartObserving(crossinline body: () -> Unit) {
|
|
209
|
-
|
|
392
|
+
asyncFunction("startObserving", body)
|
|
210
393
|
}
|
|
211
394
|
|
|
212
395
|
/**
|
|
213
|
-
*
|
|
396
|
+
* Creates module's lifecycle listener that is called right after all event listeners are removed.
|
|
214
397
|
*/
|
|
215
398
|
inline fun onStopObserving(crossinline body: () -> Unit) {
|
|
216
|
-
|
|
399
|
+
asyncFunction("stopObserving", body)
|
|
217
400
|
}
|
|
218
401
|
|
|
402
|
+
/**
|
|
403
|
+
* Creates module's lifecycle listener that is called right after the new intent was received.
|
|
404
|
+
*/
|
|
219
405
|
inline fun onNewIntent(crossinline body: (Intent) -> Unit) {
|
|
220
406
|
eventListeners[EventName.ON_NEW_INTENT] = EventListenerWithPayload<Intent>(EventName.ON_NEW_INTENT) { body(it) }
|
|
221
407
|
}
|
|
222
408
|
|
|
409
|
+
/**
|
|
410
|
+
* Creates module's lifecycle listener that is called right after the activity has received a result.
|
|
411
|
+
*/
|
|
223
412
|
inline fun onActivityResult(crossinline body: (Activity, OnActivityResultPayload) -> Unit) {
|
|
224
413
|
eventListeners[EventName.ON_ACTIVITY_RESULT] =
|
|
225
414
|
EventListenerWithSenderAndPayload<Activity, OnActivityResultPayload>(EventName.ON_ACTIVITY_RESULT) { sender, payload -> body(sender, payload) }
|
|
@@ -3,13 +3,13 @@ package expo.modules.kotlin.modules
|
|
|
3
3
|
import expo.modules.kotlin.events.EventListener
|
|
4
4
|
import expo.modules.kotlin.events.EventName
|
|
5
5
|
import expo.modules.kotlin.events.EventsDefinition
|
|
6
|
-
import expo.modules.kotlin.
|
|
6
|
+
import expo.modules.kotlin.functions.AnyFunction
|
|
7
7
|
import expo.modules.kotlin.views.ViewManagerDefinition
|
|
8
8
|
|
|
9
9
|
class ModuleDefinitionData(
|
|
10
10
|
val name: String,
|
|
11
11
|
val constantsProvider: () -> Map<String, Any?>,
|
|
12
|
-
val methods: Map<String,
|
|
12
|
+
val methods: Map<String, AnyFunction>,
|
|
13
13
|
val viewManagerDefinition: ViewManagerDefinition? = null,
|
|
14
14
|
val eventListeners: Map<EventName, EventListener> = emptyMap(),
|
|
15
15
|
val eventsDefinition: EventsDefinition? = null
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
package expo.modules.kotlin.records
|
|
2
|
+
|
|
3
|
+
import expo.modules.kotlin.exception.ValidationException
|
|
4
|
+
|
|
5
|
+
interface FieldValidator<T> {
|
|
6
|
+
fun validate(value: T)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class NumericRangeValidator<T : Comparable<T>>(
|
|
10
|
+
private val from: T,
|
|
11
|
+
private val to: T,
|
|
12
|
+
private val fromInclusive: Boolean,
|
|
13
|
+
private val toInclusive: Boolean
|
|
14
|
+
) : FieldValidator<T> {
|
|
15
|
+
override fun validate(value: T) {
|
|
16
|
+
if (
|
|
17
|
+
value < from ||
|
|
18
|
+
to < value ||
|
|
19
|
+
value == from && !fromInclusive ||
|
|
20
|
+
value == to && !toInclusive
|
|
21
|
+
) {
|
|
22
|
+
throw ValidationException("Value should be in range $from ${if (fromInclusive) "<=" else "<"} 'value' ${if (toInclusive) "<=" else "<"} $to, got $value")
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class IsNotEmptyCollectionValidator : FieldValidator<Collection<*>> {
|
|
28
|
+
override fun validate(value: Collection<*>) {
|
|
29
|
+
if (value.isEmpty()) {
|
|
30
|
+
throw ValidationException("Collection is empty")
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class IsNotEmptyIntArrayValidator : FieldValidator<IntArray> {
|
|
36
|
+
override fun validate(value: IntArray) {
|
|
37
|
+
if (value.isEmpty()) {
|
|
38
|
+
throw ValidationException("Array is empty")
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class IsNotEmptyFloatArrayValidator : FieldValidator<FloatArray> {
|
|
44
|
+
override fun validate(value: FloatArray) {
|
|
45
|
+
if (value.isEmpty()) {
|
|
46
|
+
throw ValidationException("Array is empty")
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class IsNotEmptyDoubleArrayValidator : FieldValidator<DoubleArray> {
|
|
52
|
+
override fun validate(value: DoubleArray) {
|
|
53
|
+
if (value.isEmpty()) {
|
|
54
|
+
throw ValidationException("Array is empty")
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class IsNotEmptyArrayValidator : FieldValidator<Array<*>> {
|
|
60
|
+
override fun validate(value: Array<*>) {
|
|
61
|
+
if (value.isEmpty()) {
|
|
62
|
+
throw ValidationException("Array is empty")
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
class CollectionSizeValidator(
|
|
68
|
+
private val min: Int,
|
|
69
|
+
private val max: Int
|
|
70
|
+
) : FieldValidator<Collection<*>> {
|
|
71
|
+
override fun validate(value: Collection<*>) {
|
|
72
|
+
if (value.size < min || value.size > max) {
|
|
73
|
+
throw ValidationException("Number of elements in the collection should be between $min and $max, got ${value.size}")
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
class IntArraySizeValidator(
|
|
79
|
+
private val min: Int,
|
|
80
|
+
private val max: Int
|
|
81
|
+
) : FieldValidator<IntArray> {
|
|
82
|
+
override fun validate(value: IntArray) {
|
|
83
|
+
if (value.size < min || value.size > max) {
|
|
84
|
+
throw ValidationException("Number of elements in the array should be between $min and $max, got ${value.size}")
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
class DoubleArraySizeValidator(
|
|
90
|
+
private val min: Int,
|
|
91
|
+
private val max: Int
|
|
92
|
+
) : FieldValidator<DoubleArray> {
|
|
93
|
+
override fun validate(value: DoubleArray) {
|
|
94
|
+
if (value.size < min || value.size > max) {
|
|
95
|
+
throw ValidationException("Number of elements in the array should be between $min and $max, got ${value.size}")
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
class FloatArraySizeValidator(
|
|
101
|
+
private val min: Int,
|
|
102
|
+
private val max: Int
|
|
103
|
+
) : FieldValidator<FloatArray> {
|
|
104
|
+
override fun validate(value: FloatArray) {
|
|
105
|
+
if (value.size < min || value.size > max) {
|
|
106
|
+
throw ValidationException("Number of elements in the array should be between $min and $max, got ${value.size}")
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
class ArraySizeValidator(
|
|
112
|
+
private val min: Int,
|
|
113
|
+
private val max: Int
|
|
114
|
+
) : FieldValidator<Array<*>> {
|
|
115
|
+
override fun validate(value: Array<*>) {
|
|
116
|
+
if (value.size < min || value.size > max) {
|
|
117
|
+
throw ValidationException("Number of elements in the array should be between $min and $max, got ${value.size}")
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
class StringSizeValidator(
|
|
123
|
+
private val min: Int,
|
|
124
|
+
private val max: Int
|
|
125
|
+
) : FieldValidator<String> {
|
|
126
|
+
override fun validate(value: String) {
|
|
127
|
+
if (value.length < min || value.length > max) {
|
|
128
|
+
throw ValidationException("Length of the string should be between $min and $max, got $value (${value.length} characters)")
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
class RegexValidator(private val regex: Regex) : FieldValidator<CharSequence> {
|
|
134
|
+
override fun validate(value: CharSequence) {
|
|
135
|
+
if (!regex.matches(value)) {
|
|
136
|
+
throw ValidationException("Provided string $value didn't match regex $regex")
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|