Xamarin.forms: [Android] PanGestureRecognizer occasionally neglects firing the Completed event

Created on 4 Jan 2018  ·  13Comments  ·  Source: xamarin/Xamarin.Forms

Migrated from https://bugzilla.xamarin.com/show_bug.cgi?id=39768

Description

Migrated report; there are circumstances where panning slowly in Android can cause it to neglect firing the Completed event.

Steps to Reproduce

  1. You can utilize the PanGesture sample for this.
  2. Add debug logs/breakpoints in the Gesture.Completed case in the PanContainer.cs's OnPanUpdated method display.
  3. When running the application, start a pan, hold it for a moment or two, and release.

Expected Behavior

The completed state is reached.

Actual Behavior

Occasionally/frequently, this state is not reached. On an S8 this is maybe occurring 20% of the time, but not clear of whether some aspect of the pan is causing it.

Basic Information

  • Version with issue: 2.5.0
  • Affected Devices: (Tested with an S8)

Screenshots

Reproduction Link

As stated above, the PanGesture sample works for this.

gestures 🖖 4 help wanted inactive Android needs-info ❓ bug up-for-grabs

Most helpful comment

_(Please refrain from +1 comments when possible to avoid clutter; GitHub provides reactions for such things.)_

All 13 comments

For people like me that depends heavily on the PanGesture, there is a little hack I made to temporary use the PanGesture in Android: I catch the MotionEventActions.Up in the MainActivity and send a message to my PanGesture code to end the Pan.

Also, sometimes the Started event of the pan is also not triggered, the pan just recognizes the Running state, so you should set a bool var in Started and Running to detect if the pan is running, then when the event from MainActivity is detected, if the var is true, stop the Pan and works like a charm by now. Here the code for the MainActivity:

   public override bool OnTouchEvent(MotionEvent e) {
        base.OnTouchEvent(e);

        if (e.Action == MotionEventActions.Up) {
            System.Diagnostics.Debug.WriteLine("OnTouchEvent UP");
            _eventAggregator.GetEvent<AndroidTouchUpEvent>().Publish(true);
        }

        return true;
    }

Note here I am using Prism to send the message with the EventAgregator class, but MessagingCenter from Xamarin.Forms can be used too.

I hope this can help someone.

_(Please refrain from +1 comments when possible to avoid clutter; GitHub provides reactions for such things.)_

I played about with the source locally, and I think I've fixed the issue. I've attached a patch (for the 15-5 branch, renamed from .diff to .txt so I could upload it) that appears to maintain previous gesture functionality but also ensures the Complete status is sent for the pan gesture.
patch.txt

I have the same problem. What is the temporary solution?

@matt4pi Why not fork the repo, make the change and submit a pull request?

Closed by 3bcb9c6

I've just tested this using the PanGesture sample with XamForms version 2.5.0.280555, which according to here: https://developer.xamarin.com/releases/xamarin-forms/xamarin-forms-2.5/2.5.0-sr5/ is the version after the fix (I can't install service release 4 version using nuget).

The completed event does appear to always fire on this example, however I've got another example which uses the PanGesture for a virtual joystick and the completed event doesn't always fire. I've loaded this example here: https://github.com/richardpike/JoystickPanGestureBug it's quite easy to trigger it so that the completed event doesn't fire.

I'm also not seeing this problem resolved, yet.
Is updating forms enough, or does anything else need to be updated?
I could not get daspuru's solution to work for me, but I did do something similar thanks to his idea. Most reliable for me has been to catch things in:

// Catch all in Main Activity public override bool DispatchTouchEvent(MotionEvent ev) { if (ev.Action == MotionEventActions.Up) { System.Diagnostics.Debug.WriteLine(ev.Action.ToString()); MessagingCenter.Send<Object>(this, "UP"); } return base.DispatchTouchEvent(ev); }

Then I'm firing the corresponding cancelled handlers myself and everything works just as well as in IOS.

Any updates on the situation??

This issue doesn't seem to have had any activity in a long time. We're working on prioritizing issues and resolving them as quickly as we can. To help us get through the list, we would appreciate an update from you to let us know if this is still affecting you on the latest version of Xamarin.Forms, since it's possible that we may have resolved this as part of another related or duplicate issue. If we don't see any new activity on this issue in the next 30 days, we'll evaluate whether this issue should be closed. Thank you!

TL;DR; Unable to replicate on Pixel 2 XL.

I got the PanGesture sample listed above, updated it to latest XF version (it was like .709 up to .800, so sample was mostly up to date anyway), added a Debug.WriteLine, and I was unable to replicate.

Pointed it to target Android 10, hit the migrate to AndroidX button, still unable to replicate. Unsure if this is fixed, or if I never would have experienced it on my Pixel 2 XL.

Xamarin_Forms___PanGesture 28-05-2020.zip

Thanks, @beeradmoore !! I'll go ahead and close this now, but if it resurfaces, feel free to let us know.

Was this page helpful?
0 / 5 - 0 ratings