Is there a way to “store” a composable function as...
# compose
s
Is there a way to “store” a composable function as a method of a data class/interface and call it programmatically from another composable function? I’m getting a weird java.lang.NoSuchMethodError when trying to invoke the
render
method
Copy code
interface TestScreen<State: Any> {
    val name: String
    val initialState: State
    @Composable
    fun render(state: State, setState: (State) -> Unit)
}
a
yes
s
looks really similar to what I’m trying to achieve, how do you call the
build
function? You just use it normally? Perhaps the problem is related to the generic
State
type and I have somehow to erase it
a
Can you post the full error you're seeing?
s
a
i call it from inside a composable function
s
yeah, me too
s
I’m just doing this:
Copy code
@Composable
fun PreviewBox(
    selectedTestScreen: TestScreen<out Any>,
) {
        selectedTestScreen.doRender()
}
a
yes, it looks like it don0t know the type, try with *
s
it’s the same
z
Does your method implementation also have the Composable annotation?
s
Yes
@Adam Powell So i discovered the issue. It’s not related to the generics but to the fact that the interface is declared in another module w.r.t. where I use it
a
Was the compose compiler plugin not enabled for one of the modules?