Adds a null check for Xamarin.Forms.Platform.Android.PageRenderer.Xamarin.Forms.Platform.Android.IOrderedTraversalController.UpdateTraversalOrder (#7050)

* Fixes #7049

* Test?

* Tap View please

* Spacing

* Address comments

* Excuse me, semicolons

* Remove private
This commit is contained in:
Happypig375 2019-08-09 20:19:08 +08:00 коммит произвёл Gerald Versluis
Родитель 7e9c60edad
Коммит f4ef490fac
3 изменённых файлов: 61 добавлений и 2 удалений

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

@ -0,0 +1,58 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using NUnit.Framework;
using Xamarin.UITest;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve (AllMembers=true)]
[Issue (IssueTracker.Github, 7049, "Null reference exception on some Android devices - Xamarin.Forms.Platform.Android.PageRenderer.Xamarin.Forms.Platform.Android.IOrderedTraversalController.UpdateTraversalOrder", PlatformAffected.Android)]
public class Issue7049 : TestContentPage
{
const string ContinueButton = "ContinueButton";
const string View1 = "View1";
const string View2 = "View2";
const string View3 = "View3";
bool _flag = true;
protected override void Init()
{
var button = new Button { AutomationId = ContinueButton, Text = "Continue" };
button.Clicked += (_, __) =>
{
var view = _flag ?
(View)new Entry { AutomationId = View2, Text = "Press 1 time to crash" } :
new Label { AutomationId = View3, Text = "I'm shown, bug fixed!" };
_flag ^= true;
(Content as StackLayout).Children[1] = view;
};
Content = new StackLayout
{
Children =
{
button,
new Label { AutomationId = View1, Text = "Press 2 times to crash" }
}
};
}
#if UITEST && __ANDROID__
[Test]
[Description ("Test null reference in IOrderedTraversalController.UpdateTraversalOrder of Android PageRenderer")]
public void Issue7049TestsNullRefInUpdateTraversalOrder()
{
RunningApp.WaitForElement(View1);
RunningApp.Tap(ContinueButton);
RunningApp.WaitForElement(View2);
RunningApp.Tap(ContinueButton);
RunningApp.WaitForElement(View3);
RunningApp.Tap(ContinueButton);
}
#endif
}
}

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

@ -22,6 +22,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue6644.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue7049.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShellGestures.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShellInsets.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewGrouping.cs" />

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

@ -187,7 +187,7 @@ namespace Xamarin.Forms.Platform.Android
!(
child is VisualElement ve && ve.IsTabStop
&& AutomationProperties.GetIsInAccessibleTree(ve) != false // accessible == true
&& ve.GetRenderer().View is ITabStop tabStop)
&& ve.GetRenderer()?.View is ITabStop tabStop)
)
continue;
@ -218,4 +218,4 @@ namespace Xamarin.Forms.Platform.Android
OrderedTraversalController.UpdateTraversalOrder();
}
}
}
}