Hello everybody. I want to create some `Composable...
# compose-web
o
Hello everybody. I want to create some
Composable
function inside of an interface and realize this function in realizations if that interface. I have tried to use some
@Composable
callback getters (
val renderer: @Composable () -> Unit
), common functions (
@Composable fun render()
) and several other ways, but I got errors in rendering fun (
IllegalStateException {message: 'Function TextArea should have been replaced by compiler.', cause: undefined, name: 'IllegalStateException', stack: 'IllegalStateException: Function TextArea should ha…://127.0.0.1:8080/postssystem.client.js:1:2202661'}
error,
TextArea
here is external
@Composable
top-level function) or event getting an error
java.lang.AssertionError: No such value argument slot in IrCallImpl: 0 (total=0).
. Could somebody help me with this?
h
Can you provide a simplified reproducer? What do you mean with:
TextArea
is external? This:
@Composable external fun TextArea()
? This won't work
o
Copy code
interface Renderer {
    fun render()

    class Default {
        @Composable
        override fun render()
    }
}
That construction do not lead to any error in compile time but lead to errors in runtime in case of calling
@Composable
fun, but if I will mark
render
as
@Composable
in interface, it will throw
java.lang.AssertionError: No such value argument slot in IrCallImpl: 0 (total=0).
in compile time
TextArea is the function in web compose
h
Which versions do you use? This works for me (jsBrowserProductionRun), Kotlin 1.6.10 and Compose 1.1.1:
Copy code
import androidx.compose.runtime.*
import org.jetbrains.compose.web.*
import org.jetbrains.compose.web.dom.*

fun main() {
    renderComposableInBody {
        A.Default.render()
        A.B().render()
    }
}

interface A {
    @Composable
    fun render()

    companion object Default: A {
        @Composable
        override fun render() {
            Text("Default")
        }
    }

    class B: A {
        @Composable
        override fun render() {
            Text("B")
        }
    }
}
Same with TextArea
o
Could you please try to replace realization in another gradle module and add here?
I am using 1.6.10, compose 1.1.1, JS IR
h
Ah, you mean moving the interface into another module?
Works too 😄
o
Thanks, will try
Could we make a call about this issue? I have tried your code and it works correctly, but in my case I am facing with errors
h
Do it 😄 But please include your code
s
Make sure you apply Compose plugin to all gradle modules, it is likely the issue :)
❤️ 1
👍 1
o
@shikasd your advise has helped
@shikasd thank you :)