Hey all, new to KMP and exploring the feasibility of creating a shared lib that can be used across iOS, Android, and web (TS + React).
My specific question is how are people working around the limitation where
kotlin.collections.List
can’t be exported with
@JsExport
?
With my limited experience in KMP, see below for something I’ve cobbled together that’s been working but it does not seem ideal. For instance, converting to and from
List
and having to create wrappers for every collection type takes away from the dream of writing business logic once at a high level and reusing it across platforms.
Does anyone have advice for doing this in perhaps a more generic way? Has anyone found a way to use
expect / actual
as a better solution?
@ExperimentalJsExport
@JsExport
class PeopleList : MutableList<StarWarsPerson> by mutableListOf() {
fun toArray(): Array<StarWarsPerson> {
val array = emptyArray<StarWarsPerson>()
this.forEachIndexed { index, person ->
array[index] = person
}
return array
}
companion object {
fun fromArray(people: Array<StarWarsPerson>): PeopleList {
val peopleList = PeopleList()
peopleList.addAll(people)
return peopleList
}
}
}
@ExperimentalJsExport
@JsExport
data class StarWarsPerson(val name: String