Ulrik Bech Hald
06/18/2024, 7:21 AMcomposeResources
with Kotlin 2.0 etc. and it is working great so far (android + iOS targets)
However, I would like to be able to apply separate android and iOS variants of a drawable resource and use that within commonMain. Example:
// Android-styled back icon
// androidMain/composeResources/drawable/ic_arrow_back.xml
// iOS-styled back icon
// iosMain/composeResources/drawable/ic_arrow_back.xml
..
// Access drawable inside commonMain @Composable
Res.drawable.ic_arrow_back
This obviously doesn’t work, since commonMain doesn’t have access to the platform-specific drawables (or the generated extension properties on Res
).
Is it possible to apply some form of the expect
/ actual
mechanism for resources? Or some other pattern/workaround to make this happen?
I would like to avoid the platform conditionals in commonMain.Khubaib Khan
06/18/2024, 7:36 AMUlrik Bech Hald
06/18/2024, 10:02 AMRes
so I don’t have to do anything other than define the 2 (actual) variant drawable resources in androidMain/composeResources and iosMain/composeResources and then just reference the (expect) Res.drawable.ic_arrow_back in commonMain.Khubaib Khan
06/18/2024, 10:15 AMMahvi
06/18/2024, 11:02 AMKonstantin Tskhovrebov
06/18/2024, 1:46 PMinternal expect val Res.drawable.ic_platform: DrawableResource