xamarin/Xamarin.Forms

Android pan TotalX/TotalY bad when the gesture recognizer view is affected by layout change

Open

#3,469 opened on Aug 2, 2018

 (2 comments) (0 reactions) (0 assignees)C# (1,926 forks)batch import
e/8 :clock8:help wantedi/highinactivep/Androidt/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Description

On Android, if the view that holds a pan gesture recognizer is affected by a layout change while the pan is running, then the TotalX and TotalY values are incorrect. iOS and UWP do not have this problem. The values are less than they should be, and there is "jitter" in the values as they step up and partially back during a linear pan operation.

Others have noticed this problem:

  1. https://forums.xamarin.com/discussion/118226/android-pangesturerecognizer-jumps-back-and-forth
  2. https://forums.xamarin.com/discussion/87287/pangesturerecognizer-behaves-not-as-expected
  3. https://stackoverflow.com/questions/39458078/xamarin-pan-gesture-recognizer-not-giving-accurate-coordinates
  4. ...

I have attached a very simple iOS/Android/UWP project that illustrates the problem. The view with the pan gesture is in the bottom row of a grid, and the grid rows are resized as the pan occurs. See the screenshot below.

Steps to Reproduce

  1. Add a PanGestureRecognizer to a control on a page
  2. Handle the PanUpdated event, and update the location of the control (or its container) relative to the PanUpdated TotalX/TotalY values

Expected Behavior

On iOS and UWP, the TotalX/TotalY values in the PanUpdated event args will be correct and the affected control moves as expected

Actual Behavior

On Android, the control location lags the mouse position, and the location has "jitter"...jumps around as it moves

Basic Information

  • Version with issue: 2.x, 3.x
  • Last known good version: Unknown if any
  • Platform Target Frameworks:
    • Android: 8.1 (but the problem existed in previous versions as well)

Screenshots

Here it is in action (the jitter is not apparent in this compressed gif format):

panresizerow

Reproduction Link

PanResizeRowApp.zip

Contributor guide