I wish to have an interface which has a composable function Show like this in Android project feature module A.
interface AInterface {
@Composable
fun Show(modifier: Modifier = Modifier)
}
class AInterfaceImpl : AInterface {
@Composable
override fun Show(modifier: Modifier) {
Text(
modifier = modifier,
text = "Message",
)
}
}
And inject the AInterfaceImpl object to Android project feature module B using Hilt and when I call aInterfaceImpl.Show(modifier) in Composable function from module B, it throws the below compile error.
@Composable
fun ShowAInterfaceImpl(
modifier: Modifier,
aInterface: AInterface
) {
aInterface.Show(
modifier = modifier
)
}
kotlin.NotImplementedError: An operation is not implemented: Unknown file
at org.jetbrains.kotlin.ir.util.IrUtilsKt.getFile(IrUtils.kt:634)
at androidx.compose.compiler.plugins.kotlin.lower.InferenceFunctionDeclaration.toScheme(ComposableTargetAnnotationsTransformer.kt:680)
at androidx.compose.compiler.plugins.kotlin.lower.InferenceFunctionDeclaration.toDeclaredScheme(ComposableTargetAnnotationsTransformer.kt:671)
at androidx.compose.compiler.plugins.kotlin.lower.InferenceFunction.toDeclaredScheme$default(ComposableTargetAnnotationsTransformer.kt:614)
I spent a lot of time working around it, however, I have not got any clue. If anyone has any clue, please let me know. Thanks in advance.
I have investigated this issue for a long time and found the below two issues:
So basically, Composable function in the interface does not support the function parameter default value.
interface AInterface {
@Composable
fun Show(modifier: Modifier)
}
So it works. Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With