Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash when we press right mouse button during dragging with left button Fixes JetBrains/compose-multiplatform#1426 Fixes JetBrains/compose-multiplatform#1176 Fixes JetBrains/compose-multiplatform#1430 Get rid of mousePressed from ComposeScene mousePressed is unreliable on Windows (we can miss the release event), and doesn't work well with multiple buttons. After this fix, mouseClickable only reacts to the first pressed button. Right button click doesn't trigger callback, if there is already left mouse button is pressed. `Clickable` shouldn't be able to handle these cases. If users would want simultaneously handle multiple buttons, they have to use low-level api: ``` Modifier.pointerInput(Unit) { while (true) { val event = awaitPointerEventScope { awaitPointerEvent() } if (event.type == PointerEventType.Press && event.buttons.isPrimaryPressed) { // do something } else if (event.type == PointerEventType.Press && event.buttons.isSecondaryPressed) { // do something } } } ``` (it is verbose, there is a field for improvement) Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true Test: the snippet from JetBrains/compose-multiplatform#1149, because changed the code for that fix Remove pointerId from ComposeScene pointerId was indroduced in https://android-review.googlesource.com/c/platform/frameworks/support/+/1402607, because double click didn't work (see https://jetbrains.slack.com/archives/GT449QBCK/p1597328095373000) But it messes with hover and clicking multiple mouse buttons at the same time. Double clicking still works after removing it: ``` import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.size import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.window.singleWindowApplication @OptIn(ExperimentalFoundationApi::class) fun main() = singleWindowApplication { Box( Modifier .size(300.dp) .background(Color.Red) .combinedClickable(onDoubleClick = { println("onDoubleClick") }, onClick = { println("onClick") }) ) { } } ``` Fixes JetBrains/compose-multiplatform#1176 Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true Test: manual (see the snippet)
- Loading branch information