expo-modules-core 0.10.0 → 0.11.2

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +3 -3
  3. package/android/CMakeLists.txt +14 -5
  4. package/android/build.gradle +78 -28
  5. package/android/src/main/cpp/CachedReferencesRegistry.cpp +67 -0
  6. package/android/src/main/cpp/CachedReferencesRegistry.h +80 -0
  7. package/android/src/main/cpp/JNIFunctionBody.cpp +28 -12
  8. package/android/src/main/cpp/JNIFunctionBody.h +2 -2
  9. package/android/src/main/cpp/JNIInjector.cpp +4 -0
  10. package/android/src/main/cpp/JavaScriptModuleObject.cpp +86 -5
  11. package/android/src/main/cpp/JavaScriptModuleObject.h +27 -5
  12. package/android/src/main/cpp/JavaScriptRuntime.cpp +10 -12
  13. package/android/src/main/cpp/MethodMetadata.cpp +181 -40
  14. package/android/src/main/cpp/MethodMetadata.h +43 -3
  15. package/android/src/main/java/expo/modules/kotlin/AppContext.kt +63 -10
  16. package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +6 -0
  17. package/android/src/main/java/expo/modules/kotlin/activityaware/AppCompatActivityAware.kt +49 -0
  18. package/android/src/main/java/expo/modules/kotlin/activityaware/AppCompatActivityAwareHelper.kt +43 -0
  19. package/android/src/main/java/expo/modules/kotlin/activityaware/OnActivityAvailableListener.kt +18 -0
  20. package/android/src/main/java/expo/modules/kotlin/activityresult/ActivityResultsManager.kt +99 -0
  21. package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultCaller.kt +25 -0
  22. package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultContract.kt +27 -0
  23. package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultFallbackCallback.kt +17 -0
  24. package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultLauncher.kt +30 -0
  25. package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultRegistry.kt +358 -0
  26. package/android/src/main/java/expo/modules/kotlin/activityresult/DataPersistor.kt +135 -0
  27. package/android/src/main/java/expo/modules/kotlin/functions/AnyFunction.kt +34 -1
  28. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +7 -1
  29. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +0 -108
  30. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionComponent.kt +5 -2
  31. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromiseComponent.kt +5 -2
  32. package/android/src/main/java/expo/modules/kotlin/functions/SuspendFunctionComponent.kt +9 -2
  33. package/android/src/main/java/expo/modules/kotlin/functions/SyncFunctionComponent.kt +9 -1
  34. package/android/src/main/java/expo/modules/kotlin/jni/CppType.kt +1 -0
  35. package/android/src/main/java/expo/modules/kotlin/jni/JNIFunctionBody.kt +2 -2
  36. package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptModuleObject.kt +4 -2
  37. package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +1 -1
  38. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +5 -454
  39. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionData.kt +7 -15
  40. package/android/src/main/java/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +271 -0
  41. package/android/src/main/java/expo/modules/kotlin/objects/ObjectDefinitionData.kt +21 -0
  42. package/android/src/main/java/expo/modules/kotlin/objects/PropertyComponent.kt +54 -0
  43. package/android/src/main/java/expo/modules/kotlin/objects/PropertyComponentBuilder.kt +32 -0
  44. package/android/src/main/java/expo/modules/kotlin/types/AnyTypeConverter.kt +36 -0
  45. package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +7 -0
  46. package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinitionBuilder.kt +0 -41
  47. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +0 -33
  48. package/build/PermissionsInterface.d.ts +29 -0
  49. package/build/PermissionsInterface.d.ts.map +1 -1
  50. package/build/PermissionsInterface.js +9 -0
  51. package/build/PermissionsInterface.js.map +1 -1
  52. package/ios/ExpoModulesCore.podspec +2 -1
  53. package/ios/JSI/EXJSIInstaller.mm +2 -0
  54. package/ios/JSI/EXJSIUtils.h +1 -0
  55. package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +4 -3
  56. package/ios/Swift/AppContext.swift +2 -4
  57. package/ios/Swift/Classes/ClassComponentElementsBuilder.swift +2 -2
  58. package/ios/Swift/Exceptions/ChainableException.swift +3 -3
  59. package/ios/Swift/ExpoBridgeModule.swift +16 -2
  60. package/ios/Swift/Logging/Logger.swift +3 -0
  61. package/ios/Swift/Promise.swift +5 -1
  62. package/package.json +2 -2
  63. package/src/PermissionsInterface.ts +29 -0
@@ -1,51 +1,22 @@
1
- /**
2
- * We used a function from the experimental STD API - typeOf (see kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/type-of.html).
3
- * We shouldn't have any problem with that function, cause it's widely used in other libraries created by JetBrains like kotlinx-serializer.
4
- * This function is super handy if we want to receive a collection type.
5
- * For example, it's very hard to obtain the generic parameter type from the list class.
6
- * In plain Java, it's almost impossible. There is a trick to getting such information using something called TypeToken.
7
- * For instance, the Gson library uses this workaround. But there still will be a problem with nullability.
8
- * We didn't find a good solution to distinguish between List<Any?> and List<Any>.
9
- * Mainly because from the JVM perspective it's the same type.
10
- * That's why we used typeOf. It solves all problems described above.
11
- */
12
- @file:OptIn(ExperimentalStdlibApi::class)
13
1
  @file:Suppress("FunctionName")
14
2
 
15
3
  package expo.modules.kotlin.modules
16
4
 
17
5
  import android.app.Activity
18
6
  import android.content.Intent
19
- import expo.modules.kotlin.Promise
20
7
  import expo.modules.kotlin.events.BasicEventListener
21
8
  import expo.modules.kotlin.events.EventListener
22
9
  import expo.modules.kotlin.events.EventListenerWithPayload
23
10
  import expo.modules.kotlin.events.EventListenerWithSenderAndPayload
24
11
  import expo.modules.kotlin.events.EventName
25
- import expo.modules.kotlin.events.EventsDefinition
26
12
  import expo.modules.kotlin.events.OnActivityResultPayload
27
- import expo.modules.kotlin.functions.AsyncFunction
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
32
- import expo.modules.kotlin.types.toAnyType
13
+ import expo.modules.kotlin.objects.ObjectDefinitionBuilder
33
14
  import expo.modules.kotlin.views.ViewManagerDefinition
34
15
  import expo.modules.kotlin.views.ViewManagerDefinitionBuilder
35
- import kotlin.reflect.typeOf
36
16
 
37
17
  @DefinitionMarker
38
- class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null) {
18
+ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null) : ObjectDefinitionBuilder() {
39
19
  private var name: String? = null
40
- private var constantsProvider = { emptyMap<String, Any?>() }
41
- private var eventsDefinition: EventsDefinition? = null
42
- private var functionBuilders = mutableListOf<AsyncFunctionBuilder>()
43
-
44
- @PublishedApi
45
- internal var syncFunctions = mutableMapOf<String, SyncFunctionComponent>()
46
-
47
- @PublishedApi
48
- internal var asyncFunctions = mutableMapOf<String, AsyncFunction>()
49
20
 
50
21
  @PublishedApi
51
22
  internal var viewManagerDefinition: ViewManagerDefinition? = null
@@ -53,27 +24,17 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
53
24
  @PublishedApi
54
25
  internal val eventListeners = mutableMapOf<EventName, EventListener>()
55
26
 
56
- fun build(): ModuleDefinitionData {
27
+ fun buildModule(): ModuleDefinitionData {
57
28
  val moduleName = name ?: module?.javaClass?.simpleName
58
29
 
59
30
  return ModuleDefinitionData(
60
31
  requireNotNull(moduleName),
61
- constantsProvider,
62
- syncFunctions,
63
- asyncFunctions,
64
- functionBuilders.map { it.build() },
32
+ buildObject(),
65
33
  viewManagerDefinition,
66
- eventListeners,
67
- eventsDefinition
34
+ eventListeners
68
35
  )
69
36
  }
70
37
 
71
- @Deprecated(
72
- message = "The 'name' component was renamed to 'Name'.",
73
- replaceWith = ReplaceWith("Name(name)")
74
- )
75
- fun name(name: String) = Name(name)
76
-
77
38
  /**
78
39
  * Sets the name of the module that is exported to the JavaScript world.
79
40
  */
@@ -81,335 +42,6 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
81
42
  this.name = name
82
43
  }
83
44
 
84
- @Deprecated(
85
- message = "The 'constants' component was renamed to 'Constants'.",
86
- replaceWith = ReplaceWith("Constants(constantsProvider)")
87
- )
88
- fun constants(constantsProvider: () -> Map<String, Any?>) = Constants(constantsProvider)
89
-
90
- /**
91
- * Definition function setting the module's constants to export.
92
- */
93
- fun Constants(constantsProvider: () -> Map<String, Any?>) {
94
- this.constantsProvider = constantsProvider
95
- }
96
-
97
- @Deprecated(
98
- message = "The 'constants' component was renamed to 'Constants'.",
99
- replaceWith = ReplaceWith("Constants(constants)")
100
- )
101
- fun constants(vararg constants: Pair<String, Any?>) = Constants(*constants)
102
-
103
- /**
104
- * Definition of the module's constants to export.
105
- */
106
- fun Constants(vararg constants: Pair<String, Any?>) {
107
- constantsProvider = { constants.toMap() }
108
- }
109
-
110
- @JvmName("FunctionWithoutArgs")
111
- inline fun Function(
112
- name: String,
113
- crossinline body: () -> Any?
114
- ) {
115
- SyncFunctionComponent(name, arrayOf()) { body() }.also {
116
- syncFunctions[name] = it
117
- }
118
- }
119
-
120
- inline fun <reified R> Function(
121
- name: String,
122
- crossinline body: () -> R
123
- ) {
124
- SyncFunctionComponent(name, arrayOf()) { body() }.also {
125
- syncFunctions[name] = it
126
- }
127
- }
128
-
129
- inline fun <reified R, reified P0> Function(
130
- name: String,
131
- crossinline body: (p0: P0) -> R
132
- ) {
133
- SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }.also {
134
- syncFunctions[name] = it
135
- }
136
- }
137
-
138
- inline fun <reified R, reified P0, reified P1> Function(
139
- name: String,
140
- crossinline body: (p0: P0, p1: P1) -> R
141
- ) {
142
- SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }.also {
143
- syncFunctions[name] = it
144
- }
145
- }
146
-
147
- inline fun <reified R, reified P0, reified P1, reified P2> Function(
148
- name: String,
149
- crossinline body: (p0: P0, p1: P1, p2: P2) -> R
150
- ) {
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
153
- }
154
- }
155
-
156
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3> function(
157
- name: String,
158
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
159
- ) {
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
162
- }
163
- }
164
-
165
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> function(
166
- name: String,
167
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
168
- ) {
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
171
- }
172
- }
173
-
174
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> Function(
175
- name: String,
176
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
177
- ) {
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
180
- }
181
- }
182
-
183
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> function(
184
- name: String,
185
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
186
- ) {
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
189
- }
190
- }
191
-
192
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> function(
193
- name: String,
194
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
195
- ) {
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
198
- }
199
- }
200
-
201
- @Deprecated(
202
- message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
203
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
204
- )
205
- @JvmName("asyncFunctionWithoutArgs")
206
- inline fun asyncFunction(
207
- name: String,
208
- crossinline body: () -> Any?
209
- ) = AsyncFunction(name, body)
210
-
211
- @JvmName("AsyncFunctionWithoutArgs")
212
- inline fun AsyncFunction(
213
- name: String,
214
- crossinline body: () -> Any?
215
- ) {
216
- asyncFunctions[name] = AsyncFunctionComponent(name, arrayOf()) { body() }
217
- }
218
-
219
- @Deprecated(
220
- message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
221
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
222
- )
223
- inline fun <reified R> asyncFunction(
224
- name: String,
225
- crossinline body: () -> R
226
- ) = AsyncFunction(name, body)
227
-
228
- inline fun <reified R> AsyncFunction(
229
- name: String,
230
- crossinline body: () -> R
231
- ) {
232
- asyncFunctions[name] = AsyncFunctionComponent(name, arrayOf()) { body() }
233
- }
234
-
235
- @Deprecated(
236
- message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
237
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
238
- )
239
- inline fun <reified R, reified P0> asyncFunction(
240
- name: String,
241
- crossinline body: (p0: P0) -> R
242
- ) = AsyncFunction(name, body)
243
-
244
- inline fun <reified R, reified P0> AsyncFunction(
245
- name: String,
246
- crossinline body: (p0: P0) -> R
247
- ) {
248
- asyncFunctions[name] = if (P0::class == Promise::class) {
249
- AsyncFunctionWithPromiseComponent(name, arrayOf()) { _, promise -> body(promise as P0) }
250
- } else {
251
- AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }
252
- }
253
- }
254
-
255
- @Deprecated(
256
- message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
257
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
258
- )
259
- inline fun <reified R, reified P0, reified P1> asyncFunction(
260
- name: String,
261
- crossinline body: (p0: P0, p1: P1) -> R
262
- ) = AsyncFunction(name, body)
263
-
264
- inline fun <reified R, reified P0, reified P1> AsyncFunction(
265
- name: String,
266
- crossinline body: (p0: P0, p1: P1) -> R
267
- ) {
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) }
270
- } else {
271
- AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }
272
- }
273
- }
274
-
275
- @Deprecated(
276
- message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
277
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
278
- )
279
- inline fun <reified R, reified P0, reified P1, reified P2> asyncFunction(
280
- name: String,
281
- crossinline body: (p0: P0, p1: P1, p2: P2) -> R
282
- ) = AsyncFunction(name, body)
283
-
284
- inline fun <reified R, reified P0, reified P1, reified P2> AsyncFunction(
285
- name: String,
286
- crossinline body: (p0: P0, p1: P1, p2: P2) -> R
287
- ) {
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) }
290
- } else {
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) }
292
- }
293
- }
294
-
295
- @Deprecated(
296
- message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
297
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
298
- )
299
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3> asyncFunction(
300
- name: String,
301
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
302
- ) = AsyncFunction(name, body)
303
-
304
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3> AsyncFunction(
305
- name: String,
306
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
307
- ) {
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) }
310
- } else {
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) }
312
- }
313
- }
314
-
315
- @Deprecated(
316
- message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
317
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
318
- )
319
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> asyncFunction(
320
- name: String,
321
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
322
- ) = AsyncFunction(name, body)
323
-
324
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> AsyncFunction(
325
- name: String,
326
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
327
- ) {
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) }
330
- } else {
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) }
332
- }
333
- }
334
-
335
- @Deprecated(
336
- message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
337
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
338
- )
339
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> asyncFunction(
340
- name: String,
341
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
342
- ) = AsyncFunction(name, body)
343
-
344
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> AsyncFunction(
345
- name: String,
346
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
347
- ) {
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) }
350
- } else {
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) }
352
- }
353
- }
354
-
355
- @Deprecated(
356
- message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
357
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
358
- )
359
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> asyncFunction(
360
- name: String,
361
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
362
- ) = AsyncFunction(name, body)
363
-
364
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> AsyncFunction(
365
- name: String,
366
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
367
- ) {
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) }
370
- } else {
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) }
372
- }
373
- }
374
-
375
- @Deprecated(
376
- message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
377
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
378
- )
379
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> asyncFunction(
380
- name: String,
381
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
382
- ) = AsyncFunction(name, body)
383
-
384
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> AsyncFunction(
385
- name: String,
386
- crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
387
- ) {
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) }
390
- } else {
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) }
392
- }
393
- }
394
-
395
- @Deprecated(
396
- message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
397
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
398
- )
399
- fun asyncFunction(
400
- name: String
401
- ) = AsyncFunction(name)
402
-
403
- fun AsyncFunction(
404
- name: String
405
- ) = AsyncFunctionBuilder(name).also { functionBuilders.add(it) }
406
-
407
- @Deprecated(
408
- message = "The 'viewManager' component was renamed to 'ViewManager'.",
409
- replaceWith = ReplaceWith("ViewManager(body)")
410
- )
411
- inline fun viewManager(body: ViewManagerDefinitionBuilder.() -> Unit) = ViewManager(body)
412
-
413
45
  /**
414
46
  * Creates the view manager definition that scopes other view-related definitions.
415
47
  */
@@ -421,12 +53,6 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
421
53
  viewManagerDefinition = viewManagerDefinitionBuilder.build()
422
54
  }
423
55
 
424
- @Deprecated(
425
- message = "The 'onCreate' component was renamed to 'OnCreate'.",
426
- replaceWith = ReplaceWith("OnCreate(body)")
427
- )
428
- inline fun onCreate(crossinline body: () -> Unit) = OnCreate(body)
429
-
430
56
  /**
431
57
  * Creates module's lifecycle listener that is called right after the module initialization.
432
58
  */
@@ -434,12 +60,6 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
434
60
  eventListeners[EventName.MODULE_CREATE] = BasicEventListener(EventName.MODULE_CREATE) { body() }
435
61
  }
436
62
 
437
- @Deprecated(
438
- message = "The 'onDestroy' component was renamed to 'OnDestroy'.",
439
- replaceWith = ReplaceWith("OnDestroy(body)")
440
- )
441
- inline fun onDestroy(crossinline body: () -> Unit) = OnDestroy(body)
442
-
443
63
  /**
444
64
  * Creates module's lifecycle listener that is called when the module is about to be deallocated.
445
65
  */
@@ -447,12 +67,6 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
447
67
  eventListeners[EventName.MODULE_DESTROY] = BasicEventListener(EventName.MODULE_DESTROY) { body() }
448
68
  }
449
69
 
450
- @Deprecated(
451
- message = "The 'onActivityEntersForeground' component was renamed to 'OnActivityEntersForeground'.",
452
- replaceWith = ReplaceWith("OnActivityEntersForeground(body)")
453
- )
454
- inline fun onActivityEntersForeground(crossinline body: () -> Unit) = OnActivityEntersForeground(body)
455
-
456
70
  /**
457
71
  * Creates module's lifecycle listener that is called right after the activity is resumed.
458
72
  */
@@ -460,12 +74,6 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
460
74
  eventListeners[EventName.ACTIVITY_ENTERS_FOREGROUND] = BasicEventListener(EventName.ACTIVITY_ENTERS_FOREGROUND) { body() }
461
75
  }
462
76
 
463
- @Deprecated(
464
- message = "The 'onActivityEntersBackground' component was renamed to 'OnActivityEntersBackground'.",
465
- replaceWith = ReplaceWith("OnActivityEntersBackground(body)")
466
- )
467
- inline fun onActivityEntersBackground(crossinline body: () -> Unit) = OnActivityEntersBackground(body)
468
-
469
77
  /**
470
78
  * Creates module's lifecycle listener that is called right after the activity is paused.
471
79
  */
@@ -473,12 +81,6 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
473
81
  eventListeners[EventName.ACTIVITY_ENTERS_BACKGROUND] = BasicEventListener(EventName.ACTIVITY_ENTERS_BACKGROUND) { body() }
474
82
  }
475
83
 
476
- @Deprecated(
477
- message = "The 'onActivityDestroys' component was renamed to 'OnActivityDestroys'.",
478
- replaceWith = ReplaceWith("OnActivityDestroys(body)")
479
- )
480
- inline fun onActivityDestroys(crossinline body: () -> Unit) = OnActivityDestroys(body)
481
-
482
84
  /**
483
85
  * Creates module's lifecycle listener that is called right after the activity is destroyed.
484
86
  */
@@ -486,51 +88,6 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
486
88
  eventListeners[EventName.ACTIVITY_DESTROYS] = BasicEventListener(EventName.ACTIVITY_DESTROYS) { body() }
487
89
  }
488
90
 
489
- @Deprecated(
490
- message = "The 'events' component was renamed to 'Events'.",
491
- replaceWith = ReplaceWith("Events(events)")
492
- )
493
- fun events(vararg events: String) = Events(*events)
494
-
495
- /**
496
- * Defines event names that this module can send to JavaScript.
497
- */
498
- fun Events(vararg events: String) {
499
- eventsDefinition = EventsDefinition(events)
500
- }
501
-
502
- @Deprecated(
503
- message = "The 'onStartObserving' component was renamed to 'OnStartObserving'.",
504
- replaceWith = ReplaceWith("OnStartObserving(body)")
505
- )
506
- inline fun onStartObserving(crossinline body: () -> Unit) = OnStartObserving(body)
507
-
508
- /**
509
- * Creates module's lifecycle listener that is called right after the first event listener is added.
510
- */
511
- inline fun OnStartObserving(crossinline body: () -> Unit) {
512
- AsyncFunction("startObserving", body)
513
- }
514
-
515
- @Deprecated(
516
- message = "The 'onStopObserving' component was renamed to 'OnStopObserving'.",
517
- replaceWith = ReplaceWith("OnStopObserving(body)")
518
- )
519
- inline fun onStopObserving(crossinline body: () -> Unit) = OnStopObserving(body)
520
-
521
- /**
522
- * Creates module's lifecycle listener that is called right after all event listeners are removed.
523
- */
524
- inline fun OnStopObserving(crossinline body: () -> Unit) {
525
- AsyncFunction("stopObserving", body)
526
- }
527
-
528
- @Deprecated(
529
- message = "The 'onNewIntent' component was renamed to 'OnNewIntent'.",
530
- replaceWith = ReplaceWith("OnNewIntent(body)")
531
- )
532
- inline fun onNewIntent(crossinline body: (Intent) -> Unit) = OnNewIntent(body)
533
-
534
91
  /**
535
92
  * Creates module's lifecycle listener that is called right after the new intent was received.
536
93
  */
@@ -538,12 +95,6 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
538
95
  eventListeners[EventName.ON_NEW_INTENT] = EventListenerWithPayload<Intent>(EventName.ON_NEW_INTENT) { body(it) }
539
96
  }
540
97
 
541
- @Deprecated(
542
- message = "The 'onActivityResult' component was renamed to 'OnActivityResult'.",
543
- replaceWith = ReplaceWith("OnActivityResult(body)")
544
- )
545
- inline fun onActivityResult(crossinline body: (Activity, OnActivityResultPayload) -> Unit) = OnActivityResult(body)
546
-
547
98
  /**
548
99
  * Creates module's lifecycle listener that is called right after the activity has received a result.
549
100
  */
@@ -4,10 +4,7 @@ import expo.modules.kotlin.ConcatIterator
4
4
  import expo.modules.kotlin.ModuleHolder
5
5
  import expo.modules.kotlin.events.EventListener
6
6
  import expo.modules.kotlin.events.EventName
7
- import expo.modules.kotlin.events.EventsDefinition
8
- import expo.modules.kotlin.functions.AsyncFunction
9
- import expo.modules.kotlin.functions.SuspendFunctionComponentBuilder
10
- import expo.modules.kotlin.functions.SyncFunctionComponent
7
+ import expo.modules.kotlin.objects.ObjectDefinitionData
11
8
  import expo.modules.kotlin.views.ViewManagerDefinition
12
9
 
13
10
  /**
@@ -16,13 +13,9 @@ import expo.modules.kotlin.views.ViewManagerDefinition
16
13
  */
17
14
  class ModuleDefinitionData(
18
15
  val name: String,
19
- val constantsProvider: () -> Map<String, Any?>,
20
- val syncFunctions: Map<String, SyncFunctionComponent>,
21
- val asyncFunctions: Map<String, AsyncFunction>,
22
- val suspendFunctionBuilders: List<SuspendFunctionComponentBuilder>,
16
+ val objectDefinition: ObjectDefinitionData,
23
17
  val viewManagerDefinition: ViewManagerDefinition? = null,
24
18
  val eventListeners: Map<EventName, EventListener> = emptyMap(),
25
- val eventsDefinition: EventsDefinition? = null
26
19
  )
27
20
 
28
21
  /**
@@ -35,14 +28,13 @@ class ProcessedModuleDefinition(
35
28
  moduleHolder: ModuleHolder
36
29
  ) {
37
30
  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
- }
31
+ val constantsProvider = data.objectDefinition.constantsProvider
32
+ val syncFunctions = data.objectDefinition.syncFunctions
33
+ val asyncFunctions = data.objectDefinition.asyncFunctions + data.objectDefinition.buildSuspendFunctions(moduleHolder)
43
34
  val viewManagerDefinition = data.viewManagerDefinition
44
35
  val eventListeners = data.eventListeners
45
- val eventsDefinition = data.eventsDefinition
36
+ val eventsDefinition = data.objectDefinition.eventsDefinition
37
+ val properties = data.objectDefinition.properties
46
38
 
47
39
  val functions
48
40
  get() = ConcatIterator(syncFunctions.values.iterator(), asyncFunctions.values.iterator())