JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.28k stars 1.11k forks source link

Multi touch tap events failing on desktop #4688

Open EricWarburton opened 2 months ago

EricWarburton commented 2 months ago

Describe the bug When tapping multiple times on the same button/card quickly the final touch event doesn't finish.

Affected platforms

Versions

To Reproduce Steps and/or the code snippet to reproduce the behavior: (Note: Click works as expected) Double tap a button, if you have a counter tied to the button the counter will move up by one. You should notice the button will remain highlighted. From there there are a couple scenarios.

` import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.material3.Button import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import org.jetbrains.compose.ui.tooling.preview.Preview

@Composable @Preview fun App() { MaterialTheme { var counter1 by remember { mutableStateOf(0) } var counter2 by remember { mutableStateOf(0) } var counter3 by remember { mutableStateOf(0) }

    Column(
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = Modifier.fillMaxSize()
    ) {
        Row(
            horizontalArrangement = Arrangement.Center
        ) {
            ButtonWithCounter("Button 1", mutableStateOf(counter1)) { counter1++ }
            ButtonWithCounter("Button 2", mutableStateOf(counter2)) { counter2++ }
            ButtonWithCounter("Button 3", mutableStateOf(counter3)) { counter3++ }
        }
        Spacer(Modifier.height(16.dp))
        Row(
            horizontalArrangement = Arrangement.Center
        ) {
            Button(onClick = {
                counter1 = 0
                counter2 = 0
                counter3 = 0
            }) { Text(text = "Clear Values") }
        }
    }
}

}

@Composable fun ButtonWithCounter(buttonText: String, counter: MutableState, onClick: () -> Unit) { Column( horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(8.dp) ) { Button(onClick = onClick) { Text(buttonText) } Text(text = "Counter: ${counter.value}") } } `

Expected behavior I expect the button to fire the event when tapped, even if tapped over and over.

Screenshots Button Multiple Tap Bug

m-sasha commented 2 months ago

@Schahen This looks like wrong usage of states. Can you check, please?