[Android] Fix NRE when page is being disposed (#1118)

* [ControlGallery] Add test case for bugzilla 59097

* [Android] Fix NRE
This commit is contained in:
Rui Marinho 2017-09-01 16:22:28 +01:00 коммит произвёл Samantha Houts
Родитель c2f6a9c16c
Коммит 35375bc2dc
3 изменённых файлов: 52 добавлений и 0 удалений

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

@ -0,0 +1,49 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 59097, "[Android] Calling PopAsync via TapGestureRecognizer causes an application crash", PlatformAffected.Android)]
public class Bugzilla59097 : TestNavigationPage // or TestMasterDetailPage, etc ...
{
protected override void Init()
{
Navigation.PushAsync(new ContentPage { Content = new Label { Text = "previous page " } });
Navigation.PushAsync(new ToPopPage());
}
public class ToPopPage : ContentPage
{
public ToPopPage()
{
var boxView = new BoxView { WidthRequest = 100, HeightRequest = 100, Color = Color.Red, AutomationId = "boxView" };
var tapGesture = new TapGestureRecognizer { NumberOfTapsRequired = 1, Command = new Command(PopPageBack) };
boxView.GestureRecognizers.Add(tapGesture);
var layout = new StackLayout();
layout.Children.Add(boxView);
Content = layout;
}
async void PopPageBack(object obj)
{
await Navigation.PopAsync(true);
}
}
#if UITEST
[Test]
public void Bugzilla59097Test()
{
RunningApp.WaitForElement(q => q.Marked("boxView"));
RunningApp.Tap(q => q.Marked("boxView"));
}
#endif
}
}

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

@ -318,6 +318,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzila57749.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ScrollViewObjectDisposed.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla58645.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59097.cs" />
<Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42620.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" />

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

@ -179,6 +179,8 @@ namespace Xamarin.Forms.Platform.Android
bool HasDoubleTapHandler()
{
if (_tapGestureRecognizers == null)
return false;
return _tapGestureRecognizers(2).Any();
}
}