I'm converting an android app slowly to kmp compos...
# compose-ios
c
I'm converting an android app slowly to kmp compose ios. I have this composable that I'm not sure what to do because of the @DrawableRes image.
Copy code
@Composable
fun MyButtonToggleable(
    modifier: Modifier,
    onClick: () -> Unit,
    text: String,
    toggle: Boolean = false,
    @DrawableRes image: Int? = null
) {
Image(painterResource(id = image), null)
I guess my two questions are: 1. Is there a way to bring that annotation over into kmp? seems to be android specific? 2. painterResource isn't available?
c
Compose iOS has its own mechanism for providing drawables. Until very recently it used to be "stringly typed". A very recent beta of CMP 1.6 has introduced compile time safety similar to Android's R class.
I'm on mobile right now but if you search in the Compose repo you'll find examples for both
If you create a new KMP project using the online wizard it creates a screen with the Compose logo animation. That one already demonstrates how to use drawables in CMP.
a
If it’s a vector xml there is a handy tool you can covert to true compose vector that works on any platform.
👍 1
j
The annotations not really Android specific itself, but androidx annotations only targetting Android I think. Also not really anything special about them, just regular Ints used 🙂 To make it easier migrate to KMP I recommend creating new like ImageResource, TextResource, DimensionResource etc. Regular sealed classes/interfaces. And then resolve the image in this case only when needed. Then you can delegate it one way in Android and another way in iOS as of example. As @curioustechizen mentioned compose multiplatform offers a component resources, solving this. WHere also painterResource exist but for DrawableResource class Jetbrains provide in their plugin.