From 6ef847abfa3d65544c672af855c8bb24eedbd335 Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Wed, 28 Jun 2017 15:35:37 -0600 Subject: [PATCH] Add disposed check to EnsureLongClickCancellation (#1016) --- .../Bugzilla57758.cs | 56 +++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 1 + .../Renderers/ViewCellExtensions.cs | 5 ++ 3 files changed, 62 insertions(+) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla57758.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla57758.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla57758.cs new file mode 100644 index 000000000..f8982e68b --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla57758.cs @@ -0,0 +1,56 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +using Xamarin.Forms.Core.UITests; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ +#if UITEST + [Category(UITestCategories.Gestures)] + [Category(UITestCategories.Image)] +#endif + + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 57758, "ObjectDisposedException for Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer", PlatformAffected.Android)] + public class Bugzilla57758 : TestContentPage + { + const string ImageId = "TestImageId"; + + protected override void Init() + { + var testImage = new Image { Source = "coffee.png", AutomationId = ImageId }; + + var layout = new StackLayout + { + Padding = new Thickness(0, 20, 0, 0), + Children = + { + testImage + } + }; + + var tapGesture = new TapGestureRecognizer + { + NumberOfTapsRequired = 1, + Command = new Command(() => layout.Children.Remove(testImage)) + }; + + testImage.GestureRecognizers.Add(tapGesture); + + Content = layout; + } + +#if UITEST + [Test] + public void RemovingImageWithGestureFromLayoutWithinGestureHandlerDoesNotCrash() + { + RunningApp.WaitForElement(ImageId); + RunningApp.Tap(ImageId); + } +#endif + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index f7ae06f35..b4155f629 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -213,6 +213,7 @@ + diff --git a/Xamarin.Forms.Platform.Android/Renderers/ViewCellExtensions.cs b/Xamarin.Forms.Platform.Android/Renderers/ViewCellExtensions.cs index a3b34f62c..278e284a5 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ViewCellExtensions.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ViewCellExtensions.cs @@ -22,6 +22,11 @@ namespace Xamarin.Forms.Platform.Android public static void EnsureLongClickCancellation(this AView view, MotionEvent motionEvent, bool handled, VisualElement element) { + if (view.IsDisposed()) + { + return; + } + if (motionEvent.Action == MotionEventActions.Up && handled && view.LongClickable && element.IsInViewCell()) { // In order for long presses/clicks (for opening context menus) to work in a ViewCell