Mapped accesibility properties
This commit is contained in:
Родитель
ef9fb791bd
Коммит
ea273abaf2
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Graphics.Android;
|
||||
using Android.Content;
|
||||
using Android.Views;
|
||||
|
@ -36,9 +37,20 @@ namespace GraphicsControls.Android
|
|||
e.NewElement.Invalidated += OnDrawInvalidated;
|
||||
SetNativeControl(new NativeGraphicsView(Context));
|
||||
Control.Drawable = Element;
|
||||
|
||||
UpdateAutomationProperties();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnElementPropertyChanged(sender, e);
|
||||
|
||||
if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName ||
|
||||
e.PropertyName == AutomationProperties.NameProperty.PropertyName)
|
||||
UpdateAutomationProperties();
|
||||
}
|
||||
|
||||
protected override void OnAttachedToWindow()
|
||||
{
|
||||
base.OnAttachedToWindow();
|
||||
|
@ -96,5 +108,35 @@ namespace GraphicsControls.Android
|
|||
{
|
||||
Control?.InvalidateDrawable();
|
||||
}
|
||||
|
||||
void UpdateAutomationProperties()
|
||||
{
|
||||
if (Control == null)
|
||||
return;
|
||||
|
||||
var defaultContentDescription = Control.ContentDescription;
|
||||
|
||||
string value = ConcatenateNameAndHelpText(Element);
|
||||
|
||||
var contentDescription = !string.IsNullOrWhiteSpace(value) ? value : defaultContentDescription;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(contentDescription) && Element is Element element)
|
||||
contentDescription = element.AutomationId;
|
||||
|
||||
Control.ContentDescription = contentDescription;
|
||||
}
|
||||
|
||||
internal static string ConcatenateNameAndHelpText(BindableObject Element)
|
||||
{
|
||||
var name = (string)Element.GetValue(AutomationProperties.NameProperty);
|
||||
var helpText = (string)Element.GetValue(AutomationProperties.HelpTextProperty);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return helpText;
|
||||
if (string.IsNullOrWhiteSpace(helpText))
|
||||
return name;
|
||||
|
||||
return $"{name}. {helpText}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,6 +49,8 @@ namespace GraphicsControls.iOS
|
|||
Control.Drawable = Element;
|
||||
|
||||
UpdateContent();
|
||||
UpdateAutomationHelpText();
|
||||
UpdateAutomationName();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +60,10 @@ namespace GraphicsControls.iOS
|
|||
|
||||
if (e.PropertyName == ContentView.ContentProperty.PropertyName)
|
||||
UpdateContent();
|
||||
else if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
|
||||
UpdateAutomationHelpText();
|
||||
else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName)
|
||||
UpdateAutomationName();
|
||||
|
||||
Control?.InvalidateDrawable();
|
||||
}
|
||||
|
@ -173,5 +179,15 @@ namespace GraphicsControls.iOS
|
|||
var content = Subviews[0];
|
||||
BringSubviewToFront(content);
|
||||
}
|
||||
|
||||
void UpdateAutomationHelpText()
|
||||
{
|
||||
Control?.SetAccessibilityHint(Element);
|
||||
}
|
||||
|
||||
void UpdateAutomationName()
|
||||
{
|
||||
Control?.SetAccessibilityLabel(Element);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,6 +47,8 @@ namespace GraphicsControls.Mac
|
|||
Control.Drawable = Element;
|
||||
|
||||
UpdateContent();
|
||||
UpdateAutomationHelpText();
|
||||
UpdateAutomationName();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,6 +58,10 @@ namespace GraphicsControls.Mac
|
|||
|
||||
if (e.PropertyName == ContentView.ContentProperty.PropertyName)
|
||||
UpdateContent();
|
||||
else if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
|
||||
UpdateAutomationHelpText();
|
||||
else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName)
|
||||
UpdateAutomationName();
|
||||
|
||||
Control?.InvalidateDrawable();
|
||||
}
|
||||
|
@ -143,5 +149,15 @@ namespace GraphicsControls.Mac
|
|||
content.RemoveFromSuperview();
|
||||
AddSubview(content);
|
||||
}
|
||||
|
||||
void UpdateAutomationHelpText()
|
||||
{
|
||||
Control?.SetAccessibilityHint(Element);
|
||||
}
|
||||
|
||||
void UpdateAutomationName()
|
||||
{
|
||||
Control?.SetAccessibilityLabel(Element);
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче