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

Calculation for child gesture regions is wrong #41

Open
idunnololz opened this issue Jul 14, 2024 · 0 comments
Open

Calculation for child gesture regions is wrong #41

idunnololz opened this issue Jul 14, 2024 · 0 comments

Comments

@idunnololz
Copy link

idunnololz commented Jul 14, 2024

The child gesture region calculation includes this code:

    val coordinates = intArrayOf(0, 0)
    view.getLocationInWindow(coordinates)

    val x = coordinates[0]
    val y = coordinates[1]

    val absoluteRight = x + right
    val absoluteBottom = y + bottom

    viewIdToGestureRegionMap[view.id] = Rect(
      x,
      y,
      absoluteRight,
      absoluteBottom
    )

This code is only correct in calculating the child's "region" if the top and left of the child is 0. Otherwise the calculation is wrong. Specifically it calculates the absoluteRight and absoluteBottom as absoluteRight = x + right and absoluteBottom = y + bottom.

However the right and bottom of a view is left + width and top + height respectively. So in essence it's calculating absoluteRight as absoluteRight = x + left + width and thus it's accounting for how far left the view is twice. Once in x and again in left. The correct calculations should be:

    val coordinates = intArrayOf(0, 0)
    view.getLocationInWindow(coordinates)

    val x = coordinates[0]
    val y = coordinates[1]

    val width = right - left
    val height = bottom - top

    val absoluteRight = x + width
    val absoluteBottom = y + height

    viewIdToGestureRegionMap[view.id] = Rect(
      x,
      y,
      absoluteRight,
      absoluteBottom
    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant