James
03/19/2025, 2:46 PMUIKitView
and a UIImageView
being created in the factory. The image is a SF Symbol/system image so it’s got a transparent background. However whatever I try and set, either the backgroundColor
of the UIImageView
or the modifier of the compose component, it’s always white, not clear/transparent.
Example snippet here:
@Composable
actual fun SystemImageView(name: String, modifier: Modifier) {
val systemImage = remember { UIImage.systemImageNamed(name) }
UIKitView(
factory = {
UIImageView(systemImage).apply {
opaque = false
backgroundColor = UIColor.clearColor
contentMode = UIViewContentMode.UIViewContentModeScaleAspectFit
tintColor = UIColor.orangeColor
}
},
modifier = modifier
)
}
It feels like somewhere there’s a wrapping view which has a default background colour I can’t access. Any help appreciated. 🙇James
03/19/2025, 2:49 PMUIScrollView
, which has other issues I may ask about another day 🙃). So I’m wondering if it’s something coming from UIKitView
or `InteropView`/`UIKitInteropViewHolder`.
I see that the other way, the config for ComposeUIViewController
has an opaque
option, but there doesn’t seem to be an option this way.Andrei Salavei
03/19/2025, 6:07 PMJames
03/19/2025, 6:44 PMjoakim
03/19/2025, 6:54 PMAndrei Salavei
03/19/2025, 8:25 PMAlexander Zhirkevich
03/20/2025, 6:56 AMfun ImageBitmap.Companion.systemImage(systemName: String) : ImageBitmap {
return requireNotNull(UIImage.systemImageNamed(systemName)) {
"Image with name $systemName not found"
}.toComposeImageBitmap()
}
@OptIn(ExperimentalForeignApi::class)
fun UIImage.toComposeImageBitmap() : ImageBitmap {
val bytes = requireNotNull(UIImagePNGRepresentation(this)) {
"Failed to get PNG representation of image"
}
val byteArray = ByteArray(bytes.length.toInt())
byteArray.usePinned {
memcpy(it.addressOf(0), bytes.bytes, bytes.length)
}
return Image.makeFromEncoded(byteArray)
.toComposeImageBitmap()
}
Ivan Matkov
03/20/2025, 8:19 AMJames
03/20/2025, 8:26 AMJames
03/20/2025, 8:29 AMAlexander Zhirkevich
03/20/2025, 8:36 AMAndrei Salavei
03/20/2025, 10:07 AM