moko-resources
moko-resources copied to clipboard
toUIImage returns nil for iOS
I am using the version: 0.23.0
I have the following structure for my images: shared/commonMain/resources/MR/images/ic_partnership.svg
I have a suggested helper method
fun getImageByFileName(name: String): ImageResource {
val fallbackImage = MR.images.transparent
return MR.images.getImageByFileName(name) ?: fallbackImage
}
From iOS I call it like this
let imageRes = ResourcesKt.getImageByFileName(name: "ic_partnership") // Successfully finds the resource
let uiImage = imageRes.toUIImage() // returns nil
Image(uiImage: uiImage!).padding() // crashes because "Unexpectedly found nil while unwrapping an Optional value"
Could it be that this an issue with svgs? .toUIImage seems to work fine for me with pngs, but with svgs I get nil as well.
svg works in samples. svg on iOS require iOS 13+, check your iOS version please
svg works in samples. svg on iOS require iOS 13+, check your iOS version please
I am using the iOS 17, so I think that should not be the issue
@Danijal98 please test your svg inside xcode project directly. maybe iOS for some reason can't process this svg
I’m seeing a similar issue with an SVG file on iOS. Interestingly, while in light mode, I see the image (.toUIImage() returns non-nil). However, when I switch to dark mode, I don’t see the image (.toUIImage() returns nil). Maybe this clue helps?
I’m seeing a similar issue with an SVG file on iOS. Interestingly, while in light mode, I see the image (.toUIImage() returns non-nil). However, when I switch to dark mode, I don’t see the image (.toUIImage() returns nil). Maybe this clue helps?
Is it maybe related to this one (should be fixed in the most recent version / beta)? https://github.com/icerockdev/moko-resources/issues/543
I’m seeing a similar issue with an SVG file on iOS. Interestingly, while in light mode, I see the image (.toUIImage() returns non-nil). However, when I switch to dark mode, I don’t see the image (.toUIImage() returns nil). Maybe this clue helps?
Is it maybe related to this one (should be fixed in the most recent version / beta)? #543
Dark mode SVG images are indeed working. The comments for #624 provided the insight I needed - add an image resource with “-dark” appended to its name. I tested by copying “car_black.svg” to “car_black-dark.svg” and both light and dark mode now work as advertised.
@Alex009 I can confirm that this bug does not occur anymore for me after upgrading to moko 0.24.1