In
dev11
, you could call a top-level composable function from a library via reflection by passing in
currentComposer
:
val clazz = Class.forName("com.commonsware.jetc.specimen.basics.ActionCheckboxKt")
val demoMethod = clazz.methods.find { it.name == "ActionCheckboxDemo" }
demoMethod?.let {
it.isAccessible = true
it.invoke(null, currentComposer)
}
In this case,
ActionCheckboxDemo()
has zero parameters in terms of the way the source is written. But, if you looked at the compiled class file (e.g., via External Libraries in Studio), you would see that the function was rewritten to take a
Composer
.
I'm uncertain how to accomplish this in
dev12
. If I look at the compiled class file, it claims to take zero parameters. If I try
invoke()
, it claims to take 3 parameters. The release notes support the three-parameter signature, though the docs seem to be somewhat mangled:
A Composable function accepting a single parameter is transformed into a function accepting 3 parameters, the additional parameters are the Composer, a ‘key’ integer. a bitmask integer used to propagate metadata through calls.
If I change the invocation to
it.invoke(null, currentComposer, 0, 0)
, it runs. But... should I be deriving better values for those integers from somewhere?