:wave: Any multiplatform async image loading libra...
# compose
n
👋 Any multiplatform async image loading library that supports local files? (
android.net.Uri
and file://
NSUrl
) I know Kamel but it doesn't support local files.
j
https://github.com/Kamel-Media/Kamel Not entirely sure if supports local files but think so.
n
It doesn’t support local files, no 😞 . At least not out of the box.
j
It has resource fetcher for desktop and Android/jvm. Would be possible iOS plugin hybride I guess.
But yeah struggle with images, fonts and such in general. Its possible using custom resource sharing with jetbrains resources plugin.
n
This is easier, I think. It’s just that the images can be selected locally. Imagine a social network, you are in the edit profile screen, the avatar image is either a remote URI (the API sent you) or a local URI (you selected a file and didn’t submit yet).
j
Yeah I would do a custom compasable compatible with all variants, Kamel, Coil, Url, File etc and delegate per platform. I do this always to also support Lottie :) Then able to support all frameworks with one image composable you control ;)
If it happen to mean for iOS using NsUrl manual lookup can hide implementation detail with expect/actual
n
🤔 You mean to check if NSUrl is a local file and delegate to Kamel if it is remote and print it with a native solution otherwise?
j
Yeah :)
n
That could work 👍 I’ll give it a try!
Thank you
j
Also my suggestion work for things like Lottie, video, animated gifs, vectors etc. If can use local or remote but also for remote selecting rendering option per platform. Would also decouple it to like CustomImageSource and different implementation for iOS and Android as of example. Not sure which targets you have. Then having almost everything in commonMain will be possible :)
n
That’s a good advice, thank you! 👍
l
@Nacho Ruiz Martin kamel does support local files
https://github.com/Kamel-Media/Kamel#loading-an-image-resource
Copy code
// File (JVM, Native)
asyncPainterResource(data = File("/path/to/image.png"))
android.net.Uri
is different. See https://github.com/Kamel-Media/Kamel/issues/62 for
NSUrl
wrap it in
URL
. https://github.com/Kamel-Media/Kamel/blob/c83ef4ae6ad05bd58a00a51352bda7068057cd02[…]kamel-core/src/appleMain/kotlin/io/kamel/core/utils/Platform.kt If it’s not working feel free to create an issue
n
Hey, Luca. Sorry I wasn’t super clear! It indeed does support local files with the File API. What I meant is that it doesn’t support local URIs. Meaning
file://
NSURLs on iOS or
content://
android.net.Uri
on Android. I saw 62 and I will study the possibility to contribute to the library by adding support for them. I don’t have spare time now but as soon as I find some I’ll make a proposal 👍 .
l
@Nacho Ruiz Martin so yeah, it looks like
NSURL
will only resolve remote urls based on how I implemented it. Can you get a path from the
NSURL
? if so you can just use
File("/path/to/image.png")
as I was saying.
what really should be done is adding apple only
Mapper<NSURL, Url>
and
Mapper<NSURL, File>
implementations
n
That sounds like a really elegant solution. Would you want me to test and contribute that to the library?
l
n
Maybe having something to check if it's applicable just as you have for fetchers?
l
that or just have a mapper return null if it can’t do it and try the next one if available
And yeah if you want go ahead, otherwise I’ll just make an issue for it and get to it eventually… but no guarrantee’s on time
n
Please, create the issue and I’ll try to schedule it 🙂.
l
made the issues. Shouldn’t be too hard to implement if you get to it before me
n
Yes, sounds easy. I’ll try to go for it asap. Do you prefer the
Copy code
//Mapper.kt
...
public fun map(input: I): O?
nullable approach or the
Copy code
public val I.isSupported: Boolean
new property approach (that would require to update all mappers)?
l
hmm maybe isSupported would be better. just to be consistent
you could just add a default implementation set to true in the mapper interface though and just override it for mappers that could have multiple output types
n
Ok 👍, let’s go for that.
👍 1