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

Unable to zoom using detectTransformGestures in Modifier.pointerInput #2209

Open
AnyUnderstanding opened this issue Jul 26, 2022 · 3 comments
Labels
desktop enhancement New feature or request input Touch, mouse, keyboard input related

Comments

@AnyUnderstanding
Copy link

AnyUnderstanding commented Jul 26, 2022

Tested on:

Compose versions: 1.1.1, 1.2.0-alpha01-dev753
Kotlin versions: 1.6.10, 1.7.0
Java version: openjdk-16.0.1-1
OS: Arch, Windows 11

Code:

Modifier.pointerInput(Unit){
      detectTransformGestures(
          onGesture = {centroid, pan, zoom, rotation ->
              println(zoom)
          }
      )
  }

Behavior:

Trying to zoom on a touchscreen of a laptop with two fingers (pinch), the above code always prints "1.0", regardless of the pinch direction.

Expected Behavior:

The above code should yield different zoom levels in relation to the distance between touchpoints. If the distance between the touchpoints is increasing, zoom should increase as well. Otherwise, if the distance is decreasing, zoom should also decrease.

While debugging, I noticed that zoom is calculated in the function calculateZoom by dividing currentCentroidSize / previousCentroidSize. To calculate the CentroidSize the function calculateCentroidSize is used. The function calculateCentroidSize iterates through the list changes (seems to hold the changed touch positions) and averages over the distance of all changes to the Centroid. Interestingly, the list changes always holds only one value, even if two fingers are on the touchscreen, therefore the distance to the centroid is always zero and currentCentroidSize and previousCentroidSize is also zero. To prevent division by zero, calculateZoom checks:

    if (currentCentroidSize == 0f || previousCentroidSize == 0f) {
        return 1f
    }

As a result, zoom is always one and the code works as described in the "Behavior" section.

All the functions described above can be found in TransformGestureDetector.kt.

@saket
Copy link

saket commented May 16, 2023

I'd love to use this for creating zoomable images on desktop using telephoto https://saket.github.io/telephoto/zoomableimage/

@MatkovIvan MatkovIvan added enhancement New feature or request input Touch, mouse, keyboard input related desktop labels May 17, 2023
@gsteckman
Copy link

Some applications, e.g. Firefox, let you use ctrl + scroll wheel on the mouse to zoom, and this also doesn't work. In this case, the onGesture callback to detectTransformGestures isn't invoked at all.

@okushnikov
Copy link

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
desktop enhancement New feature or request input Touch, mouse, keyboard input related
Projects
None yet
Development

No branches or pull requests

5 participants