https://kotlinlang.org logo
#compose
Title
# compose
s

Stefano Rodriguez

11/03/2020, 3:53 PM
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

alorma

11/03/2020, 4:13 PM
yes
s

Stefano Rodriguez

11/03/2020, 4:17 PM
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

Adam Powell

11/03/2020, 4:20 PM
Can you post the full error you're seeing?
s

Stefano Rodriguez

11/03/2020, 4:25 PM
a

alorma

11/03/2020, 4:29 PM
i call it from inside a composable function
s

Stefano Rodriguez

11/03/2020, 4:29 PM
yeah, me too
s

Stefano Rodriguez

11/03/2020, 4:30 PM
I’m just doing this:
Copy code
@Composable
fun PreviewBox(
    selectedTestScreen: TestScreen<out Any>,
) {
        selectedTestScreen.doRender()
}
a

alorma

11/03/2020, 4:31 PM
yes, it looks like it don0t know the type, try with *
s

Stefano Rodriguez

11/03/2020, 4:31 PM
it’s the same
z

Zach Klippenstein (he/him) [MOD]

11/03/2020, 5:11 PM
Does your method implementation also have the Composable annotation?
s

Stefano Rodriguez

11/03/2020, 5:38 PM
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

Adam Powell

11/05/2020, 2:38 PM
Was the compose compiler plugin not enabled for one of the modules?
3 Views