expo-modules-core 3.0.12 → 3.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,12 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 3.0.13 — 2025-09-04
14
+
15
+ ### 💡 Others
16
+
17
+ - [Android] Remove some usage of `kotlin.reflect.full.*`. ([#39385](https://github.com/expo/expo/pull/39385) by [@lukmccall](https://github.com/lukmccall))
18
+
13
19
  ## 3.0.12 — 2025-09-03
14
20
 
15
21
  ### 💡 Others
@@ -25,7 +25,7 @@ if (shouldIncludeCompose) {
25
25
  }
26
26
 
27
27
  group = 'host.exp.exponent'
28
- version = '3.0.12'
28
+ version = '3.0.13'
29
29
 
30
30
  def isExpoModulesCoreTests = {
31
31
  Gradle gradle = getGradle()
@@ -75,7 +75,7 @@ android {
75
75
  defaultConfig {
76
76
  consumerProguardFiles 'proguard-rules.pro'
77
77
  versionCode 1
78
- versionName "3.0.12"
78
+ versionName "3.0.13"
79
79
  buildConfigField "String", "EXPO_MODULES_CORE_VERSION", "\"${versionName}\""
80
80
  buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled.toString()
81
81
 
@@ -1,13 +1,12 @@
1
- package expo.modules.kotlin.modules
1
+ package expo.modules.kotlin
2
2
 
3
3
  import expo.modules.kotlin.types.Enumerable
4
4
  import kotlin.reflect.KProperty1
5
5
  import kotlin.reflect.full.declaredMemberProperties
6
- import kotlin.reflect.full.primaryConstructor
7
6
 
8
- internal fun <T> convertEnumToString(enumValue: T): String where T : Enumerable, T : Enum<T> {
9
- val enumClass = enumValue::class
10
- val primaryConstructor = enumClass.primaryConstructor
7
+ fun <T> T.convertToString(): String where T : Enum<T>, T : Enumerable {
8
+ val enumClass = this::class
9
+ val primaryConstructor = enumClass.fastPrimaryConstructor
11
10
  if (primaryConstructor?.parameters?.size == 1) {
12
11
  val parameterName = primaryConstructor.parameters.first().name
13
12
  val parameterProperty = enumClass
@@ -18,8 +17,8 @@ internal fun <T> convertEnumToString(enumValue: T): String where T : Enumerable,
18
17
  require(parameterProperty.returnType.classifier == String::class) { "The enum parameter has to be a string." }
19
18
 
20
19
  @Suppress("UNCHECKED_CAST")
21
- return (parameterProperty as KProperty1<T, String>).get(enumValue)
20
+ return (parameterProperty as KProperty1<T, String>).get(this)
22
21
  }
23
22
 
24
- return enumValue.name
23
+ return this.name
25
24
  }
@@ -0,0 +1,10 @@
1
+ package expo.modules.kotlin
2
+
3
+ import kotlin.reflect.KClass
4
+ import kotlin.reflect.KFunction
5
+ import kotlin.reflect.full.primaryConstructor
6
+
7
+ val <T : Any> KClass<T>.fastPrimaryConstructor: KFunction<T>?
8
+ // If class only has one constructor, use it as a primary constructor.
9
+ // Otherwise, try to find the primary constructor using kotlin reflection.
10
+ get() = constructors.singleOrNull() ?: primaryConstructor
@@ -3,16 +3,15 @@ package expo.modules.kotlin
3
3
  import com.facebook.react.bridge.ReadableArray
4
4
  import com.facebook.react.bridge.ReadableMap
5
5
  import com.facebook.react.bridge.ReadableType
6
- import kotlin.reflect.KType
7
- import kotlin.reflect.full.createType
6
+ import kotlin.reflect.KClass
8
7
 
9
- fun ReadableType.toKType(): KType {
8
+ fun ReadableType.toKClass(): KClass<*> {
10
9
  return when (this) {
11
- ReadableType.Null -> Any::class.createType(nullable = true)
12
- ReadableType.Boolean -> Boolean::class.createType()
13
- ReadableType.Number -> Number::class.createType()
14
- ReadableType.String -> String::class.createType()
15
- ReadableType.Map -> ReadableMap::class.createType()
16
- ReadableType.Array -> ReadableArray::class.createType()
10
+ ReadableType.Null -> Any::class
11
+ ReadableType.Boolean -> Boolean::class
12
+ ReadableType.Number -> Number::class
13
+ ReadableType.String -> String::class
14
+ ReadableType.Map -> ReadableMap::class
15
+ ReadableType.Array -> ReadableArray::class
17
16
  }
18
17
  }
@@ -71,8 +71,8 @@ inline fun <reified T : CodedException> errorCodeOf(): String =
71
71
  CodedException.inferCode(T::class.java)
72
72
 
73
73
  internal class IncompatibleArgTypeException(
74
- argumentType: KType,
75
- desiredType: KType,
74
+ argumentType: KClass<*>,
75
+ desiredType: KClass<*>,
76
76
  cause: Throwable? = null
77
77
  ) : CodedException(
78
78
  message = "Argument type '$argumentType' is not compatible with expected type '$desiredType'.",
@@ -3,6 +3,7 @@ package expo.modules.kotlin.modules
3
3
  import android.os.Bundle
4
4
  import expo.modules.kotlin.AppContext
5
5
  import expo.modules.kotlin.RuntimeContext
6
+ import expo.modules.kotlin.convertToString
6
7
  import expo.modules.kotlin.providers.AppContextProvider
7
8
  import expo.modules.kotlin.tracing.trace
8
9
  import expo.modules.kotlin.types.Enumerable
@@ -44,11 +45,11 @@ abstract class Module : AppContextProvider {
44
45
  }
45
46
 
46
47
  fun <T> sendEvent(enum: T, body: Bundle? = Bundle.EMPTY) where T : Enumerable, T : Enum<T> {
47
- moduleEventEmitter?.emit(convertEnumToString(enum), body)
48
+ moduleEventEmitter?.emit(enum.convertToString(), body)
48
49
  }
49
50
 
50
51
  fun <T> sendEvent(enum: T, body: Map<String, Any?>? = null) where T : Enumerable, T : Enum<T> {
51
- moduleEventEmitter?.emit(convertEnumToString(enum), body)
52
+ moduleEventEmitter?.emit(enum.convertToString(), body)
52
53
  }
53
54
 
54
55
  open fun converters(): TypeConverterProvider? = null
@@ -7,7 +7,9 @@ import expo.modules.kotlin.Promise
7
7
  import expo.modules.kotlin.component6
8
8
  import expo.modules.kotlin.component7
9
9
  import expo.modules.kotlin.component8
10
+ import expo.modules.kotlin.convertToString
10
11
  import expo.modules.kotlin.events.EventsDefinition
12
+ import expo.modules.kotlin.fastPrimaryConstructor
11
13
  import expo.modules.kotlin.functions.AsyncFunctionComponent
12
14
  import expo.modules.kotlin.functions.AsyncFunctionBuilder
13
15
  import expo.modules.kotlin.functions.AsyncFunctionWithPromiseComponent
@@ -18,14 +20,12 @@ import expo.modules.kotlin.jni.JavaScriptModuleObject
18
20
  import expo.modules.kotlin.jni.decorators.JSDecoratorsBridgingObject
19
21
  import expo.modules.kotlin.modules.Module
20
22
  import expo.modules.kotlin.modules.ModuleDefinitionBuilder
21
- import expo.modules.kotlin.modules.convertEnumToString
22
23
  import expo.modules.kotlin.types.Enumerable
23
24
  import expo.modules.kotlin.types.TypeConverterProvider
24
25
  import expo.modules.kotlin.types.enforceType
25
26
  import expo.modules.kotlin.types.toArgsArray
26
27
  import expo.modules.kotlin.types.toReturnType
27
28
  import kotlin.reflect.full.declaredMemberProperties
28
- import kotlin.reflect.full.primaryConstructor
29
29
 
30
30
  /**
31
31
  * Base class for other definitions representing an object, such as `ModuleDefinition`.
@@ -449,7 +449,7 @@ open class ObjectDefinitionBuilder(
449
449
  }
450
450
 
451
451
  inline fun <reified T> Events() where T : Enumerable, T : Enum<T> {
452
- val primaryConstructor = T::class.primaryConstructor
452
+ val primaryConstructor = T::class.fastPrimaryConstructor
453
453
  val events = if (primaryConstructor?.parameters?.size == 1) {
454
454
  val parameterName = primaryConstructor.parameters.first().name
455
455
 
@@ -487,7 +487,7 @@ open class ObjectDefinitionBuilder(
487
487
  * Creates module's lifecycle listener that is called right after the first event listener is added for given event.
488
488
  */
489
489
  fun <T> OnStartObserving(enum: T, body: () -> Unit) where T : Enumerable, T : Enum<T> {
490
- OnStartObserving(convertEnumToString(enum), body)
490
+ OnStartObserving(enum.convertToString(), body)
491
491
  }
492
492
 
493
493
  /**
@@ -520,7 +520,7 @@ open class ObjectDefinitionBuilder(
520
520
  * Creates module's lifecycle listener that is called right after all event listeners are removed for given event.
521
521
  */
522
522
  fun <T> OnStopObserving(enum: T, body: () -> Unit) where T : Enumerable, T : Enum<T> {
523
- OnStopObserving(convertEnumToString(enum), body)
523
+ OnStopObserving(enum.convertToString(), body)
524
524
  }
525
525
 
526
526
  /**
@@ -10,7 +10,6 @@ import expo.modules.kotlin.types.NonNullableTypeConverter
10
10
  import kotlin.reflect.KClass
11
11
  import kotlin.reflect.KType
12
12
  import kotlin.reflect.KTypeProjection
13
- import kotlin.reflect.full.isSuperclassOf
14
13
 
15
14
  class SharedObjectTypeConverter<T : SharedObject>(
16
15
  val type: KType
@@ -74,7 +73,7 @@ class SharedRefTypeConverter<T : SharedRef<*>>(
74
73
  val ref = sharedRef.ref ?: return sharedRef
75
74
  val sharedRefClass = sharedRefType?.classifier as? KClass<*>
76
75
  ?: return sharedRef
77
- if (sharedRefClass.isSuperclassOf(ref.javaClass.kotlin)) {
76
+ if (ref::class.java.isAssignableFrom(sharedRefClass.javaObjectType) || ref::class.java.isAssignableFrom(sharedRefClass.java)) {
78
77
  return sharedRef
79
78
  }
80
79
 
@@ -5,12 +5,11 @@ import expo.modules.kotlin.AppContext
5
5
  import expo.modules.kotlin.exception.DynamicCastException
6
6
  import expo.modules.kotlin.exception.EnumNoSuchValueException
7
7
  import expo.modules.kotlin.exception.IncompatibleArgTypeException
8
+ import expo.modules.kotlin.fastPrimaryConstructor
8
9
  import expo.modules.kotlin.jni.ExpectedType
9
10
  import expo.modules.kotlin.logger
10
- import expo.modules.kotlin.toKType
11
+ import expo.modules.kotlin.toKClass
11
12
  import kotlin.reflect.KClass
12
- import kotlin.reflect.full.createType
13
- import kotlin.reflect.full.primaryConstructor
14
13
 
15
14
  class EnumTypeConverter(
16
15
  private val enumClass: KClass<Enum<*>>
@@ -23,7 +22,9 @@ class EnumTypeConverter(
23
22
  }
24
23
  }
25
24
 
26
- private val primaryConstructor = requireNotNull(enumClass.primaryConstructor) {
25
+ private val primaryConstructor = requireNotNull(
26
+ enumClass.fastPrimaryConstructor
27
+ ) {
27
28
  "Cannot convert js value to enum without the primary constructor"
28
29
  }
29
30
 
@@ -48,7 +49,7 @@ class EnumTypeConverter(
48
49
  )
49
50
  }
50
51
 
51
- throw IncompatibleArgTypeException(value.type.toKType(), enumClass.createType())
52
+ throw IncompatibleArgTypeException(value.type.toKClass(), enumClass)
52
53
  }
53
54
 
54
55
  override fun convertFromAny(value: Any, context: AppContext?, forceConversion: Boolean): Enum<*> {
@@ -62,7 +63,7 @@ class EnumTypeConverter(
62
63
  )
63
64
  }
64
65
 
65
- throw IncompatibleArgTypeException(value::class.createType(), enumClass.createType())
66
+ throw IncompatibleArgTypeException(value::class, enumClass)
66
67
  }
67
68
 
68
69
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-modules-core",
3
- "version": "3.0.12",
3
+ "version": "3.0.13",
4
4
  "description": "The core of Expo Modules architecture",
5
5
  "main": "src/index.ts",
6
6
  "types": "build/index.d.ts",
@@ -65,5 +65,5 @@
65
65
  "@testing-library/react-native": "^13.2.0",
66
66
  "expo-module-scripts": "^5.0.6"
67
67
  },
68
- "gitHead": "f97e6d1cae0cb14d5eed1b08fad6d12a7144af3a"
68
+ "gitHead": "8cafaff8076e443e6c80e8013ec809f4f290f24d"
69
69
  }