Migrated from https://bugzilla.xamarin.com/show_bug.cgi?id=39768
Migrated report; there are circumstances where panning slowly in Android can cause it to neglect firing the Completed
event.
The completed state is reached.
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.
As stated above, the PanGesture sample works for this.
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.
Another repro is on https://github.com/xamarin/xamarin-android/issues/2884
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.
Thanks, @beeradmoore !! I'll go ahead and close this now, but if it resurfaces, feel free to let us know.
Most helpful comment
_(Please refrain from +1 comments when possible to avoid clutter; GitHub provides reactions for such things.)_