Is there way to create `DrawableResource` dynamica...
# compose-desktop
j
Is there way to create
DrawableResource
dynamically when using CMP shared resources. For example I want to create
flagResource
based on some country code I have.
Copy code
Image(
    painterResource(flagResource),
    modifier = Modifier.size(32.dp),
    contentDescription = country.displayName
)
On Android I was using
Copy code
val flagResourceId = context.resources.getIdentifier(
    "flag_${country.code",
    "drawable",context.packageName)
Found following that seems to work
Copy code
@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),
        )
    )
though possibly not a recommended approach
j
nice, thanks! What version of CMP is that in?
k