Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JVM] graphicsLayer modifier causes problems with pointer input on Desktop #3230

Closed
wakaztahir opened this issue Jun 3, 2023 · 6 comments · Fixed by JetBrains/compose-multiplatform-core#598
Assignees
Labels
bug Something isn't working regression reproduced

Comments

@wakaztahir
Copy link

wakaztahir commented Jun 3, 2023

This behavior is inconsistent with Android Platform

If you apply graphicsLayer modifier to a parent Box composable with some translation and scale , on Android when you tap on a child composable with onClick modifier the onClick is fired correctly but on Desktop the onClick is fired wrong , what I mean is , I tap somewhere else and it detects the click somewhere else

This is a big problem as we use zoomable and zoom state to allow user to zoom in on images and apply graphicsLayer on top of the composable but onClicks don't work properly for children

This happens on Jvm Desktop but Android Works fine , With Compose Version 1.4.0

@wakaztahir wakaztahir added bug Something isn't working submitted labels Jun 3, 2023
@wakaztahir wakaztahir changed the title [JVM] graphicsLayer modifier causes problems with pointer input [JVM] graphicsLayer modifier causes problems with pointer input on Desktop Jun 3, 2023
@alexzhirkevich
Copy link
Contributor

Same in Compose native. I guess only scale causes the issue. Translation works fine. Pointer input gestures try to interact with non-scaled content. And for example detectTransformGestures will adjust non scaled pan. Not the case on Android

@alexzhirkevich
Copy link
Contributor

alexzhirkevich commented Jun 4, 2023

‼️Regression!

It worked well in Compose 1.3.0. Bug appears in 1.4.0-alpha01-dev977

Repro:

@Composable
fun App() {
    var containerScale by remember {
        mutableStateOf(1f)
    }

    var offset by remember {
        mutableStateOf(Offset.Zero)
    }


    val source = remember {
        MutableInteractionSource()
    }

    val hovered by source.collectIsHoveredAsState()

    val size = 100.dp

    BoxWithConstraints(
        Modifier.background(Color.White)
    ) {
        Slider(
            value = containerScale,
            valueRange = 0f..3f,
            onValueChange = {
                containerScale = it
            }
        )

        Box(modifier = Modifier
            .fillMaxSize()
            .graphicsLayer {
                scaleY = containerScale
                scaleX = containerScale
            }
            .border(1.dp, Color.Black)
        ) {
            Box(modifier = Modifier
                .offset {
                    offset.round()
                }
                .hoverable(source)
                .size(size)
                .background(if (hovered) Color.Red else Color.Red.copy(alpha = .5f))
                .pointerInput(0) {
                    detectTransformGestures { _, pan, _, _ ->
                        offset += pan

                    }
                }
            ) {
                Text("Move me")
            }
        }


        Box(modifier = Modifier
            .size(size)
            .offset {
                val x = offset.x - (constraints.maxWidth / 2f - offset.x - size.toPx()/2) *
                        (1 - containerScale) / (containerScale)
                val y = offset.y - (constraints.maxHeight / 2f - offset.y - size.toPx()/2) *
                        (1 - containerScale) / (containerScale)
                Offset(x,y).round()
            }
            .scale(1/containerScale)
            .border(3.dp, Color.Green),
            contentAlignment = Alignment.BottomStart
        ) {
            Text("Actual bounds")
        }
    }
}

Android (works as expected):

Screen.Recording.2023-06-04.at.14.37.37.mov

Other platforms:

Screen.Recording.2023-06-04.at.14.40.04.mov

@eymar
Copy link
Member

eymar commented Jun 5, 2023

The change after which this bug became visible is - JetBrains/compose-multiplatform-core#422

But the actual issue is much older: #1718

We'll look into it.


Also: reproduible in web (canvas) too.

@MatkovIvan
Copy link
Member

I've fixed it in JetBrains/compose-multiplatform-core#598. It will be included in the next patch

cc @alexzhirkevich

@alexzhirkevich
Copy link
Contributor

Thanks <3

@okushnikov
Copy link
Collaborator

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression reproduced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants