expo-modules-core 0.8.0 → 0.9.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 (26) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/java/expo/modules/core/interfaces/ReactNativeHostHandler.java +11 -0
  4. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +127 -18
  5. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +210 -26
  6. package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinitionBuilder.kt +55 -5
  7. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +43 -5
  8. package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +3 -0
  9. package/ios/Swift/AppContext.swift +1 -8
  10. package/ios/Swift/Arguments/AnyArgumentType.swift +1 -1
  11. package/ios/Swift/Functions/AnyFunction.swift +5 -0
  12. package/ios/Swift/Functions/AsyncFunctionComponent.swift +182 -0
  13. package/ios/Swift/Functions/ConcreteFunction.swift +34 -67
  14. package/ios/Swift/Functions/SyncFunctionComponent.swift +181 -0
  15. package/ios/Swift/JavaScriptUtils.swift +51 -6
  16. package/ios/Swift/ModuleHolder.swift +11 -10
  17. package/ios/Swift/Modules/ModuleDefinitionComponents.swift +66 -44
  18. package/ios/Swift/Objects/ObjectDefinitionComponents.swift +45 -172
  19. package/ios/Swift/Views/ViewManagerDefinitionComponents.swift +23 -0
  20. package/ios/Tests/ConstantsSpec.swift +4 -4
  21. package/ios/Tests/ExpoModulesSpec.swift +3 -4
  22. package/ios/Tests/FunctionSpec.swift +11 -12
  23. package/ios/Tests/FunctionWithConvertiblesSpec.swift +2 -2
  24. package/ios/Tests/ModuleEventListenersSpec.swift +13 -13
  25. package/package.json +2 -2
  26. package/ios/Swift/Functions/AsyncFunction.swift +0 -17
@@ -10,6 +10,7 @@
10
10
  * That's why we used typeOf. It solves all problems described above.
11
11
  */
12
12
  @file:OptIn(ExperimentalStdlibApi::class)
13
+ @file:Suppress("FunctionName")
13
14
 
14
15
  package expo.modules.kotlin.modules
15
16
 
@@ -61,30 +62,48 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
61
62
  )
62
63
  }
63
64
 
65
+ @Deprecated(
66
+ message = "The 'name' component was renamed to 'Name'.",
67
+ replaceWith = ReplaceWith("Name(name)")
68
+ )
69
+ fun name(name: String) = Name(name)
70
+
64
71
  /**
65
72
  * Sets the name of the module that is exported to the JavaScript world.
66
73
  */
67
- fun name(name: String) {
74
+ fun Name(name: String) {
68
75
  this.name = name
69
76
  }
70
77
 
78
+ @Deprecated(
79
+ message = "The 'constants' component was renamed to 'Constants'.",
80
+ replaceWith = ReplaceWith("Constants(constantsProvider)")
81
+ )
82
+ fun constants(constantsProvider: () -> Map<String, Any?>) = Constants(constantsProvider)
83
+
71
84
  /**
72
85
  * Definition function setting the module's constants to export.
73
86
  */
74
- fun constants(constantsProvider: () -> Map<String, Any?>) {
87
+ fun Constants(constantsProvider: () -> Map<String, Any?>) {
75
88
  this.constantsProvider = constantsProvider
76
89
  }
77
90
 
91
+ @Deprecated(
92
+ message = "The 'constants' component was renamed to 'Constants'.",
93
+ replaceWith = ReplaceWith("Constants(constants)")
94
+ )
95
+ fun constants(vararg constants: Pair<String, Any?>) = Constants(*constants)
96
+
78
97
  /**
79
98
  * Definition of the module's constants to export.
80
99
  */
81
- fun constants(vararg constants: Pair<String, Any?>) {
100
+ fun Constants(vararg constants: Pair<String, Any?>) {
82
101
  constantsProvider = { constants.toMap() }
83
102
  }
84
103
 
85
104
  @Deprecated(
86
105
  message = "The 'function' component was deprecated and will change its behavior in the future.",
87
- replaceWith = ReplaceWith("asyncFunction(name, body)")
106
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
88
107
  )
89
108
  @JvmName("functionWithoutArgs")
90
109
  inline fun function(
@@ -96,7 +115,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
96
115
 
97
116
  @Deprecated(
98
117
  message = "The 'function' component was deprecated and will change its behavior in the future.",
99
- replaceWith = ReplaceWith("asyncFunction(name, body)")
118
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
100
119
  )
101
120
  inline fun <reified R> function(
102
121
  name: String,
@@ -107,7 +126,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
107
126
 
108
127
  @Deprecated(
109
128
  message = "The 'function' component was deprecated and will change its behavior in the future.",
110
- replaceWith = ReplaceWith("asyncFunction(name, body)")
129
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
111
130
  )
112
131
  inline fun <reified R, reified P0> function(
113
132
  name: String,
@@ -122,7 +141,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
122
141
 
123
142
  @Deprecated(
124
143
  message = "The 'function' component was deprecated and will change its behavior in the future.",
125
- replaceWith = ReplaceWith("asyncFunction(name, body)")
144
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
126
145
  )
127
146
  inline fun <reified R, reified P0, reified P1> function(
128
147
  name: String,
@@ -137,7 +156,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
137
156
 
138
157
  @Deprecated(
139
158
  message = "The 'function' component was deprecated and will change its behavior in the future.",
140
- replaceWith = ReplaceWith("asyncFunction(name, body)")
159
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
141
160
  )
142
161
  inline fun <reified R, reified P0, reified P1, reified P2> function(
143
162
  name: String,
@@ -152,7 +171,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
152
171
 
153
172
  @Deprecated(
154
173
  message = "The 'function' component was deprecated and will change its behavior in the future.",
155
- replaceWith = ReplaceWith("asyncFunction(name, body)")
174
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
156
175
  )
157
176
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3> function(
158
177
  name: String,
@@ -167,7 +186,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
167
186
 
168
187
  @Deprecated(
169
188
  message = "The 'function' component was deprecated and will change its behavior in the future.",
170
- replaceWith = ReplaceWith("asyncFunction(name, body)")
189
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
171
190
  )
172
191
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> function(
173
192
  name: String,
@@ -182,7 +201,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
182
201
 
183
202
  @Deprecated(
184
203
  message = "The 'function' component was deprecated and will change its behavior in the future.",
185
- replaceWith = ReplaceWith("asyncFunction(name, body)")
204
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
186
205
  )
187
206
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> function(
188
207
  name: String,
@@ -197,7 +216,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
197
216
 
198
217
  @Deprecated(
199
218
  message = "The 'function' component was deprecated and will change its behavior in the future.",
200
- replaceWith = ReplaceWith("asyncFunction(name, body)")
219
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
201
220
  )
202
221
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> function(
203
222
  name: String,
@@ -212,7 +231,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
212
231
 
213
232
  @Deprecated(
214
233
  message = "The 'function' component was deprecated and will change its behavior in the future.",
215
- replaceWith = ReplaceWith("asyncFunction(name, body)")
234
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
216
235
  )
217
236
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> function(
218
237
  name: String,
@@ -225,24 +244,52 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
225
244
  }
226
245
  }
227
246
 
247
+ @Deprecated(
248
+ message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
249
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
250
+ )
228
251
  @JvmName("asyncFunctionWithoutArgs")
229
252
  inline fun asyncFunction(
230
253
  name: String,
231
254
  crossinline body: () -> Any?
255
+ ) = AsyncFunction(name, body)
256
+
257
+ @JvmName("AsyncFunctionWithoutArgs")
258
+ inline fun AsyncFunction(
259
+ name: String,
260
+ crossinline body: () -> Any?
232
261
  ) {
233
262
  methods[name] = AsyncFunction(name, arrayOf()) { body() }
234
263
  }
235
264
 
265
+ @Deprecated(
266
+ message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
267
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
268
+ )
236
269
  inline fun <reified R> asyncFunction(
237
270
  name: String,
238
271
  crossinline body: () -> R
272
+ ) = AsyncFunction(name, body)
273
+
274
+ inline fun <reified R> AsyncFunction(
275
+ name: String,
276
+ crossinline body: () -> R
239
277
  ) {
240
278
  methods[name] = AsyncFunction(name, arrayOf()) { body() }
241
279
  }
242
280
 
281
+ @Deprecated(
282
+ message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
283
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
284
+ )
243
285
  inline fun <reified R, reified P0> asyncFunction(
244
286
  name: String,
245
287
  crossinline body: (p0: P0) -> R
288
+ ) = AsyncFunction(name, body)
289
+
290
+ inline fun <reified R, reified P0> AsyncFunction(
291
+ name: String,
292
+ crossinline body: (p0: P0) -> R
246
293
  ) {
247
294
  methods[name] = if (P0::class == Promise::class) {
248
295
  AsyncFunctionWithPromise(name, arrayOf()) { _, promise -> body(promise as P0) }
@@ -251,9 +298,18 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
251
298
  }
252
299
  }
253
300
 
301
+ @Deprecated(
302
+ message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
303
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
304
+ )
254
305
  inline fun <reified R, reified P0, reified P1> asyncFunction(
255
306
  name: String,
256
307
  crossinline body: (p0: P0, p1: P1) -> R
308
+ ) = AsyncFunction(name, body)
309
+
310
+ inline fun <reified R, reified P0, reified P1> AsyncFunction(
311
+ name: String,
312
+ crossinline body: (p0: P0, p1: P1) -> R
257
313
  ) {
258
314
  methods[name] = if (P1::class == Promise::class) {
259
315
  AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType())) { args, promise -> body(args[0] as P0, promise as P1) }
@@ -262,9 +318,18 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
262
318
  }
263
319
  }
264
320
 
321
+ @Deprecated(
322
+ message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
323
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
324
+ )
265
325
  inline fun <reified R, reified P0, reified P1, reified P2> asyncFunction(
266
326
  name: String,
267
327
  crossinline body: (p0: P0, p1: P1, p2: P2) -> R
328
+ ) = AsyncFunction(name, body)
329
+
330
+ inline fun <reified R, reified P0, reified P1, reified P2> AsyncFunction(
331
+ name: String,
332
+ crossinline body: (p0: P0, p1: P1, p2: P2) -> R
268
333
  ) {
269
334
  methods[name] = if (P2::class == Promise::class) {
270
335
  AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, promise as P2) }
@@ -273,9 +338,18 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
273
338
  }
274
339
  }
275
340
 
341
+ @Deprecated(
342
+ message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
343
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
344
+ )
276
345
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3> asyncFunction(
277
346
  name: String,
278
347
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
348
+ ) = AsyncFunction(name, body)
349
+
350
+ inline fun <reified R, reified P0, reified P1, reified P2, reified P3> AsyncFunction(
351
+ name: String,
352
+ crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
279
353
  ) {
280
354
  methods[name] = if (P3::class == Promise::class) {
281
355
  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) }
@@ -284,9 +358,18 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
284
358
  }
285
359
  }
286
360
 
361
+ @Deprecated(
362
+ message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
363
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
364
+ )
287
365
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> asyncFunction(
288
366
  name: String,
289
367
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
368
+ ) = AsyncFunction(name, body)
369
+
370
+ inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> AsyncFunction(
371
+ name: String,
372
+ crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
290
373
  ) {
291
374
  methods[name] = if (P4::class == Promise::class) {
292
375
  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) }
@@ -295,9 +378,18 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
295
378
  }
296
379
  }
297
380
 
381
+ @Deprecated(
382
+ message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
383
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
384
+ )
298
385
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> asyncFunction(
299
386
  name: String,
300
387
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
388
+ ) = AsyncFunction(name, body)
389
+
390
+ inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> AsyncFunction(
391
+ name: String,
392
+ crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
301
393
  ) {
302
394
  methods[name] = if (P5::class == Promise::class) {
303
395
  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) }
@@ -306,9 +398,18 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
306
398
  }
307
399
  }
308
400
 
401
+ @Deprecated(
402
+ message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
403
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
404
+ )
309
405
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> asyncFunction(
310
406
  name: String,
311
407
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
408
+ ) = AsyncFunction(name, body)
409
+
410
+ inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> AsyncFunction(
411
+ name: String,
412
+ crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
312
413
  ) {
313
414
  methods[name] = if (P6::class == Promise::class) {
314
415
  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) }
@@ -317,9 +418,18 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
317
418
  }
318
419
  }
319
420
 
421
+ @Deprecated(
422
+ message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
423
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
424
+ )
320
425
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> asyncFunction(
321
426
  name: String,
322
427
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
428
+ ) = AsyncFunction(name, body)
429
+
430
+ inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> AsyncFunction(
431
+ name: String,
432
+ crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
323
433
  ) {
324
434
  methods[name] = if (P7::class == Promise::class) {
325
435
  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) }
@@ -328,14 +438,28 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
328
438
  }
329
439
  }
330
440
 
441
+ @Deprecated(
442
+ message = "The 'asyncFunction' component was renamed to 'AsyncFunction'.",
443
+ replaceWith = ReplaceWith("AsyncFunction(name, body)")
444
+ )
331
445
  fun asyncFunction(
332
446
  name: String
447
+ ) = AsyncFunction(name)
448
+
449
+ fun AsyncFunction(
450
+ name: String
333
451
  ) = AsyncFunctionBuilder(name).also { functionBuilders.add(it) }
334
452
 
453
+ @Deprecated(
454
+ message = "The 'viewManager' component was renamed to 'ViewManager'.",
455
+ replaceWith = ReplaceWith("ViewManager(body)")
456
+ )
457
+ inline fun viewManager(body: ViewManagerDefinitionBuilder.() -> Unit) = ViewManager(body)
458
+
335
459
  /**
336
460
  * Creates the view manager definition that scopes other view-related definitions.
337
461
  */
338
- inline fun viewManager(body: ViewManagerDefinitionBuilder.() -> Unit) {
462
+ inline fun ViewManager(body: ViewManagerDefinitionBuilder.() -> Unit) {
339
463
  require(viewManagerDefinition == null) { "The module definition may have exported only one view manager." }
340
464
 
341
465
  val viewManagerDefinitionBuilder = ViewManagerDefinitionBuilder()
@@ -343,73 +467,133 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
343
467
  viewManagerDefinition = viewManagerDefinitionBuilder.build()
344
468
  }
345
469
 
470
+ @Deprecated(
471
+ message = "The 'onCreate' component was renamed to 'OnCreate'.",
472
+ replaceWith = ReplaceWith("OnCreate(body)")
473
+ )
474
+ inline fun onCreate(crossinline body: () -> Unit) = OnCreate(body)
475
+
346
476
  /**
347
477
  * Creates module's lifecycle listener that is called right after the module initialization.
348
478
  */
349
- inline fun onCreate(crossinline body: () -> Unit) {
479
+ inline fun OnCreate(crossinline body: () -> Unit) {
350
480
  eventListeners[EventName.MODULE_CREATE] = BasicEventListener(EventName.MODULE_CREATE) { body() }
351
481
  }
352
482
 
483
+ @Deprecated(
484
+ message = "The 'onDestroy' component was renamed to 'OnDestroy'.",
485
+ replaceWith = ReplaceWith("OnDestroy(body)")
486
+ )
487
+ inline fun onDestroy(crossinline body: () -> Unit) = OnDestroy(body)
488
+
353
489
  /**
354
490
  * Creates module's lifecycle listener that is called when the module is about to be deallocated.
355
491
  */
356
- inline fun onDestroy(crossinline body: () -> Unit) {
492
+ inline fun OnDestroy(crossinline body: () -> Unit) {
357
493
  eventListeners[EventName.MODULE_DESTROY] = BasicEventListener(EventName.MODULE_DESTROY) { body() }
358
494
  }
359
495
 
496
+ @Deprecated(
497
+ message = "The 'onActivityEntersForeground' component was renamed to 'OnActivityEntersForeground'.",
498
+ replaceWith = ReplaceWith("OnActivityEntersForeground(body)")
499
+ )
500
+ inline fun onActivityEntersForeground(crossinline body: () -> Unit) = OnActivityEntersForeground(body)
501
+
360
502
  /**
361
503
  * Creates module's lifecycle listener that is called right after the activity is resumed.
362
504
  */
363
- inline fun onActivityEntersForeground(crossinline body: () -> Unit) {
505
+ inline fun OnActivityEntersForeground(crossinline body: () -> Unit) {
364
506
  eventListeners[EventName.ACTIVITY_ENTERS_FOREGROUND] = BasicEventListener(EventName.ACTIVITY_ENTERS_FOREGROUND) { body() }
365
507
  }
366
508
 
509
+ @Deprecated(
510
+ message = "The 'onActivityEntersBackground' component was renamed to 'OnActivityEntersBackground'.",
511
+ replaceWith = ReplaceWith("OnActivityEntersBackground(body)")
512
+ )
513
+ inline fun onActivityEntersBackground(crossinline body: () -> Unit) = OnActivityEntersBackground(body)
514
+
367
515
  /**
368
516
  * Creates module's lifecycle listener that is called right after the activity is paused.
369
517
  */
370
- inline fun onActivityEntersBackground(crossinline body: () -> Unit) {
518
+ inline fun OnActivityEntersBackground(crossinline body: () -> Unit) {
371
519
  eventListeners[EventName.ACTIVITY_ENTERS_BACKGROUND] = BasicEventListener(EventName.ACTIVITY_ENTERS_BACKGROUND) { body() }
372
520
  }
373
521
 
522
+ @Deprecated(
523
+ message = "The 'onActivityDestroys' component was renamed to 'OnActivityDestroys'.",
524
+ replaceWith = ReplaceWith("OnActivityDestroys(body)")
525
+ )
526
+ inline fun onActivityDestroys(crossinline body: () -> Unit) = OnActivityDestroys(body)
527
+
374
528
  /**
375
529
  * Creates module's lifecycle listener that is called right after the activity is destroyed.
376
530
  */
377
- inline fun onActivityDestroys(crossinline body: () -> Unit) {
531
+ inline fun OnActivityDestroys(crossinline body: () -> Unit) {
378
532
  eventListeners[EventName.ACTIVITY_DESTROYS] = BasicEventListener(EventName.ACTIVITY_DESTROYS) { body() }
379
533
  }
380
534
 
535
+ @Deprecated(
536
+ message = "The 'events' component was renamed to 'Events'.",
537
+ replaceWith = ReplaceWith("Events(events)")
538
+ )
539
+ fun events(vararg events: String) = Events(*events)
540
+
381
541
  /**
382
542
  * Defines event names that this module can send to JavaScript.
383
543
  */
384
- fun events(vararg events: String) {
544
+ fun Events(vararg events: String) {
385
545
  eventsDefinition = EventsDefinition(events)
386
546
  }
387
547
 
548
+ @Deprecated(
549
+ message = "The 'onStartObserving' component was renamed to 'OnStartObserving'.",
550
+ replaceWith = ReplaceWith("OnStartObserving(body)")
551
+ )
552
+ inline fun onStartObserving(crossinline body: () -> Unit) = OnStartObserving(body)
553
+
388
554
  /**
389
555
  * Creates module's lifecycle listener that is called right after the first event listener is added.
390
556
  */
391
- inline fun onStartObserving(crossinline body: () -> Unit) {
392
- asyncFunction("startObserving", body)
557
+ inline fun OnStartObserving(crossinline body: () -> Unit) {
558
+ AsyncFunction("startObserving", body)
393
559
  }
394
560
 
561
+ @Deprecated(
562
+ message = "The 'onStopObserving' component was renamed to 'OnStopObserving'.",
563
+ replaceWith = ReplaceWith("OnStopObserving(body)")
564
+ )
565
+ inline fun onStopObserving(crossinline body: () -> Unit) = OnStopObserving(body)
566
+
395
567
  /**
396
568
  * Creates module's lifecycle listener that is called right after all event listeners are removed.
397
569
  */
398
- inline fun onStopObserving(crossinline body: () -> Unit) {
399
- asyncFunction("stopObserving", body)
570
+ inline fun OnStopObserving(crossinline body: () -> Unit) {
571
+ AsyncFunction("stopObserving", body)
400
572
  }
401
573
 
574
+ @Deprecated(
575
+ message = "The 'onNewIntent' component was renamed to 'OnNewIntent'.",
576
+ replaceWith = ReplaceWith("OnNewIntent(body)")
577
+ )
578
+ inline fun onNewIntent(crossinline body: (Intent) -> Unit) = OnNewIntent(body)
579
+
402
580
  /**
403
581
  * Creates module's lifecycle listener that is called right after the new intent was received.
404
582
  */
405
- inline fun onNewIntent(crossinline body: (Intent) -> Unit) {
583
+ inline fun OnNewIntent(crossinline body: (Intent) -> Unit) {
406
584
  eventListeners[EventName.ON_NEW_INTENT] = EventListenerWithPayload<Intent>(EventName.ON_NEW_INTENT) { body(it) }
407
585
  }
408
586
 
587
+ @Deprecated(
588
+ message = "The 'onActivityResult' component was renamed to 'OnActivityResult'.",
589
+ replaceWith = ReplaceWith("OnActivityResult(body)")
590
+ )
591
+ inline fun onActivityResult(crossinline body: (Activity, OnActivityResultPayload) -> Unit) = OnActivityResult(body)
592
+
409
593
  /**
410
594
  * Creates module's lifecycle listener that is called right after the activity has received a result.
411
595
  */
412
- inline fun onActivityResult(crossinline body: (Activity, OnActivityResultPayload) -> Unit) {
596
+ inline fun OnActivityResult(crossinline body: (Activity, OnActivityResultPayload) -> Unit) {
413
597
  eventListeners[EventName.ON_ACTIVITY_RESULT] =
414
598
  EventListenerWithSenderAndPayload<Activity, OnActivityResultPayload>(EventName.ON_ACTIVITY_RESULT) { sender, payload -> body(sender, payload) }
415
599
  }
@@ -1,4 +1,5 @@
1
1
  @file:OptIn(ExperimentalStdlibApi::class)
2
+ @file:Suppress("FunctionName")
2
3
 
3
4
  package expo.modules.kotlin.views
4
5
 
@@ -8,11 +9,20 @@ import expo.modules.kotlin.modules.DefinitionMarker
8
9
 
9
10
  @DefinitionMarker
10
11
  class ViewGroupDefinitionBuilder {
11
- @PublishedApi internal var addViewAction: AddViewAction? = null
12
- @PublishedApi internal var getChildAtAction: GetChildAtAction? = null
13
- @PublishedApi internal var getChildCountAction: GetChildCountAction? = null
14
- @PublishedApi internal var removeViewAction: RemoveViewAction? = null
15
- @PublishedApi internal var removeViewAtAction: RemoveViewAtAction? = null
12
+ @PublishedApi
13
+ internal var addViewAction: AddViewAction? = null
14
+
15
+ @PublishedApi
16
+ internal var getChildAtAction: GetChildAtAction? = null
17
+
18
+ @PublishedApi
19
+ internal var getChildCountAction: GetChildCountAction? = null
20
+
21
+ @PublishedApi
22
+ internal var removeViewAction: RemoveViewAction? = null
23
+
24
+ @PublishedApi
25
+ internal var removeViewAtAction: RemoveViewAtAction? = null
16
26
 
17
27
  fun build() = ViewGroupDefinition(
18
28
  addViewAction,
@@ -22,40 +32,80 @@ class ViewGroupDefinitionBuilder {
22
32
  removeViewAtAction
23
33
  )
24
34
 
35
+ @Deprecated(
36
+ message = "The 'addChildView' component was renamed to 'AddChildView'.",
37
+ replaceWith = ReplaceWith("AddChildView(body)")
38
+ )
25
39
  inline fun <reified ParentViewType : ViewGroup, reified ChildViewType : View> addChildView(
26
40
  noinline body: (parent: ParentViewType, child: ChildViewType, index: Int) -> Unit
41
+ ) = AddChildView(body)
42
+
43
+ inline fun <reified ParentViewType : ViewGroup, reified ChildViewType : View> AddChildView(
44
+ noinline body: (parent: ParentViewType, child: ChildViewType, index: Int) -> Unit
27
45
  ) {
28
46
  addViewAction = { parent, child, index ->
29
47
  body(parent as ParentViewType, child as ChildViewType, index)
30
48
  }
31
49
  }
32
50
 
51
+ @Deprecated(
52
+ message = "The 'getChildCount' component was renamed to 'GetChildCount'.",
53
+ replaceWith = ReplaceWith("GetChildCount(body)")
54
+ )
33
55
  inline fun <reified ParentViewType : ViewGroup> getChildCount(
34
56
  noinline body: (view: ParentViewType) -> Int
57
+ ) = GetChildCount(body)
58
+
59
+ inline fun <reified ParentViewType : ViewGroup> GetChildCount(
60
+ noinline body: (view: ParentViewType) -> Int
35
61
  ) {
36
62
  getChildCountAction = { view ->
37
63
  body(view as ParentViewType)
38
64
  }
39
65
  }
40
66
 
67
+ @Deprecated(
68
+ message = "The 'getChildViewAt' component was renamed to 'GetChildViewAt'.",
69
+ replaceWith = ReplaceWith("GetChildViewAt(body)")
70
+ )
41
71
  inline fun <reified ParentViewType : ViewGroup, reified ChildViewType : View> getChildViewAt(
42
72
  noinline body: (view: ParentViewType, index: Int) -> ChildViewType?
73
+ ) = GetChildViewAt(body)
74
+
75
+ inline fun <reified ParentViewType : ViewGroup, reified ChildViewType : View> GetChildViewAt(
76
+ noinline body: (view: ParentViewType, index: Int) -> ChildViewType?
43
77
  ) {
44
78
  getChildAtAction = { view, index ->
45
79
  body(view as ParentViewType, index)
46
80
  }
47
81
  }
48
82
 
83
+ @Deprecated(
84
+ message = "The 'removeChildViewAt' component was renamed to 'RemoveChildViewAt'.",
85
+ replaceWith = ReplaceWith("RemoveChildViewAt(body)")
86
+ )
49
87
  inline fun <reified ParentViewType : ViewGroup> removeChildViewAt(
50
88
  noinline body: (view: ParentViewType, index: Int) -> Unit
89
+ ) = RemoveChildViewAt(body)
90
+
91
+ inline fun <reified ParentViewType : ViewGroup> RemoveChildViewAt(
92
+ noinline body: (view: ParentViewType, index: Int) -> Unit
51
93
  ) {
52
94
  removeViewAtAction = { view, index ->
53
95
  body(view as ParentViewType, index)
54
96
  }
55
97
  }
56
98
 
99
+ @Deprecated(
100
+ message = "The 'removeChildView' component was renamed to 'RemoveChildView'.",
101
+ replaceWith = ReplaceWith("RemoveChildView(body)")
102
+ )
57
103
  inline fun <reified ParentViewType : ViewGroup, reified ChildViewType : View> removeChildView(
58
104
  noinline body: (parent: ParentViewType, child: ChildViewType) -> Unit
105
+ ) = RemoveChildView(body)
106
+
107
+ inline fun <reified ParentViewType : ViewGroup, reified ChildViewType : View> RemoveChildView(
108
+ noinline body: (parent: ParentViewType, child: ChildViewType) -> Unit
59
109
  ) {
60
110
  removeViewAction = { view, child ->
61
111
  body(view as ParentViewType, child as ChildViewType)