Heet Changela
Heet Changela

Reputation: 600

Unsupported [References to variables aren't supported yet] in android jetpack compose

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.

Upvotes: 1

Views: 435

Answers (2)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364556

Composable function reference is not yet supported. You need to use:

onClick = {onClose()}

Upvotes: 1

Arpit Shukla
Arpit Shukla

Reputation: 10503

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

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

Upvotes: 3

Related Questions