Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toUIImage returns nil for iOS #640

Closed
Danijal98 opened this issue Feb 2, 2024 · 8 comments
Closed

toUIImage returns nil for iOS #640

Danijal98 opened this issue Feb 2, 2024 · 8 comments

Comments

@Danijal98
Copy link

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"
@rph8
Copy link

rph8 commented Feb 21, 2024

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.

@Alex009
Copy link
Member

Alex009 commented Feb 25, 2024

svg works in samples. svg on iOS require iOS 13+, check your iOS version please

@Danijal98
Copy link
Author

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

@Alex009
Copy link
Member

Alex009 commented Feb 27, 2024

@Danijal98 please test your svg inside xcode project directly. maybe iOS for some reason can't process this svg

@djehrlich
Copy link

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?

@rph8
Copy link

rph8 commented May 13, 2024

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

@djehrlich
Copy link

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.

@Danijal98
Copy link
Author

@Alex009 I can confirm that this bug does not occur anymore for me after upgrading to moko 0.24.1

@Alex009 Alex009 closed this as completed Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants