iOS - Test and fix for VoiceOver crash on a ContentPage not having any Content defined (#6987) fixes #6926

* Added test case for showing crash for issue 6926.

* Potential fix for issue 6926. Prevents a null reference exception when a ContentPage has no Content.
This commit is contained in:
Samantha Houts 2019-07-29 02:01:24 -07:00 коммит произвёл Rui Marinho
Родитель beab7a98bd
Коммит a237197208
3 изменённых файлов: 46 добавлений и 0 удалений

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

@ -0,0 +1,42 @@
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 6926, "[iOS] iOS - Using VoiceOver will crash when a ContentPage has no Content", PlatformAffected.iOS)]
public class GitHub6926 : TestContentPage
{
protected override void Init()
{
Content = new StackLayout
{
Children = {
new Label()
{
Text = "Enable VoiceOver and then click either:",
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center,
},
new Button()
{
Text = "ContentPage without content (crash)",
Command = new Command(() =>
{
Navigation.PushAsync(new ContentPage());
})
},
new Button()
{
Text = "ContentPage with content (no crash)",
Command = new Command(() =>
{
Navigation.PushAsync(new ContentPage() { Content = new StackLayout() });
})
}
},
};
}
}
}

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

@ -979,6 +979,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue3548.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue6472.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue6614.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GitHub6926.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">

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

@ -62,6 +62,9 @@ namespace Xamarin.Forms.Platform.iOS
[Export("accessibilityElementCount")]
nint AccessibilityElementCount()
{
if (AccessibilityElements == null)
return 0;
// Note: this will only be called when VoiceOver is enabled
return AccessibilityElements.Count;
}