This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 455
[Enhancement] Accessibility - Screen reader to read specific textΒ #1385
Copy link
Copy link
Closed
Labels
a11yIssue/PR has to do with accessibilityIssue/PR has to do with accessibilityfeature-requestA request for a new feature.A request for a new feature.needs-approvalFeature request has been submitted but is awaiting final approval. Please do not implement before!Feature request has been submitted but is awaiting final approval. Please do not implement before!
Description
Summary
API to make the screen reader read out specific text - https://forums.xamarin.com/discussion/185004/xamarin-forms-accessibility-screen-reader-to-read-each-page-name-header-on-page-load-appearing
API Changes
New interface -
public interface IAccessibility
{
void Announcement(string text);
}iOS implementation -
namespace Sample.iOS.Platform.Accessibility
{
/// <summary>
/// iOS accessibility class. Handles the accessibility related
/// operations in the iOS native.
/// </summary>
public class IosAccessibility : IAccessibility
{
/// <summary>
/// Announces the accessibility text passed based on the VoiceOver is enabled.
/// </summary>
/// <param name="text">The text to speak/announce</param>
public void Announcement(string text)
{
if (!UIAccessibility.IsVoiceOverRunning)
return;
// Post notification to announce the accessibility text.
UIAccessibility.PostNotification(UIAccessibilityPostNotification.Announcement, new NSString(text));
}
}
}Android implementation -
namespace Sample.Droid.Platform.Accessibility
{
/// <summary>
/// Android accessibility class. Handles the accessibility related
/// operations in the Android native.
/// </summary>
public class AndroidAccessibility : IAccessibility
{
/// <summary>
/// Announces the accessibility text passed based on the TalkBack or screen reader enabled.
/// </summary>
/// <param name="text">The text to speak/announce</param>
public void Announcement(string text)
{
AccessibilityManager manager = (AccessibilityManager)Android.App.Application.Context.GetSystemService(Android.App.Application.AccessibilityService);
if (!(manager.IsEnabled || manager.IsTouchExplorationEnabled))
return;
// Sends the accessibility event to announce.
AccessibilityEvent e = AccessibilityEvent.Obtain();
e.EventType = EventTypes.Announcement;
e.Text.Add(new Java.Lang.String(text));
manager.SendAccessibilityEvent(e);
}
}
}Usage -
DependencyService.Get<IAccessibility>().Announcement("Item added to basket");Intended Use Case
I have a number of places I need to use this in our app -
- We have a custom switch and checkbox (using lottie) and need a way of announcing the current state when it is changed i.e. on/ off, checked/ not checked, etc.
- When an item is added to the basket, it needs to announce "2 bikes added to your basket"
Who Will Do The Work?
- I am willing to take this on myself
- Just putting this out there for someone to pick up
jfversluis
Metadata
Metadata
Assignees
Labels
a11yIssue/PR has to do with accessibilityIssue/PR has to do with accessibilityfeature-requestA request for a new feature.A request for a new feature.needs-approvalFeature request has been submitted but is awaiting final approval. Please do not implement before!Feature request has been submitted but is awaiting final approval. Please do not implement before!