forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes JetBrains/compose-multiplatform#1324 (comment) Compose doesn't work well if we send an event with different coordinates without sending Move event before it: ``` Column { Box(size=10) Box(size=10) } ``` If we send these events: Move(5,5) -> Scroll(5,15) -> Move(5,15) Then during the scroll event, HitPathTracker forgets about the first Box, and never send Exit to it. Instead it sends the Scroll event to it. We should send events in this order: Move(5,5) -> Move(5,15) -> Scroll(5,15) -> Move(5,15) With synthetic events things more complicated, as we always send events with the same position. I suppose the proper fix should be in Compose core itself, but it would a very huge fix. Reproducer: ``` import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.size import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ImageComposeScene import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.input.pointer.PointerEventType import androidx.compose.ui.input.pointer.onPointerEvent import androidx.compose.ui.unit.Density import androidx.compose.ui.unit.dp import androidx.compose.ui.use import com.google.common.truth.Truth.assertThat import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 @OptIn(ExperimentalComposeUiApi::class) @RunWith(JUnit4::class) class MouseHoverFilterTest { // bug: JetBrains/compose-multiplatform#1324 (comment) @test fun `move from one component to another, between another non-move event`() = ImageComposeScene( width = 100, height = 100, density = Density(1f) ).use { scene -> var enterCount1 = 0 var exitCount1 = 0 var enterCount2 = 0 var exitCount2 = 0 scene.setContent { Column { Box( modifier = Modifier .pointerMove( onEnter = { enterCount1++ }, onExit = { exitCount1++ } ) .size(10.dp, 10.dp) ) Box( modifier = Modifier .pointerMove( onEnter = { enterCount2++ }, onExit = { exitCount2++ } ) .size(10.dp, 10.dp) ) } } scene.sendPointerEvent(PointerEventType.Enter, Offset(5f, 5f)) assertThat(enterCount1).isEqualTo(1) assertThat(exitCount1).isEqualTo(0) assertThat(enterCount2).isEqualTo(0) assertThat(exitCount2).isEqualTo(0) // Compose doesn't work well if we send an event with different type and different coordinates, without sending move event before it scene.sendPointerEvent(PointerEventType.Scroll, Offset(5f, 15f)) scene.sendPointerEvent(PointerEventType.Move, Offset(5f, 15f)) assertThat(enterCount1).isEqualTo(1) assertThat(exitCount1).isEqualTo(1) assertThat(enterCount2).isEqualTo(1) assertThat(exitCount2).isEqualTo(0) } } ``` Another issue: JetBrains/compose-multiplatform#1480
- Loading branch information
Showing
5 changed files
with
97 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters