icerockdev / moko-resources

Resources access for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1.12k stars 124 forks source link

Resources-composable should have a ColorDesc.localized() function #752

Open dalewking opened 3 months ago

dalewking commented 3 months ago

StringDesc has a localized function, but for some reason ColorDesc does not.

dalewking commented 3 months ago

This is what I implemented in our code:

@Composable
fun ColorDesc.localized(): Color = when (this) {
    is ColorDescResource -> colorResource(resource)
    is ColorDescSingle -> Color(color.argb)
    is ColorDescThemed -> when {
        isSystemInDarkTheme() -> Color(darkColor.argb)
        else -> Color(lightColor.argb)
    }
    else -> throw NotImplementedError()
}