Hi all! I have a KMP with a react website and an A...
# multiplatform
j
Hi all! I have a KMP with a react website and an Android application. To support the functional components, I make my props (RProps) external interfaces in the common module. However, when I try to build the Android application, it complains about these external interfaces:
Copy code
Modifier 'external' is not applicable to 'class'
It looks (for example) like this:
Copy code
external interface EventDetailsContractProps: BaseProps {
    var eventId: UUID
    var handler: EventDetailsContract.Handler
}

interface EventDetailsContract {
    interface Handler: EventSummaryContract.Handler {
        fun onEventDetailsFinished()
    }
}

data class EventDetailsProps constructor(
    override var eventId: UUID,
    override var handler: EventDetailsContract.Handler
): EventDetailsContractProps
This code is shared between my javascript and android targets. Is there any way to resolve this? I could try:
Copy code
expect interface EventDetailsContractProps {
    var eventId: UUID
    var handler: EventDetailsContract.Handler
}
And then make a platform specific
actual
Interface, but that would mean a lot of boilerplate (As I would have to rewrite the interface 3 times).
m
You can’t use
external
in outside of Kotlin/JS. Also not with
expect
/
actual
. You’ll have to wrap your props.
Copy code
external interface MyProps<T> {
   var value: T
}
Then your component has
MyProps<EventDetailsContractProps>
as props where
EventDetailsContractProps
is a regular
class
or
interface
.
kotlin-react
is annoying in that regard. For that reason and others I’ve created my own 🙂 https://github.com/fluidsonic/fluid-react (no class components though and requires IR compiler)
j
I think I can still write: actual external interface EventDetailsContractProps: BaseProps
m
If that would be possible then common code is broken because things like
value is EventDetailsContractProps
or
value.equals(…)
etc. won’t work and just crash.
j
well to support the external interfaces I already took away all reified things and comparisons
so I think in that case I should always remember to keep it like that
m
Yeah I didn’t want to make all the compromises like that or losing type safety b/c of
external
. Hence I’ve made my own library 😉