|
It was indicated in the documentation the Skip does not support loading images from resources yet so I added this compose code as an alternative. I have a |
Replies: 4 comments 8 replies
|
I'm sorry for the trouble. You're definitely on the right track!
|
|
I should have mentioned that when you're getting used to mixing Compose/Kotlin into your code, one technique we've found useful is to open the whole project in Android Studio and play with the Kotlin directly. You get code completion and automatic imports and all that. Then back-port your solution to your Swift (or for lots of code, add a separate .kt file to your project that you write entirely in Android Studio). Just keep in mind that while you're experimenting with transpiled files in Android Studio, you should avoid running from Xcode or it'll re-transpile and overwrite your edits. To open in Android Studio, make sure you've built your project once in Xcode and then in the Xcode file tree panel go to |
|
We've released Skip 0.7.26 ( To expand on the topic slightly, Skip's approach to resources handling is to convert the We don't have any immediate plans to handle Android's static |
|
The problem is that the However, you can look up the image by name at runtime. I just tried this out, and it seems to work: @ViewBuilder func androidCustomImageView() -> some View {
#if !SKIP
EmptyView()
#else
// This module cannot access application-level `R.drawable` constants, so we need to look up the resource by name
let ctx = androidx.compose.ui.platform.LocalContext.current
// https://developer.android.com/guide/topics/resources/drawable-resource#Bitmap
let res = ctx.getResources().getIdentifier("rainbowlake", "drawable", ctx.getPackageName())
logger.log("loaded application image resource for rainbowlake: \(res)")
ComposeView { context in
if res != 0 {
androidx.compose.foundation.Image(
painter = androidx.compose.ui.res.painterResource(id = res),
contentDescription = "embedded image")
}
return .ok
}
#endif
}We hope to soon support resource loading using the Please let us know if you get it working! |




The problem is that the
R.drawableconstants are only available at the application-level module, to which only the scaffold ofAndroid/app/src/main/kotlin/poackagename/Main.ktis part of. Everything in your SwiftPM project is converted to an embedded Android module project, and so does not have access to the top-levelRconstants.However, you can look up the image by name at runtime. I just tried this out, and it seems to work: