Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Android] PanGestureRecognizer occasionally neglects firing the Completed event #1495

Closed
pauldipietro opened this issue Jan 4, 2018 · 13 comments
Labels
a/gestures 🖖 e/4 🕓 4 help wanted We welcome community contributions to any issue, but these might be a good place to start! inactive Issue is older than 6 months and needs to be retested p/Android s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!

Comments

@pauldipietro
Copy link
Contributor

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.

@daspuru
Copy link

daspuru commented Jan 4, 2018

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.

@xamarin xamarin deleted a comment from bill2004158 Jan 9, 2018
@pauldipietro
Copy link
Contributor Author

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

@matt4pi
Copy link
Contributor

matt4pi commented Jan 11, 2018

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

@githubxiaoa
Copy link

githubxiaoa commented Jan 16, 2018

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

@aetharr
Copy link

aetharr commented Jan 27, 2018

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

@samhouts
Copy link
Member

Closed by 3bcb9c6

@richardpike
Copy link

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.

@jaramire
Copy link

jaramire commented Mar 15, 2018

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.

@samhouts
Copy link
Member

samhouts commented Apr 2, 2019

Another repro is on dotnet/android#2884

@samhouts samhouts added s/unverified New report that has yet to be verified e/4 🕓 4 a/gestures 🖖 and removed s/unverified New report that has yet to be verified labels Apr 9, 2019
@3xcellentTuber
Copy link

Any updates on the situation??

@samhouts samhouts added inactive Issue is older than 6 months and needs to be retested help wanted We welcome community contributions to any issue, but these might be a good place to start! up-for-grabs We welcome community contributions to any issue, but these might be a good place to start! labels Mar 10, 2020
@samhouts
Copy link
Member

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!

@samhouts samhouts added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label May 27, 2020
@beeradmoore
Copy link
Contributor

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

@samhouts
Copy link
Member

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/gestures 🖖 e/4 🕓 4 help wanted We welcome community contributions to any issue, but these might be a good place to start! inactive Issue is older than 6 months and needs to be retested p/Android s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Projects
None yet
Development

No branches or pull requests

10 participants