skip to Main Content

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


  1. onClick = (::onClose)() isn’t a valid syntax. You can’t call a function reference.

    Use onClick = onClose or onClick = { onClose() }.

    Login or Signup to reply.
  2. Composable function reference is not yet supported. You need to use:

    onClick = {onClose()}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search