Add disposed check to EnsureLongClickCancellation (#1016)

This commit is contained in:
E.Z. Hart 2017-06-28 15:35:37 -06:00 коммит произвёл Jason Smith
Родитель c6c4b7f9be
Коммит 6ef847abfa
3 изменённых файлов: 62 добавлений и 0 удалений

Просмотреть файл

@ -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
}
}

Просмотреть файл

@ -213,6 +213,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla55912.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla57317.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla57114.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla57758.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ButtonBackgroundColorTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.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