This repository has been archived by the owner on May 1, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] fix accessibility of Picker (#5125)
* [Android] fix accessibility of Picker * fix NRE * fixes read selected item with accessibility * refactoring test * added dispose of accessibility delegate * fix build uitest * Update Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3454.cs Co-Authored-By: paymicro <v-payako@microsoft.com> * Update Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3454.cs Co-Authored-By: paymicro <v-payako@microsoft.com>
- Loading branch information
Showing
7 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3454.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 3454, "Picker accessibility text is wrong", PlatformAffected.Android)] | ||
public class Issue3454 : TestContentPage | ||
{ | ||
protected override void Init() | ||
{ | ||
var pickers = new List<Picker>(); | ||
var grid = new Grid(); | ||
int row = 0, col = 0; | ||
grid.AddChild(new Label { Text = "Default Style" }, col, row++); | ||
#if APP | ||
void AddPicker(string title, Func<Picker> getPicker) | ||
{ | ||
grid.AddChild(new Label { Text = title }, col, row++); | ||
var picker = getPicker(); | ||
picker.ItemsSource = Enumerable.Range(1, 10).Select(i => $"item {i}").ToList(); | ||
pickers.Add(picker); | ||
grid.AddChild(picker, col, row++); | ||
} | ||
|
||
AddPicker("AutomationProperties", () => | ||
{ | ||
var picker = new Picker(); | ||
picker.SetAutomationPropertiesName("First accessibility"); | ||
picker.SetAutomationPropertiesHelpText("This is the accessibility text"); | ||
return picker; | ||
}); | ||
AddPicker("Default", () => new Picker ()); | ||
AddPicker("Default + Title", () => new Picker { Title = "Title1" }); | ||
AddPicker("AutomationProperties + Title", () => | ||
{ | ||
var picker = new Picker { Title = "Title2" }; | ||
picker.SetAutomationPropertiesName("Last accessibility"); | ||
picker.SetAutomationPropertiesHelpText("This is the accessibility text"); | ||
return picker; | ||
}); | ||
|
||
row = 0; col++; | ||
grid.AddChild(new Label { Text = "Material Style" }, col, row++); | ||
AddPicker("AutomationProperties", () => | ||
{ | ||
var picker = new Picker { Visual = VisualMarker.Material }; | ||
picker.SetAutomationPropertiesName("First accessibility"); | ||
picker.SetAutomationPropertiesHelpText("This is the accessibility text"); | ||
return picker; | ||
}); | ||
AddPicker("Default", () => new Picker { Visual = VisualMarker.Material }); | ||
AddPicker("Default + Title", () => new Picker { Title = "Title1", Visual = VisualMarker.Material }); | ||
AddPicker("AutomationProperties + Title", () => | ||
{ | ||
var picker = new Picker { Title = "Title2", Visual = VisualMarker.Material }; | ||
picker.SetAutomationPropertiesName("Last accessibility"); | ||
picker.SetAutomationPropertiesHelpText("This is the accessibility text"); | ||
return picker; | ||
}); | ||
#endif | ||
|
||
Content = new ScrollView | ||
{ | ||
Content = new StackLayout | ||
{ | ||
Children = | ||
{ | ||
grid, | ||
new Button | ||
{ | ||
Text = "Clear pickers", | ||
Command = new Command(() => pickers.ForEach(p => p.SelectedItem = null)) | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Xamarin.Forms.Platform.Android/EntryAccessibilityDelegate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Android.Views.Accessibility; | ||
using Xamarin.Forms.Platform.Android.FastRenderers; | ||
|
||
namespace Xamarin.Forms.Platform.Android | ||
{ | ||
class EntryAccessibilityDelegate : global::Android.Views.View.AccessibilityDelegate | ||
{ | ||
BindableObject _element; | ||
|
||
public EntryAccessibilityDelegate(BindableObject Element) : base() | ||
{ | ||
_element = Element; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
_element = null; | ||
base.Dispose(disposing); | ||
} | ||
|
||
public string ValueText { get; set; } | ||
|
||
public string ClassName { get; set; } = "android.widget.Button"; | ||
|
||
public override void OnInitializeAccessibilityNodeInfo(global::Android.Views.View host, AccessibilityNodeInfo info) | ||
{ | ||
base.OnInitializeAccessibilityNodeInfo(host, info); | ||
info.ClassName = ClassName; | ||
if (_element != null) | ||
{ | ||
var value = string.IsNullOrWhiteSpace(ValueText) ? string.Empty : $"{ValueText}. "; | ||
host.ContentDescription = $"{value}{AutomationPropertiesProvider.ConcatenateNameAndHelpText(_element)}"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters