expo-modules-core 0.7.0 → 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.
Files changed (124) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +1 -1
  3. package/android/ExpoModulesCorePlugin.gradle +15 -0
  4. package/android/build.gradle +46 -32
  5. package/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java +5 -5
  6. package/android/src/main/java/expo/modules/adapters/react/services/UIManagerModuleWrapper.java +13 -0
  7. package/android/src/main/java/expo/modules/core/ViewManager.java +9 -0
  8. package/android/src/main/java/expo/modules/core/interfaces/JavaScriptContextProvider.java +4 -0
  9. package/android/src/main/java/expo/modules/core/interfaces/ReactActivityHandler.java +37 -1
  10. package/android/src/main/java/expo/modules/core/interfaces/ReactNativeHostHandler.java +19 -0
  11. package/android/src/main/java/expo/modules/core/interfaces/services/UIManager.java +2 -0
  12. package/android/src/main/java/expo/modules/kotlin/AppContext.kt +13 -5
  13. package/android/src/main/java/expo/modules/kotlin/KPromiseWrapper.kt +2 -13
  14. package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +11 -5
  15. package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +5 -1
  16. package/android/src/main/java/expo/modules/kotlin/ModuleRegistry.kt +17 -0
  17. package/android/src/main/java/expo/modules/kotlin/callbacks/ViewCallback.kt +14 -3
  18. package/android/src/main/java/expo/modules/kotlin/events/EventEmitter.kt +13 -0
  19. package/android/src/main/java/expo/modules/kotlin/events/KModuleEventEmitterWrapper.kt +102 -0
  20. package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +25 -1
  21. package/android/src/main/java/expo/modules/kotlin/{methods/AnyMethod.kt → functions/AnyFunction.kt} +6 -5
  22. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +15 -0
  23. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +61 -0
  24. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromise.kt +15 -0
  25. package/android/src/main/java/expo/modules/kotlin/functions/AsyncSuspendFunction.kt +36 -0
  26. package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +14 -0
  27. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +176 -27
  28. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionData.kt +2 -2
  29. package/android/src/main/java/expo/modules/kotlin/records/FieldValidator.kt +139 -0
  30. package/android/src/main/java/expo/modules/kotlin/records/Record.kt +0 -39
  31. package/android/src/main/java/expo/modules/kotlin/records/RecordTypeConverter.kt +59 -10
  32. package/android/src/main/java/expo/modules/kotlin/records/Required.kt +5 -0
  33. package/android/src/main/java/expo/modules/kotlin/records/ValidationBinder.kt +110 -0
  34. package/android/src/main/java/expo/modules/kotlin/records/Validators.kt +61 -0
  35. package/android/src/main/java/expo/modules/kotlin/types/JSTypeConverter.kt +35 -0
  36. package/android/src/main/java/expo/modules/kotlin/types/JSTypeConverterHelper.kt +148 -0
  37. package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +9 -1
  38. package/android/src/main/java/expo/modules/kotlin/views/GroupViewManagerWrapper.kt +49 -0
  39. package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinition.kt +18 -0
  40. package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinitionBuilder.kt +64 -0
  41. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinition.kt +4 -1
  42. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +15 -2
  43. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerWrapperDelegate.kt +3 -0
  44. package/build/NativeModulesProxy.native.d.ts +0 -4
  45. package/build/NativeModulesProxy.native.d.ts.map +1 -1
  46. package/build/NativeModulesProxy.native.js +1 -14
  47. package/build/NativeModulesProxy.native.js.map +1 -1
  48. package/build/NativeModulesProxy.types.d.ts +0 -3
  49. package/build/NativeModulesProxy.types.d.ts.map +1 -1
  50. package/build/NativeModulesProxy.types.js.map +1 -1
  51. package/build/NativeViewManagerAdapter.native.d.ts.map +1 -1
  52. package/build/NativeViewManagerAdapter.native.js +9 -33
  53. package/build/NativeViewManagerAdapter.native.js.map +1 -1
  54. package/build/sweet/NativeErrorManager.js +1 -1
  55. package/build/sweet/NativeErrorManager.js.map +1 -1
  56. package/ios/AppDelegates/EXAppDelegatesLoader.m +4 -8
  57. package/ios/AppDelegates/ExpoAppDelegate.swift +4 -10
  58. package/ios/EXAppDefines.h +1 -0
  59. package/ios/EXAppDefines.m +6 -0
  60. package/ios/EXUtilities.h +2 -0
  61. package/ios/EXUtilities.m +12 -0
  62. package/ios/ExpoModulesCore.h +4 -0
  63. package/ios/ExpoModulesCore.podspec +4 -2
  64. package/ios/Interfaces/FileSystem/EXFileSystemInterface.h +1 -1
  65. package/ios/Interfaces/TaskManager/EXTaskServiceInterface.h +1 -0
  66. package/ios/JSI/{JSIConversions.h → EXJSIConversions.h} +4 -1
  67. package/ios/JSI/{JSIConversions.mm → EXJSIConversions.mm} +16 -5
  68. package/ios/JSI/{JSIInstaller.h → EXJSIInstaller.h} +3 -3
  69. package/ios/JSI/EXJSIInstaller.mm +17 -0
  70. package/ios/JSI/{ExpoModulesProxySpec.h → EXJSIUtils.h} +0 -9
  71. package/ios/JSI/{ExpoModulesProxySpec.mm → EXJSIUtils.mm} +4 -48
  72. package/ios/JSI/EXJavaScriptObject.h +97 -0
  73. package/ios/JSI/EXJavaScriptObject.mm +121 -0
  74. package/ios/JSI/{JavaScriptRuntime.h → EXJavaScriptRuntime.h} +27 -8
  75. package/ios/JSI/EXJavaScriptRuntime.mm +153 -0
  76. package/ios/JSI/EXJavaScriptValue.h +57 -0
  77. package/ios/JSI/EXJavaScriptValue.mm +166 -0
  78. package/ios/JSI/ExpoModulesHostObject.mm +2 -1
  79. package/ios/JSI/JavaScriptRuntime.swift +32 -0
  80. package/ios/JSI/JavaScriptValue.swift +94 -0
  81. package/ios/ModuleRegistryAdapter/EXModuleRegistryAdapter.m +1 -11
  82. package/ios/NativeModulesProxy/EXNativeModulesProxy.h +2 -2
  83. package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +24 -22
  84. package/ios/ReactDelegates/EXReactCompatibleHelpers.h +18 -0
  85. package/ios/ReactDelegates/EXReactCompatibleHelpers.m +19 -0
  86. package/ios/ReactDelegates/ExpoReactDelegate.swift +2 -2
  87. package/ios/ReactDelegates/ExpoReactDelegateHandler.swift +1 -1
  88. package/ios/Swift/AppContext.swift +27 -1
  89. package/ios/Swift/Functions/AsyncFunction.swift +17 -0
  90. package/ios/Swift/Functions/ConcreteFunction.swift +6 -1
  91. package/ios/Swift/JavaScriptUtils.swift +11 -0
  92. package/ios/Swift/ModuleHolder.swift +14 -3
  93. package/ios/Swift/ModulesProvider.swift +3 -10
  94. package/ios/Swift/Objects/ObjectDefinitionComponents.swift +176 -0
  95. package/ios/Swift/SwiftInteropBridge.swift +14 -5
  96. package/ios/Swift/Views/ComponentData.swift +2 -1
  97. package/ios/Swift/Views/ExpoView.swift +8 -0
  98. package/ios/Swift.h +5 -0
  99. package/ios/Tests/ArgumentTypeSpec.swift +2 -3
  100. package/ios/Tests/ConstantsSpec.swift +2 -3
  101. package/ios/Tests/ConvertiblesSpec.swift +2 -3
  102. package/ios/Tests/ExceptionsSpec.swift +2 -3
  103. package/ios/Tests/ExpoModulesSpec.swift +76 -0
  104. package/ios/Tests/FunctionSpec.swift +2 -3
  105. package/ios/Tests/FunctionWithConvertiblesSpec.swift +2 -3
  106. package/ios/Tests/JavaScriptObjectSpec.swift +97 -0
  107. package/ios/Tests/JavaScriptRuntimeSpec.swift +94 -0
  108. package/ios/Tests/ModuleEventListenersSpec.swift +2 -3
  109. package/ios/Tests/ModuleRegistrySpec.swift +2 -3
  110. package/ios/Tests/RecordSpec.swift +2 -3
  111. package/package.json +2 -2
  112. package/src/NativeModulesProxy.native.ts +2 -22
  113. package/src/NativeModulesProxy.types.ts +0 -8
  114. package/src/NativeViewManagerAdapter.native.tsx +12 -28
  115. package/src/sweet/NativeErrorManager.ts +1 -1
  116. package/android/src/main/java/expo/modules/kotlin/events/KEventEmitterWrapper.kt +0 -26
  117. package/android/src/main/java/expo/modules/kotlin/methods/Method.kt +0 -14
  118. package/android/src/main/java/expo/modules/kotlin/methods/PromiseMethod.kt +0 -15
  119. package/ios/JSI/JSIInstaller.mm +0 -34
  120. package/ios/JSI/JavaScriptObject.h +0 -60
  121. package/ios/JSI/JavaScriptObject.mm +0 -93
  122. package/ios/JSI/JavaScriptRuntime.mm +0 -102
  123. package/ios/NativeModulesProxy/EXComponentDataCompatibleWrapper.h +0 -16
  124. package/ios/NativeModulesProxy/EXComponentDataCompatibleWrapper.m +0 -28
@@ -0,0 +1,110 @@
1
+ package expo.modules.kotlin.records
2
+
3
+ import kotlin.reflect.KClass
4
+ import kotlin.reflect.KType
5
+ import kotlin.reflect.full.createType
6
+ import kotlin.reflect.full.isSubclassOf
7
+
8
+ interface ValidationBinder {
9
+ fun bind(annotation: Annotation, fieldType: KType): FieldValidator<*>
10
+ }
11
+
12
+ @Retention(AnnotationRetention.RUNTIME)
13
+ @Target(AnnotationTarget.ANNOTATION_CLASS)
14
+ annotation class BindUsing(val binder: KClass<*>)
15
+
16
+ internal class IntRangeBinder : ValidationBinder {
17
+ override fun bind(annotation: Annotation, fieldType: KType): FieldValidator<*> {
18
+ val rangeAnnotation = annotation as IntRange
19
+ return NumericRangeValidator(
20
+ rangeAnnotation.from,
21
+ rangeAnnotation.to,
22
+ rangeAnnotation.fromInclusive,
23
+ rangeAnnotation.toInclusive
24
+ )
25
+ }
26
+ }
27
+
28
+ internal class LongRangeBinder : ValidationBinder {
29
+ override fun bind(annotation: Annotation, fieldType: KType): FieldValidator<*> {
30
+ val rangeAnnotation = annotation as LongRange
31
+ return NumericRangeValidator(
32
+ rangeAnnotation.from,
33
+ rangeAnnotation.to,
34
+ rangeAnnotation.fromInclusive,
35
+ rangeAnnotation.toInclusive
36
+ )
37
+ }
38
+ }
39
+
40
+ internal class FloatRangeBinder : ValidationBinder {
41
+ override fun bind(annotation: Annotation, fieldType: KType): FieldValidator<*> {
42
+ val rangeAnnotation = annotation as FloatRange
43
+ return NumericRangeValidator(
44
+ rangeAnnotation.from,
45
+ rangeAnnotation.to,
46
+ rangeAnnotation.fromInclusive,
47
+ rangeAnnotation.toInclusive
48
+ )
49
+ }
50
+ }
51
+
52
+ internal class DoubleRangeBinder : ValidationBinder {
53
+ override fun bind(annotation: Annotation, fieldType: KType): FieldValidator<*> {
54
+ val rangeAnnotation = annotation as DoubleRange
55
+ return NumericRangeValidator(
56
+ rangeAnnotation.from,
57
+ rangeAnnotation.to,
58
+ rangeAnnotation.fromInclusive,
59
+ rangeAnnotation.toInclusive
60
+ )
61
+ }
62
+ }
63
+
64
+ internal class IsCollectionNotEmptyBinder : ValidationBinder {
65
+ override fun bind(annotation: Annotation, fieldType: KType): FieldValidator<*> {
66
+ assert(annotation is IsNotEmpty)
67
+
68
+ when (fieldType) {
69
+ IntArray::class.createType() -> return IsNotEmptyIntArrayValidator()
70
+ DoubleArray::class.createType() -> return IsNotEmptyDoubleArrayValidator()
71
+ FloatArray::class.createType() -> return IsNotEmptyFloatArrayValidator()
72
+ }
73
+
74
+ val kClass = fieldType.classifier as KClass<*>
75
+ if (kClass.isSubclassOf(Array::class) || kClass.java.isArray) {
76
+ return IsNotEmptyArrayValidator()
77
+ }
78
+
79
+ return IsNotEmptyCollectionValidator()
80
+ }
81
+ }
82
+
83
+ internal class SizeBinder : ValidationBinder {
84
+ override fun bind(annotation: Annotation, fieldType: KType): FieldValidator<*> {
85
+ val sizeAnnotation = annotation as Size
86
+
87
+ when (fieldType) {
88
+ IntArray::class.createType() -> return IntArraySizeValidator(sizeAnnotation.min, sizeAnnotation.max)
89
+ DoubleArray::class.createType() -> return DoubleArraySizeValidator(sizeAnnotation.min, sizeAnnotation.max)
90
+ FloatArray::class.createType() -> return FloatArraySizeValidator(sizeAnnotation.min, sizeAnnotation.max)
91
+ }
92
+
93
+ val kClass = fieldType.classifier as KClass<*>
94
+
95
+ if (kClass.isSubclassOf(String::class)) {
96
+ return StringSizeValidator(sizeAnnotation.min, sizeAnnotation.max)
97
+ } else if (kClass.isSubclassOf(Array::class) || kClass.java.isArray) {
98
+ return ArraySizeValidator(sizeAnnotation.min, sizeAnnotation.max)
99
+ }
100
+
101
+ return CollectionSizeValidator(sizeAnnotation.min, sizeAnnotation.max)
102
+ }
103
+ }
104
+
105
+ internal class RegexBinder : ValidationBinder {
106
+ override fun bind(annotation: Annotation, fieldType: KType): FieldValidator<*> {
107
+ val regexAnnotation = annotation as RegularExpression
108
+ return RegexValidator(regexAnnotation.regex.toRegex())
109
+ }
110
+ }
@@ -0,0 +1,61 @@
1
+ package expo.modules.kotlin.records
2
+
3
+ @Retention(AnnotationRetention.RUNTIME)
4
+ @Target(AnnotationTarget.PROPERTY, AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER)
5
+ @BindUsing(IntRangeBinder::class)
6
+ annotation class IntRange(
7
+ val from: Int,
8
+ val to: Int,
9
+ val fromInclusive: Boolean = true,
10
+ val toInclusive: Boolean = true,
11
+ )
12
+
13
+ @Retention(AnnotationRetention.RUNTIME)
14
+ @Target(AnnotationTarget.PROPERTY)
15
+ @BindUsing(LongRangeBinder::class)
16
+ annotation class LongRange(
17
+ val from: Long,
18
+ val to: Long,
19
+ val fromInclusive: Boolean = true,
20
+ val toInclusive: Boolean = true
21
+ )
22
+
23
+ @Retention(AnnotationRetention.RUNTIME)
24
+ @Target(AnnotationTarget.PROPERTY)
25
+ @BindUsing(FloatRangeBinder::class)
26
+ annotation class FloatRange(
27
+ val from: Float,
28
+ val to: Float,
29
+ val fromInclusive: Boolean = true,
30
+ val toInclusive: Boolean = true
31
+ )
32
+
33
+ @Retention(AnnotationRetention.RUNTIME)
34
+ @Target(AnnotationTarget.PROPERTY)
35
+ @BindUsing(DoubleRangeBinder::class)
36
+ annotation class DoubleRange(
37
+ val from: Double,
38
+ val to: Double,
39
+ val fromInclusive: Boolean = true,
40
+ val toInclusive: Boolean = true
41
+ )
42
+
43
+ @Retention(AnnotationRetention.RUNTIME)
44
+ @Target(AnnotationTarget.PROPERTY)
45
+ @BindUsing(IsCollectionNotEmptyBinder::class)
46
+ annotation class IsNotEmpty
47
+
48
+ @Retention(AnnotationRetention.RUNTIME)
49
+ @Target(AnnotationTarget.PROPERTY)
50
+ @BindUsing(SizeBinder::class)
51
+ annotation class Size(
52
+ val min: Int = 0,
53
+ val max: Int = Int.MAX_VALUE
54
+ )
55
+
56
+ @Retention(AnnotationRetention.RUNTIME)
57
+ @Target(AnnotationTarget.PROPERTY)
58
+ @BindUsing(RegexBinder::class)
59
+ annotation class RegularExpression(
60
+ val regex: String
61
+ )
@@ -0,0 +1,35 @@
1
+ package expo.modules.kotlin.types
2
+
3
+ import android.os.Bundle
4
+ import com.facebook.react.bridge.Arguments
5
+ import com.facebook.react.bridge.WritableArray
6
+ import com.facebook.react.bridge.WritableMap
7
+ import expo.modules.kotlin.records.Record
8
+
9
+ object JSTypeConverter {
10
+ interface ContainerProvider {
11
+ fun createMap(): WritableMap
12
+ fun createArray(): WritableArray
13
+ }
14
+
15
+ internal object DefaultContainerProvider : ContainerProvider {
16
+ override fun createMap(): WritableMap = Arguments.createMap()
17
+ override fun createArray(): WritableArray = Arguments.createArray()
18
+ }
19
+
20
+ fun convertToJSValue(value: Any?, containerProvider: ContainerProvider = DefaultContainerProvider): Any? {
21
+ return when (value) {
22
+ null, is Unit -> null
23
+ is Bundle -> value.toJSValue(containerProvider)
24
+ is Iterable<*> -> value.toJSValue(containerProvider)
25
+ is Array<*> -> value.toJSValue(containerProvider)
26
+ is IntArray -> value.toJSValue(containerProvider)
27
+ is FloatArray -> value.toJSValue(containerProvider)
28
+ is DoubleArray -> value.toJSValue(containerProvider)
29
+ is Map<*, *> -> value.toJSValue(containerProvider)
30
+ is Enum<*> -> value.toJSValue()
31
+ is Record -> value.toJSValue(containerProvider)
32
+ else -> value
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,148 @@
1
+ package expo.modules.kotlin.types
2
+
3
+ import android.os.Bundle
4
+ import com.facebook.react.bridge.ReadableArray
5
+ import com.facebook.react.bridge.ReadableMap
6
+ import com.facebook.react.bridge.WritableArray
7
+ import com.facebook.react.bridge.WritableMap
8
+ import expo.modules.kotlin.records.Field
9
+ import expo.modules.kotlin.records.Record
10
+ import kotlin.reflect.KProperty1
11
+ import kotlin.reflect.full.declaredMemberProperties
12
+ import kotlin.reflect.full.findAnnotation
13
+ import kotlin.reflect.full.memberProperties
14
+ import kotlin.reflect.full.primaryConstructor
15
+ import kotlin.reflect.jvm.isAccessible
16
+
17
+ fun Record.toJSValue(containerProvider: JSTypeConverter.ContainerProvider): WritableMap {
18
+ val result = containerProvider.createMap()
19
+
20
+ javaClass
21
+ .kotlin
22
+ .memberProperties.map { property ->
23
+ val fieldInformation = property.findAnnotation<Field>() ?: return@map
24
+ val jsKey = fieldInformation.key.takeUnless { it == "" } ?: property.name
25
+
26
+ property.isAccessible = true
27
+
28
+ val value = property.get(this)
29
+ val convertedValue = JSTypeConverter.convertToJSValue(value, containerProvider)
30
+ result.putGeneric(jsKey, convertedValue)
31
+ }
32
+
33
+ return result
34
+ }
35
+
36
+ fun Bundle.toJSValue(containerProvider: JSTypeConverter.ContainerProvider): WritableMap {
37
+ val result = containerProvider.createMap()
38
+
39
+ for (key in keySet()) {
40
+ val value = get(key)
41
+ val convertedValue = JSTypeConverter.convertToJSValue(value, containerProvider)
42
+ result.putGeneric(key, convertedValue)
43
+ }
44
+
45
+ return result
46
+ }
47
+
48
+ fun <K, V> Map<K, V>.toJSValue(containerProvider: JSTypeConverter.ContainerProvider): WritableMap {
49
+ val result = containerProvider.createMap()
50
+
51
+ for ((key, value) in entries) {
52
+ val convertedValue = JSTypeConverter.convertToJSValue(value, containerProvider)
53
+ result.putGeneric(key.toString(), convertedValue)
54
+ }
55
+
56
+ return result
57
+ }
58
+
59
+ fun <T> Iterable<T>.toJSValue(containerProvider: JSTypeConverter.ContainerProvider): WritableArray {
60
+ val result = containerProvider.createArray()
61
+
62
+ for (value in this) {
63
+ val convertedValue = JSTypeConverter.convertToJSValue(value, containerProvider)
64
+ result.putGeneric(convertedValue)
65
+ }
66
+
67
+ return result
68
+ }
69
+
70
+ fun <T> Array<T>.toJSValue(containerProvider: JSTypeConverter.ContainerProvider): WritableArray {
71
+ val result = containerProvider.createArray()
72
+
73
+ for (value in this) {
74
+ val convertedValue = JSTypeConverter.convertToJSValue(value, containerProvider)
75
+ result.putGeneric(convertedValue)
76
+ }
77
+
78
+ return result
79
+ }
80
+
81
+ fun IntArray.toJSValue(containerProvider: JSTypeConverter.ContainerProvider): WritableArray {
82
+ return containerProvider.createArray().also {
83
+ for (value in this) {
84
+ it.pushInt(value)
85
+ }
86
+ }
87
+ }
88
+
89
+ fun FloatArray.toJSValue(containerProvider: JSTypeConverter.ContainerProvider): WritableArray {
90
+ return containerProvider.createArray().also {
91
+ for (value in this) {
92
+ it.pushDouble(value.toDouble())
93
+ }
94
+ }
95
+ }
96
+
97
+ fun DoubleArray.toJSValue(containerProvider: JSTypeConverter.ContainerProvider): WritableArray {
98
+ return containerProvider.createArray().also {
99
+ for (value in this) {
100
+ it.pushDouble(value)
101
+ }
102
+ }
103
+ }
104
+
105
+ fun Enum<*>.toJSValue(): Any? {
106
+ val primaryConstructor = requireNotNull(this::class.primaryConstructor) {
107
+ "Cannot convert enum without the primary constructor to js value"
108
+ }
109
+
110
+ if (primaryConstructor.parameters.isEmpty()) {
111
+ return this.name
112
+ } else if (primaryConstructor.parameters.size == 1) {
113
+ val parameterName = primaryConstructor.parameters.first().name!!
114
+ @Suppress("UNCHECKED_CAST")
115
+ val parameterProperty = this::class.declaredMemberProperties
116
+ .find { it.name == parameterName } as KProperty1<Enum<*>, *>
117
+
118
+ return parameterProperty.get(this)
119
+ }
120
+
121
+ throw IllegalStateException("Enum '$javaClass' cannot be used as return type (incompatible with JS)")
122
+ }
123
+
124
+ internal fun WritableMap.putGeneric(key: String, value: Any?) {
125
+ when (value) {
126
+ null, is Unit -> putNull(key)
127
+ is ReadableArray -> putArray(key, value)
128
+ is ReadableMap -> putMap(key, value)
129
+ is String -> putString(key, value)
130
+ is Int -> putInt(key, value)
131
+ is Number -> putDouble(key, value.toDouble())
132
+ is Boolean -> putBoolean(key, value)
133
+ else -> throw IllegalArgumentException("Could not put '${value.javaClass}' to WritableMap")
134
+ }
135
+ }
136
+
137
+ internal fun WritableArray.putGeneric(value: Any?) {
138
+ when (value) {
139
+ null, is Unit -> pushNull()
140
+ is ReadableArray -> pushArray(value)
141
+ is ReadableMap -> pushMap(value)
142
+ is String -> pushString(value)
143
+ is Int -> pushInt(value)
144
+ is Number -> pushDouble(value.toDouble())
145
+ is Boolean -> pushBoolean(value)
146
+ else -> throw IllegalArgumentException("Could not put '${value.javaClass}' to WritableArray")
147
+ }
148
+ }
@@ -35,6 +35,7 @@ fun convert(value: Dynamic, type: KType): Any? {
35
35
 
36
36
  object TypeConverterProviderImpl : TypeConverterProvider {
37
37
  private val cachedConverters = createCashedConverters(false) + createCashedConverters(true)
38
+ private val cachedRecordConverters = mutableMapOf<KClass<*>, TypeConverter<*>>()
38
39
 
39
40
  override fun obtainTypeConverter(type: KType): TypeConverter<*> {
40
41
  cachedConverters[type]?.let {
@@ -68,8 +69,15 @@ object TypeConverterProviderImpl : TypeConverterProvider {
68
69
  return EnumTypeConverter(kClass as KClass<Enum<*>>, type.isMarkedNullable)
69
70
  }
70
71
 
72
+ val cachedConverter = cachedRecordConverters[kClass]
73
+ if (cachedConverter != null) {
74
+ return cachedConverter
75
+ }
76
+
71
77
  if (kClass.isSubclassOf(Record::class)) {
72
- return RecordTypeConverter<Record>(this, type)
78
+ val converter = RecordTypeConverter<Record>(this, type)
79
+ cachedRecordConverters[kClass] = converter
80
+ return converter
73
81
  }
74
82
 
75
83
  throw MissingTypeConverter(type)
@@ -7,6 +7,7 @@ import com.facebook.react.common.MapBuilder
7
7
  import com.facebook.react.uimanager.ThemedReactContext
8
8
  import com.facebook.react.uimanager.ViewGroupManager
9
9
  import com.facebook.react.uimanager.annotations.ReactProp
10
+ import expo.modules.core.utilities.ifNull
10
11
 
11
12
  class GroupViewManagerWrapper(
12
13
  override val viewWrapperDelegate: ViewManagerWrapperDelegate
@@ -41,4 +42,52 @@ class GroupViewManagerWrapper(
41
42
 
42
43
  return super.getExportedCustomDirectEventTypeConstants()
43
44
  }
45
+
46
+ override fun addView(parent: ViewGroup, child: View, index: Int) {
47
+ viewWrapperDelegate
48
+ .viewGroupDefinition
49
+ ?.addViewAction
50
+ ?.invoke(parent, child, index)
51
+ .ifNull {
52
+ super.addView(parent, child, index)
53
+ }
54
+ }
55
+
56
+ override fun getChildCount(parent: ViewGroup): Int {
57
+ return viewWrapperDelegate.viewGroupDefinition
58
+ ?.getChildCountAction
59
+ ?.invoke(parent)
60
+ .ifNull {
61
+ super.getChildCount(parent)
62
+ }
63
+ }
64
+
65
+ override fun getChildAt(parent: ViewGroup, index: Int): View? {
66
+ viewWrapperDelegate.viewGroupDefinition
67
+ ?.getChildAtAction
68
+ ?.let {
69
+ return it.invoke(parent, index)
70
+ }
71
+ .ifNull {
72
+ return super.getChildAt(parent, index)
73
+ }
74
+ }
75
+
76
+ override fun removeViewAt(parent: ViewGroup, index: Int) {
77
+ viewWrapperDelegate.viewGroupDefinition
78
+ ?.removeViewAtAction
79
+ ?.invoke(parent, index)
80
+ .ifNull {
81
+ super.removeViewAt(parent, index)
82
+ }
83
+ }
84
+
85
+ override fun removeView(parent: ViewGroup, view: View) {
86
+ viewWrapperDelegate.viewGroupDefinition
87
+ ?.removeViewAction
88
+ ?.invoke(parent, view)
89
+ .ifNull {
90
+ super.removeView(parent, view)
91
+ }
92
+ }
44
93
  }
@@ -0,0 +1,18 @@
1
+ package expo.modules.kotlin.views
2
+
3
+ import android.view.View
4
+ import android.view.ViewGroup
5
+
6
+ class ViewGroupDefinition(
7
+ val addViewAction: AddViewAction?,
8
+ val getChildAtAction: GetChildAtAction?,
9
+ val getChildCountAction: GetChildCountAction?,
10
+ val removeViewAction: RemoveViewAction?,
11
+ val removeViewAtAction: RemoveViewAtAction?
12
+ )
13
+
14
+ internal typealias AddViewAction = (parent: ViewGroup, child: View, index: Int) -> Unit
15
+ internal typealias GetChildAtAction = (parent: ViewGroup, index: Int) -> View?
16
+ internal typealias GetChildCountAction = (parent: ViewGroup) -> Int
17
+ internal typealias RemoveViewAction = (parent: ViewGroup, childToRemove: View) -> Unit
18
+ internal typealias RemoveViewAtAction = (parent: ViewGroup, index: Int) -> Unit
@@ -0,0 +1,64 @@
1
+ @file:OptIn(ExperimentalStdlibApi::class)
2
+
3
+ package expo.modules.kotlin.views
4
+
5
+ import android.view.View
6
+ import android.view.ViewGroup
7
+ import expo.modules.kotlin.modules.DefinitionMarker
8
+
9
+ @DefinitionMarker
10
+ 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
16
+
17
+ fun build() = ViewGroupDefinition(
18
+ addViewAction,
19
+ getChildAtAction,
20
+ getChildCountAction,
21
+ removeViewAction,
22
+ removeViewAtAction
23
+ )
24
+
25
+ inline fun <reified ParentViewType : ViewGroup, reified ChildViewType : View> addChildView(
26
+ noinline body: (parent: ParentViewType, child: ChildViewType, index: Int) -> Unit
27
+ ) {
28
+ addViewAction = { parent, child, index ->
29
+ body(parent as ParentViewType, child as ChildViewType, index)
30
+ }
31
+ }
32
+
33
+ inline fun <reified ParentViewType : ViewGroup> getChildCount(
34
+ noinline body: (view: ParentViewType) -> Int
35
+ ) {
36
+ getChildCountAction = { view ->
37
+ body(view as ParentViewType)
38
+ }
39
+ }
40
+
41
+ inline fun <reified ParentViewType : ViewGroup, reified ChildViewType : View> getChildViewAt(
42
+ noinline body: (view: ParentViewType, index: Int) -> ChildViewType?
43
+ ) {
44
+ getChildAtAction = { view, index ->
45
+ body(view as ParentViewType, index)
46
+ }
47
+ }
48
+
49
+ inline fun <reified ParentViewType : ViewGroup> removeChildViewAt(
50
+ noinline body: (view: ParentViewType, index: Int) -> Unit
51
+ ) {
52
+ removeViewAtAction = { view, index ->
53
+ body(view as ParentViewType, index)
54
+ }
55
+ }
56
+
57
+ inline fun <reified ParentViewType : ViewGroup, reified ChildViewType : View> removeChildView(
58
+ noinline body: (parent: ParentViewType, child: ChildViewType) -> Unit
59
+ ) {
60
+ removeViewAction = { view, child ->
61
+ body(view as ParentViewType, child as ChildViewType)
62
+ }
63
+ }
64
+ }
@@ -17,11 +17,14 @@ class ViewManagerDefinition(
17
17
  private val viewType: Class<out View>,
18
18
  private val props: Map<String, AnyViewProp>,
19
19
  val onViewDestroys: ((View) -> Unit)? = null,
20
- val callbacksDefinition: CallbacksDefinition? = null
20
+ val callbacksDefinition: CallbacksDefinition? = null,
21
+ val viewGroupDefinition: ViewGroupDefinition? = null
21
22
  ) {
22
23
 
23
24
  fun createView(context: Context): View = viewFactory(context)
24
25
 
26
+ val propsNames: List<String> = props.keys.toList()
27
+
25
28
  fun getViewManagerType(): ViewManager.ViewManagerType {
26
29
  return if (ViewGroup::class.java.isAssignableFrom(viewType)) {
27
30
  ViewManager.ViewManagerType.GROUP
@@ -18,7 +18,8 @@ class ViewManagerDefinitionBuilder {
18
18
  internal var props = mutableMapOf<String, AnyViewProp>()
19
19
  @PublishedApi
20
20
  internal var onViewDestroys: ((View) -> Unit)? = null
21
-
21
+ @PublishedApi
22
+ internal var viewGroupDefinition: ViewGroupDefinition? = null
22
23
  private var callbacksDefinition: CallbacksDefinition? = null
23
24
 
24
25
  fun build(): ViewManagerDefinition =
@@ -27,7 +28,8 @@ class ViewManagerDefinitionBuilder {
27
28
  requireNotNull(viewType),
28
29
  props,
29
30
  onViewDestroys,
30
- callbacksDefinition
31
+ callbacksDefinition,
32
+ viewGroupDefinition
31
33
  )
32
34
 
33
35
  /**
@@ -65,4 +67,15 @@ class ViewManagerDefinitionBuilder {
65
67
  fun events(vararg callbacks: String) {
66
68
  callbacksDefinition = CallbacksDefinition(callbacks)
67
69
  }
70
+
71
+ /**
72
+ * Creates the group view definition that scopes group view-related definitions.
73
+ */
74
+ inline fun groupView(body: ViewGroupDefinitionBuilder.() -> Unit) {
75
+ require(viewGroupDefinition == null) { "The viewManager definition may have exported only one groupView definition." }
76
+
77
+ val groupViewDefinitionBuilder = ViewGroupDefinitionBuilder()
78
+ body.invoke(groupViewDefinitionBuilder)
79
+ viewGroupDefinition = groupViewDefinitionBuilder.build()
80
+ }
68
81
  }
@@ -15,6 +15,9 @@ class ViewManagerWrapperDelegate(internal var moduleHolder: ModuleHolder) {
15
15
  private val definition: ViewManagerDefinition
16
16
  get() = requireNotNull(moduleHolder.definition.viewManagerDefinition)
17
17
 
18
+ internal val viewGroupDefinition: ViewGroupDefinition?
19
+ get() = definition.viewGroupDefinition
20
+
18
21
  val name: String
19
22
  get() = moduleHolder.name
20
23
 
@@ -2,9 +2,5 @@ import { ProxyNativeModule } from './NativeModulesProxy.types';
2
2
  declare const NativeModulesProxy: {
3
3
  [moduleName: string]: ProxyNativeModule;
4
4
  };
5
- /**
6
- * Sets whether to use a TurboModule version of the proxy.
7
- */
8
- export declare function useExpoTurboModules(state?: boolean): void;
9
5
  export default NativeModulesProxy;
10
6
  //# sourceMappingURL=NativeModulesProxy.native.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NativeModulesProxy.native.d.ts","sourceRoot":"","sources":["../src/NativeModulesProxy.native.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAA0B,MAAM,4BAA4B,CAAC;AAWvF,QAAA,MAAM,kBAAkB,EAAE;IAAE,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAAA;CAAO,CAAC;AAK3E;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,GAAE,OAAc,QAExD;AAuDD,eAAe,kBAAkB,CAAC"}
1
+ {"version":3,"file":"NativeModulesProxy.native.d.ts","sourceRoot":"","sources":["../src/NativeModulesProxy.native.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAM/D,QAAA,MAAM,kBAAkB,EAAE;IAAE,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAAA;CAAO,CAAC;AAkD3E,eAAe,kBAAkB,CAAC"}
@@ -3,14 +3,6 @@ const NativeProxy = NativeModules.NativeUnimoduleProxy;
3
3
  const modulesConstantsKey = 'modulesConstants';
4
4
  const exportedMethodsKey = 'exportedMethods';
5
5
  const NativeModulesProxy = {};
6
- // Keep it opt-in for now. It's too risky without proper and thorough testing.
7
- let canUseExpoTurboModules = false;
8
- /**
9
- * Sets whether to use a TurboModule version of the proxy.
10
- */
11
- export function useExpoTurboModules(state = true) {
12
- canUseExpoTurboModules = state;
13
- }
14
6
  if (NativeProxy) {
15
7
  Object.keys(NativeProxy[exportedMethodsKey]).forEach((moduleName) => {
16
8
  NativeModulesProxy[moduleName] = NativeProxy[modulesConstantsKey][moduleName] || {};
@@ -20,12 +12,7 @@ if (NativeProxy) {
20
12
  if (argumentsCount !== args.length) {
21
13
  return Promise.reject(new Error(`Native method ${moduleName}.${methodInfo.name} expects ${argumentsCount} ${argumentsCount === 1 ? 'argument' : 'arguments'} but received ${args.length}`));
22
14
  }
23
- if (canUseExpoTurboModules && global.ExpoModulesProxy) {
24
- return global.ExpoModulesProxy.callMethodAsync(moduleName, methodInfo.name, args);
25
- }
26
- else {
27
- return NativeProxy.callMethod(moduleName, key, args);
28
- }
15
+ return NativeProxy.callMethod(moduleName, key, args);
29
16
  };
30
17
  });
31
18
  // These are called by EventEmitter (which is a wrapper for NativeEventEmitter)
@@ -1 +1 @@
1
- {"version":3,"file":"NativeModulesProxy.native.js","sourceRoot":"","sources":["../src/NativeModulesProxy.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAS7C,MAAM,WAAW,GAAG,aAAa,CAAC,oBAAoB,CAAC;AACvD,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAC/C,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAE7C,MAAM,kBAAkB,GAAgD,EAAE,CAAC;AAE3E,8EAA8E;AAC9E,IAAI,sBAAsB,GAAG,KAAK,CAAC;AAEnC;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAiB,IAAI;IACvD,sBAAsB,GAAG,KAAK,CAAC;AACjC,CAAC;AAED,IAAI,WAAW,EAAE;IACf,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAClE,kBAAkB,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACpF,WAAW,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;YACjE,kBAAkB,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAe,EAAgB,EAAE;gBACrF,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,UAAU,CAAC;gBAC3C,IAAI,cAAc,KAAK,IAAI,CAAC,MAAM,EAAE;oBAClC,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,iBAAiB,UAAU,IAAI,UAAU,CAAC,IAAI,YAAY,cAAc,IACtE,cAAc,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WACtC,iBAAiB,IAAI,CAAC,MAAM,EAAE,CAC/B,CACF,CAAC;iBACH;gBAED,IAAI,sBAAsB,IAAI,MAAM,CAAC,gBAAgB,EAAE;oBACrD,OAAO,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;iBACnF;qBAAM;oBACL,OAAO,WAAW,CAAC,UAAU,CAAC,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;iBACtD;YACH,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,+EAA+E;QAC/E,kFAAkF;QAClF,EAAE;QACF,wEAAwE;QACxE,gDAAgD;QAChD,EAAE;QACF,6GAA6G;QAC7G,gGAAgG;QAChG,4HAA4H;QAC5H,qCAAqC;QACrC,IAAI,aAAa,CAAC,yBAAyB,EAAE;YAC3C,kBAAkB,CAAC,UAAU,CAAC,CAAC,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CACvD,aAAa,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;YAClF,kBAAkB,CAAC,UAAU,CAAC,CAAC,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAC3D,aAAa,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;SACvF;aAAM;YACL,oBAAoB;YACpB,kHAAkH;YAClH,sHAAsH;YACtH,kBAAkB,CAAC,UAAU,CAAC,CAAC,WAAW,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;YACtD,kBAAkB,CAAC,UAAU,CAAC,CAAC,eAAe,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;SAC3D;IACH,CAAC,CAAC,CAAC;CACJ;KAAM;IACL,OAAO,CAAC,IAAI,CACV,gJAAgJ,CACjJ,CAAC;CACH;AAED,eAAe,kBAAkB,CAAC","sourcesContent":["import { NativeModules } from 'react-native';\n\nimport { ProxyNativeModule, TurboNativeModuleProxy } from './NativeModulesProxy.types';\n\n// `ExpoModulesProxy` is not declared in TypeScript yet. It's installed via JSI.\ndeclare namespace global {\n const ExpoModulesProxy: TurboNativeModuleProxy;\n}\n\nconst NativeProxy = NativeModules.NativeUnimoduleProxy;\nconst modulesConstantsKey = 'modulesConstants';\nconst exportedMethodsKey = 'exportedMethods';\n\nconst NativeModulesProxy: { [moduleName: string]: ProxyNativeModule } = {};\n\n// Keep it opt-in for now. It's too risky without proper and thorough testing.\nlet canUseExpoTurboModules = false;\n\n/**\n * Sets whether to use a TurboModule version of the proxy.\n */\nexport function useExpoTurboModules(state: boolean = true) {\n canUseExpoTurboModules = state;\n}\n\nif (NativeProxy) {\n Object.keys(NativeProxy[exportedMethodsKey]).forEach((moduleName) => {\n NativeModulesProxy[moduleName] = NativeProxy[modulesConstantsKey][moduleName] || {};\n NativeProxy[exportedMethodsKey][moduleName].forEach((methodInfo) => {\n NativeModulesProxy[moduleName][methodInfo.name] = (...args: unknown[]): Promise<any> => {\n const { key, argumentsCount } = methodInfo;\n if (argumentsCount !== args.length) {\n return Promise.reject(\n new Error(\n `Native method ${moduleName}.${methodInfo.name} expects ${argumentsCount} ${\n argumentsCount === 1 ? 'argument' : 'arguments'\n } but received ${args.length}`\n )\n );\n }\n\n if (canUseExpoTurboModules && global.ExpoModulesProxy) {\n return global.ExpoModulesProxy.callMethodAsync(moduleName, methodInfo.name, args);\n } else {\n return NativeProxy.callMethod(moduleName, key, args);\n }\n };\n });\n\n // These are called by EventEmitter (which is a wrapper for NativeEventEmitter)\n // only on iOS and they use iOS-specific native module, EXReactNativeEventEmitter.\n //\n // On Android only {start,stop}Observing are called on the native module\n // and these should be exported as Expo methods.\n //\n // Before the RN 65, addListener/removeListeners weren't called on Android. However, it no longer stays true.\n // See https://github.com/facebook/react-native/commit/f5502fbda9fe271ff6e1d0da773a3a8ee206a453.\n // That's why, we check if the `EXReactNativeEventEmitter` exists and only if yes, we use it in the listener implementation.\n // Otherwise, those methods are NOOP.\n if (NativeModules.EXReactNativeEventEmitter) {\n NativeModulesProxy[moduleName].addListener = (...args) =>\n NativeModules.EXReactNativeEventEmitter.addProxiedListener(moduleName, ...args);\n NativeModulesProxy[moduleName].removeListeners = (...args) =>\n NativeModules.EXReactNativeEventEmitter.removeProxiedListeners(moduleName, ...args);\n } else {\n // Fixes on Android:\n // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.\n // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.\n NativeModulesProxy[moduleName].addListener = () => {};\n NativeModulesProxy[moduleName].removeListeners = () => {};\n }\n });\n} else {\n console.warn(\n `The \"EXNativeModulesProxy\" native module is not exported through NativeModules; verify that expo-modules-core's native code is linked properly`\n );\n}\n\nexport default NativeModulesProxy;\n"]}
1
+ {"version":3,"file":"NativeModulesProxy.native.js","sourceRoot":"","sources":["../src/NativeModulesProxy.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,MAAM,WAAW,GAAG,aAAa,CAAC,oBAAoB,CAAC;AACvD,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAC/C,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAE7C,MAAM,kBAAkB,GAAgD,EAAE,CAAC;AAE3E,IAAI,WAAW,EAAE;IACf,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAClE,kBAAkB,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACpF,WAAW,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;YACjE,kBAAkB,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAe,EAAgB,EAAE;gBACrF,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,UAAU,CAAC;gBAC3C,IAAI,cAAc,KAAK,IAAI,CAAC,MAAM,EAAE;oBAClC,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,iBAAiB,UAAU,IAAI,UAAU,CAAC,IAAI,YAAY,cAAc,IACtE,cAAc,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WACtC,iBAAiB,IAAI,CAAC,MAAM,EAAE,CAC/B,CACF,CAAC;iBACH;gBACD,OAAO,WAAW,CAAC,UAAU,CAAC,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YACvD,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,+EAA+E;QAC/E,kFAAkF;QAClF,EAAE;QACF,wEAAwE;QACxE,gDAAgD;QAChD,EAAE;QACF,6GAA6G;QAC7G,gGAAgG;QAChG,4HAA4H;QAC5H,qCAAqC;QACrC,IAAI,aAAa,CAAC,yBAAyB,EAAE;YAC3C,kBAAkB,CAAC,UAAU,CAAC,CAAC,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CACvD,aAAa,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;YAClF,kBAAkB,CAAC,UAAU,CAAC,CAAC,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAC3D,aAAa,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;SACvF;aAAM;YACL,oBAAoB;YACpB,kHAAkH;YAClH,sHAAsH;YACtH,kBAAkB,CAAC,UAAU,CAAC,CAAC,WAAW,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;YACtD,kBAAkB,CAAC,UAAU,CAAC,CAAC,eAAe,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;SAC3D;IACH,CAAC,CAAC,CAAC;CACJ;KAAM;IACL,OAAO,CAAC,IAAI,CACV,gJAAgJ,CACjJ,CAAC;CACH;AAED,eAAe,kBAAkB,CAAC","sourcesContent":["import { NativeModules } from 'react-native';\n\nimport { ProxyNativeModule } from './NativeModulesProxy.types';\n\nconst NativeProxy = NativeModules.NativeUnimoduleProxy;\nconst modulesConstantsKey = 'modulesConstants';\nconst exportedMethodsKey = 'exportedMethods';\n\nconst NativeModulesProxy: { [moduleName: string]: ProxyNativeModule } = {};\n\nif (NativeProxy) {\n Object.keys(NativeProxy[exportedMethodsKey]).forEach((moduleName) => {\n NativeModulesProxy[moduleName] = NativeProxy[modulesConstantsKey][moduleName] || {};\n NativeProxy[exportedMethodsKey][moduleName].forEach((methodInfo) => {\n NativeModulesProxy[moduleName][methodInfo.name] = (...args: unknown[]): Promise<any> => {\n const { key, argumentsCount } = methodInfo;\n if (argumentsCount !== args.length) {\n return Promise.reject(\n new Error(\n `Native method ${moduleName}.${methodInfo.name} expects ${argumentsCount} ${\n argumentsCount === 1 ? 'argument' : 'arguments'\n } but received ${args.length}`\n )\n );\n }\n return NativeProxy.callMethod(moduleName, key, args);\n };\n });\n\n // These are called by EventEmitter (which is a wrapper for NativeEventEmitter)\n // only on iOS and they use iOS-specific native module, EXReactNativeEventEmitter.\n //\n // On Android only {start,stop}Observing are called on the native module\n // and these should be exported as Expo methods.\n //\n // Before the RN 65, addListener/removeListeners weren't called on Android. However, it no longer stays true.\n // See https://github.com/facebook/react-native/commit/f5502fbda9fe271ff6e1d0da773a3a8ee206a453.\n // That's why, we check if the `EXReactNativeEventEmitter` exists and only if yes, we use it in the listener implementation.\n // Otherwise, those methods are NOOP.\n if (NativeModules.EXReactNativeEventEmitter) {\n NativeModulesProxy[moduleName].addListener = (...args) =>\n NativeModules.EXReactNativeEventEmitter.addProxiedListener(moduleName, ...args);\n NativeModulesProxy[moduleName].removeListeners = (...args) =>\n NativeModules.EXReactNativeEventEmitter.removeProxiedListeners(moduleName, ...args);\n } else {\n // Fixes on Android:\n // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.\n // WARN `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.\n NativeModulesProxy[moduleName].addListener = () => {};\n NativeModulesProxy[moduleName].removeListeners = () => {};\n }\n });\n} else {\n console.warn(\n `The \"EXNativeModulesProxy\" native module is not exported through NativeModules; verify that expo-modules-core's native code is linked properly`\n );\n}\n\nexport default NativeModulesProxy;\n"]}
@@ -3,7 +3,4 @@ export declare type ProxyNativeModule = {
3
3
  addListener: (eventName: string) => void;
4
4
  removeListeners: (count: number) => void;
5
5
  };
6
- export declare type TurboNativeModuleProxy = {
7
- callMethodAsync: <ReturnType>(moduleName: string, methodName: string, args: any[]) => Promise<ReturnType>;
8
- };
9
6
  //# sourceMappingURL=NativeModulesProxy.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NativeModulesProxy.types.d.ts","sourceRoot":"","sources":["../src/NativeModulesProxy.types.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB,GAAG;IAC9B,CAAC,YAAY,EAAE,MAAM,GAAG,GAAG,CAAC;IAC5B,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1C,CAAC;AAEF,oBAAY,sBAAsB,GAAG;IACnC,eAAe,EAAE,CAAC,UAAU,EAC1B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,GAAG,EAAE,KACR,OAAO,CAAC,UAAU,CAAC,CAAC;CAC1B,CAAC"}
1
+ {"version":3,"file":"NativeModulesProxy.types.d.ts","sourceRoot":"","sources":["../src/NativeModulesProxy.types.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB,GAAG;IAC9B,CAAC,YAAY,EAAE,MAAM,GAAG,GAAG,CAAC;IAC5B,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1C,CAAC"}