Elementalist
Elementalist

Reputation: 21

Jetpack Compose Toggleable and MouseClickable consume the same event

I am trying to find a way for a making a row both toggleable and having a dropdown menu if right click is clicked in Jetpack Compose Desktop.

Row(
        modifier = Modifier.height(IntrinsicSize.Min)
            .background(if (selected) MaterialTheme.colors.secondary else Color.Transparent)
            .mouseClickable(
                onClick = {
                    if (this.buttons.isSecondaryPressed) {
                        onRightMouseClick.invoke(index)
                    }
                })
            .toggleable(
                value = !selected,
                onValueChange = {
                    onItemSelected.invoke(!selected, index)
                }
            )

    )

Is there any way to consume both events at the same time? If i change the order of the modifiers, then the second one is always consumed.

Upvotes: 0

Views: 991

Answers (1)

Elementalist
Elementalist

Reputation: 21

After not finding an answer for quite some while, I decided to do the implementation a bit differently and have used the logic behind selection inside mouseClickable (not the best of solutions but a workaround at least).

Row(
        modifier = Modifier.height(IntrinsicSize.Min)
            .background(if (selected) MaterialTheme.colors.secondary else Color.Transparent)
            .mouseClickable(
                onClick = {
                    if (this.buttons.isSecondaryPressed) {
                        onRightMouseClick.invoke(index)
                    }else{
                        onItemSelected.invoke(!selected, index)
                    }
                })

Upvotes: 1

Related Questions