Skip to content

Commit

Permalink
Revert "[modules-core][android] Use getter methods in convertibles (#…
Browse files Browse the repository at this point in the history
…30239)"

This reverts commit baa2c53.
  • Loading branch information
gabrieldonadel committed Jul 20, 2024
1 parent 6165c7d commit 66762ea
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 19 deletions.
1 change: 0 additions & 1 deletion packages/expo-modules-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

### 💡 Others

- [Android] Use getter methods in convertibles. ([#30239](https://github.com/expo/expo/pull/30239) by [@gabrieldonadel](https://github.com/gabrieldonadel))
- Change `sideEffects` to use `src` folder. ([#29964](https://github.com/expo/expo/pull/29964) by [@EvanBacon](https://github.com/EvanBacon))
- [web] Use global `crypto` object for UUID. ([#29828](https://github.com/expo/expo/pull/29828) by [@EvanBacon](https://github.com/EvanBacon))
- [iOS] Send open url event to all matching subscribers. ([#29645](https://github.com/expo/expo/pull/29645) by [@aleqsio](https://github.com/aleqsio))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FabricComponentsRegistry(viewManagerList: List<ViewManager<*, *>>) {
private val mHybridData: HybridData

init {
componentNames = viewManagerList.map { it.getName() }
componentNames = viewManagerList.map { it.name }
mHybridData = initHybrid()
registerComponentsRegistry(componentNames.toTypedArray())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ abstract class AnyFunction(
val desiredType = desiredArgsTypes[index]
argIterator.next().recycle {
exceptionDecorator({ cause ->
ArgumentCastException(desiredType.kType, index, getType().toString(), cause)
ArgumentCastException(desiredType.kType, index, type.toString(), cause)
}) {
finalArgs[index] = desiredType.convert(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class RecordTypeConverter<T : Record>(
jsMap.getDynamic(jsKey).recycle {
val javaField = property.javaField!!

val casted = exceptionDecorator({ cause -> FieldCastException(property.name, property.returnType, getType(), cause) }) {
val casted = exceptionDecorator({ cause -> FieldCastException(property.name, property.returnType, type, cause) }) {
descriptor.typeConverter.convert(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import expo.modules.kotlin.jni.ExpectedType
*/
class AnyTypeConverter(isOptional: Boolean) : DynamicAwareTypeConverters<Any>(isOptional) {
override fun convertFromDynamic(value: Dynamic): Any {
return when (value.getType()) {
return when (value.type) {
ReadableType.Boolean -> value.asBoolean()
ReadableType.Number -> value.asDouble()
ReadableType.String -> value.asString()
ReadableType.Map -> value.asMap().toHashMap()
ReadableType.Array -> value.asArray().toArrayList()
else -> error("Unknown dynamic type: ${value.getType()}")
else -> error("Unknown dynamic type: ${value.type}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ArrayTypeConverter(
.getDynamic(i)
.recycle {
exceptionDecorator({ cause ->
CollectionElementCastException(arrayType, arrayType.arguments.first().type!!, getType(), cause)
CollectionElementCastException(arrayType, arrayType.arguments.first().type!!, type, cause)
}) {
arrayElementConverter.convert(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ class ColorTypeConverter(
isOptional: Boolean
) : DynamicAwareTypeConverters<Color>(isOptional) {
override fun convertFromDynamic(value: Dynamic): Color {
return when (value.getType()) {
return when (value.type) {
ReadableType.Number -> colorFromInt(value.asDouble().toInt())
ReadableType.String -> colorFromString(value.asString())
ReadableType.Array -> {
val colorsArray = value.asArray().toArrayList().map { it as Double }.toDoubleArray()
colorFromDoubleArray(colorsArray)
}
else -> throw UnexpectedException("Unknown argument type: ${value.getType()}")
else -> throw UnexpectedException("Unknown argument type: ${value.type}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import java.time.format.DateTimeFormatter
@RequiresApi(Build.VERSION_CODES.O)
class DateTypeConverter(isOptional: Boolean) : DynamicAwareTypeConverters<LocalDate>(isOptional) {
override fun convertFromDynamic(value: Dynamic): LocalDate {
return when (value.getType()) {
return when (value.type) {
ReadableType.String -> LocalDate.parse(value.asString(), DateTimeFormatter.ISO_DATE_TIME)
ReadableType.Number -> convertFromLong(value.asDouble().toLong())
else -> throw UnexpectedException("Unknown argument type: ${value.getType()}")
else -> throw UnexpectedException("Unknown argument type: ${value.type}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class EnumTypeConverter(
)
}

throw IncompatibleArgTypeException(value.getType().toKType(), enumClass.createType())
throw IncompatibleArgTypeException(value.type.toKType(), enumClass.createType())
}

override fun convertFromAny(value: Any): Enum<*> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ListTypeConverter(
CollectionElementCastException(
listType,
listType.arguments.first().type!!,
getType(),
type,
cause
)
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class MapTypeConverter(
private fun convertFromReadableMap(jsMap: ReadableMap): Map<*, *> {
val result = mutableMapOf<String, Any?>()

jsMap.getEntryIterator().forEach { (key, value) ->
jsMap.entryIterator.forEach { (key, value) ->
DynamicFromObject(value).recycle {
exceptionDecorator({ cause ->
CollectionElementCastException(mapType, mapType.arguments[1].type!!, getType(), cause)
CollectionElementCastException(mapType, mapType.arguments[1].type!!, type, cause)
}) {
result[key] = valueConverter.convert(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PairTypeConverter(
private fun convertElement(array: ReadableArray, index: Int): Any? {
return array.getDynamic(index).recycle {
exceptionDecorator({ cause ->
CollectionElementCastException(pairType, pairType.arguments[index].type!!, getType(), cause)
CollectionElementCastException(pairType, pairType.arguments[index].type!!, type, cause)
}) {
converters[index].convert(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SetTypeConverter(
CollectionElementCastException(
setType,
setType.arguments.first().type!!,
getType(),
type,
cause
)
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class NullAwareTypeConverter<Type : Any>(
private val isOptional: Boolean
) : TypeConverter<Type>() {
override fun convert(value: Any?, context: AppContext?): Type? {
if (value == null || value is Dynamic && value.isNull()) {
if (value == null || value is Dynamic && value.isNull) {
if (isOptional) {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FilteredReadableMap(
private val filteredKeys: List<String>
) : ReadableMap by backingMap {
override fun getEntryIterator(): Iterator<Map.Entry<String, Any>> =
FilteredIterator(backingMap.getEntryIterator()) {
FilteredIterator(backingMap.entryIterator) {
!filteredKeys.contains(it.key)
}

Expand Down

0 comments on commit 66762ea

Please sign in to comment.