Skip to content

Instantly share code, notes, and snippets.

@dilrajsingh1997
Created December 2, 2021 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dilrajsingh1997/95f76326ad9a90f47cc8988a44c4a1c2 to your computer and use it in GitHub Desktop.
Save dilrajsingh1997/95f76326ad9a90f47cc8988a44c4a1c2 to your computer and use it in GitHub Desktop.
composeArgumentType = when (resolvedClassDeclarationName) {
"Boolean" -> ComposeArgumentType.BOOLEAN
"String" -> ComposeArgumentType.STRING
"Float" -> ComposeArgumentType.FLOAT
"Int" -> ComposeArgumentType.INT
"Long" -> ComposeArgumentType.LONG
"IntArray" -> ComposeArgumentType.INT_ARRAY
"BooleanArray" -> ComposeArgumentType.BOOLEAN_ARRAY
"LongArray" -> ComposeArgumentType.LONG_ARRAY
"FloatArray" -> ComposeArgumentType.FLOAT_ARRAY
else -> when {
resolvedClassQualifiedName == "kotlin.collections.ArrayList" -> {
var isParcelable = false
var isSerializable = false
for (argument in typeArguments) {
val resolvedArgument = argument.type?.resolve()
if ((resolvedArgument?.declaration as? KSClassDeclaration)?.superTypes?.map { it.toString() }
?.contains("Parcelable") == true) {
isParcelable = true
}
if ((resolvedArgument?.declaration as? KSClassDeclaration)?.superTypes?.map { it.toString() }
?.contains("Serializable") == true) {
isSerializable = true
}
}
if (isParcelable) {
ComposeArgumentType.PARCELABLE_ARRAY
} else if (isSerializable) {
ComposeArgumentType.SERIALIZABLE
} else {
logger.error(
"invalid property type, cannot pass it in bundle",
property
)
return null
}
}
(resolvedType.declaration as KSClassDeclaration).superTypes.map { it.toString() }
.contains("Parcelable") -> {
ComposeArgumentType.PARCELABLE
}
(resolvedType.declaration as KSClassDeclaration).superTypes.map { it.toString() }
.contains("Serializable") -> {
ComposeArgumentType.SERIALIZABLE
}
else -> {
logger.error(
"invalid property type, cannot pass it in bundle",
property
)
return null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment