Kamel-Media / Kamel

Kotlin asynchronous media loading and caching library for Compose.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add apple only Mapper<NSURL, Url> and Mapper<NSURL, File>

luca992 opened this issue · comments

Support multiple mappers per input class type #70 Is required for this.

Ideally these would be offered in the default config: #69

🤔 There's a problem here. KClass for Objective-C classes is not supported yet. That means we can't use NSURL on Mapper as it relies on passing the KClass:

image

Any workaround?

I think the only possible workaround is to create a Kotlin object wrapper around NSURL as it's done when using Koin. But the API will be way worse.

🤔 There's a problem here. KClass for Objective-C classes is not supported yet. That means we can't use NSURL on Mapper as it relies on passing the KClass:

image

Any workaround?

Hmmm can you get any sort of class name out of it as a string?... Or maybe is it possible to declare a companion object on it? If so just maybe it's possible to check if it has a companion object kclass as a backup if that error gets thrown

This works:

println("${NSURL.`class`()}")

and the output is "NSURL". Can you elaborate on how can we use this with the mappers?

This is OK, btw:

assertEquals(NSURL.`class`(), NSURL.fileURLWithPath(path).`class`())

Meaning we can compare it with an instance type.

@iruizmar check here I did this in like 15 minutes... it's a mess but works:

#74

I'd really rather try and find another way if possible. But lmk what you think

Maybe something like this could be used as the mappers key:

sealed interface CommonClass

internal value class KClassWrapped<T : Any>(private val kclass: KClass<T>) : CommonClass
internal value class ObjCClassWrapped(private val objcClass: ObjCClass) : CommonClass

Then maybe it's possible to do something like this:

Screenshot 2023-11-13 at 4 54 31 AM

I like more the second approach, yeah. Delegating everything to Strings looks odd. Do you want me to pull the thread from there?

I like more the second approach, yeah. Delegating everything to Strings looks odd. Do you want me to pull the thread from there?

yeah probably don't pull that. I just made that pr to show you more easily.

We can continue with the CommonClass approach, then, if you like it. I can make a quick draft and we can work on the final API from there. WDYT?

We can continue with the CommonClass approach, then, if you like it. I can make a quick draft and we can work on the final API from there. WDYT?

sounds good to me if you have the motivation to do it 👍. Otherwise I can try and get to it in the next couple weeks

Also I'm not positive the CommonClass won't have problems. But that's just what I'm thinking might work.

A method or extension to convert Any to a CommonClass will have to be an expect actual I think... either that or I guess ObjCClassWrapped could be an expect actual that is only defined for apple targets... The first approach probably makes more sense however

Sorry mate, I have a peak of work this week. Maybe during the weekend, I will be able to take a look! 👍🏻