moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

ios color asset support for runtime dark & light color switching

Open jittya opened this issue 3 years ago • 0 comments

To support runtime theme switch the generated color assets files need to be copied to iosApp. which can be automated by a gradle task like below and configure it as iOS  run script.

val copyColorAssetsToIOSApp = tasks.register<Copy>("copyColorAssetsToIOSApp") {     from("$rootDir/resources/build/generated/moko/iosMain/res/Assets.xcassets")     into("$rootDir/iosApp/iosApp/Assets.xcassets/colors") }

Now to get the color from the iOS app assets we need to use UIColor.colorNamed(“colorName”) function. Below extension method can be used for that

fun ColorResource.getThemeColor(): UIColor {    return UIColor.colorNamed(this.name)!! }

jittya avatar Jul 19 '22 16:07 jittya