moko-resources
moko-resources copied to clipboard
ios color asset support for runtime dark & light color switching
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)!! }