I want to use reference operator like onClick = ::onClose
in below code
@Composable
fun HeaderIcons(onClose: () -> Unit) {
ConstraintLayout(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
) {
IconButton(
onClick = (::onClose)()
) {
Image(imageVector = ImageVector.vectorResource(id = R.drawable.ic_close), contentDescription = null)
}
}
}
}
I am facing error: Unsupported [References to variables aren’t supported yet]
Anyone have idea how to solve it or any other alternative?
ThankYou in Advance.
2
Answers
onClick = (::onClose)()
isn’t a valid syntax. You can’t call a function reference.Use
onClick = onClose
oronClick = { onClose() }
.Composable function reference is not yet supported. You need to use: