John O'Reilly
07/26/2024, 9:15 AMDrawableResource
dynamically when using CMP shared resources. For example I want to create flagResource
based on some country code I have.
Image(
painterResource(flagResource),
modifier = Modifier.size(32.dp),
contentDescription = country.displayName
)
On Android I was using
val flagResourceId = context.resources.getIdentifier(
"flag_${country.code",
"drawable",context.packageName)
John O'Reilly
07/26/2024, 9:37 AM@OptIn(InternalResourceApi::class)
private fun getDrawable(id: String): DrawableResource =
DrawableResource(
"drawable:$id",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(),
"composeResources/bikeshare.common.generated.resources/drawable/$id.xml", -1, -1),
)
)
John O'Reilly
07/26/2024, 9:38 AMKonstantin Tskhovrebov
07/26/2024, 9:54 AMJohn O'Reilly
07/26/2024, 9:56 AMKonstantin Tskhovrebov
07/26/2024, 10:04 AM