Skip to content

Add support for AutomationPeer#141

Merged
miguelrochefort merged 1 commit intomasterfrom
dev/miro/accessibility
Aug 29, 2018
Merged

Add support for AutomationPeer#141
miguelrochefort merged 1 commit intomasterfrom
dev/miro/accessibility

Conversation

@miguelrochefort
Copy link
Copy Markdown
Contributor

No description provided.

- Avoid stacking `TextBlock`s inside a `Panel` when you can use `Inlines` inside a `TextBlock` (using `LineBreak` if necessary). This allows the screen reader to read all the text at once, instead of having the user select every part manually.
- Use a converter to trim long text. While a `TextBlock` might ellipsize long text, the screen reader will read the entire text provided.
- Avoid creating custom controls when you can use built-in ones. If you must, make sure to implement and provide an appropriate `AutomationPeer`.
- You can disable accessibility focus of native elements using `android:ImportantForAccessibility="No"` and `ios:IsAccessibilityElement="False"`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a UWP/Uno equivalent of these properties?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can disable accessibility focus of UWP/Uno elements using AutomationProperties.AccessibilityView="Raw".

It won't work on native elements, hence the ImportantFocAccessibility/IsAccessibilityElement workaround.

}
else
{
if ("".Log().IsEnabled(LogLevel.Error))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be typeof(CommandBarRenderer).Log()?

{
#region Public

public void InvalidatePeer()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NotImplemented]?

{
public partial class ComboBoxAutomationPeer : SelectorAutomationPeer, Provider.IExpandCollapseProvider, Provider.IValueProvider, Provider.IWindowProvider
{
public ExpandCollapseState ExpandCollapseState
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NotImplemented]


private int GetMaxTextLength()
{
return Owner is TextBox textBox ? textBox.MaxLength : 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not virtual? Should there be a TODO to use ITextProvider?

Copy link
Copy Markdown
Contributor Author

@miguelrochefort miguelrochefort Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just feeding Android's AccessibilityNodeInfo what it wants. I don't know if there's an equivalent in AutomationPeer's API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an ITextProvider interface but it sounds like a mess: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.automation.provider.itextprovider

ITextProvider, ITextProvider2 and ITextRangeProvider aren't implemented by any existing Windows Runtime automation peers using this definition of the interface. The text models supported by Windows Runtime text controls such as TextBox and RichTextBlock do implement some of these patterns, but do so at a native level that doesn't appear in the Windows Runtime definitions of the API surface. For more info, see the peer classes for the various Windows Runtime text controls.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find anything about maximum text length at first glance.

{
if (Owner is View view && AutomationProperties.GetAccessibilityView(Owner) != AccessibilityView.Raw)
{
// TODO: How expensive is this? Is this called recursively for all children?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored that part, confirmed this wasn't a problem, and explained why.

public partial class ImplicitTextBlock : TextBlock
{
public ImplicitTextBlock() { }
public ImplicitTextBlock(DependencyObject parent)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the reference to the ContentControl being held? Ie is there any risk of a memory leak?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It only needs its parent to retrieve its AutomationProperties.AccessibilityView value once.

IsChecked = false;
}

protected virtual void OnToggle()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnAutomationToggle()? Is it used/useful in any other context?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnToggle is part of ToggleButton's contract.

AutomationPeerToggle exists to allow OnToggle to be called from automation peers.

Comment thread src/Uno.UI/UI/Xaml/IFrameworkElement.cs Outdated
{
(e as View).ContentDescription = e.GetType().ToString();
// TODO: This causes Android to cycle through every visible IFrameworkElement every time the accessibility focus is changed
// and calls the overriden InitializeAccessibilityNodeInfo method. This could eventually cause performance issues when accessibility is enabled.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is 'eventually'? Is this a serious performance concern?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'eventually' is if we have complex UI with lots of elements. I've only noticed lags when cycling through accessible elements in debug.

The performance problem seem to be due to interop. It should only affect focus change on devices with TalkBack turned on. A possible optimization could be to set this value to false if an element's CreateAutomationPeer returns null.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the second paragraph of your reply to the comment.

@miguelrochefort miguelrochefort force-pushed the dev/miro/accessibility branch 3 times, most recently from 2b7ac0e to afd33ac Compare August 22, 2018 15:54
Copy link
Copy Markdown
Member

@carldebilly carldebilly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supports

new XElement("string",
new XAttribute("formatted", "false"), // allows special characters (%, $, etc.)
new XAttribute("name", resource.Key),
new XAttribute("name", AndroidResourceNameEncoder.Encode(resource.Key)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is related to AutomationPeers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a different PR: #156

public static IEnumerable<UIView> EnumerateAllChildren(this UIView view, int maxDepth = 20)
{
return FindSubviews(view, _ => true, maxDepth);
var children = view.GetChildren().OfType<UIElement>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

children variable is not used...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return key
.Replace('[', '_')
.Replace(']', '_')
.Replace(':', '_');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it something called often? Could have perf issues.

@@ -0,0 +1,47 @@
namespace Windows.UI.Xaml.Automation.Peers
{
public enum AutomationControlType
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alpha ordering?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... or is this order important? If yes needs a comment about it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order is important. I added the values.

@miguelrochefort miguelrochefort force-pushed the dev/miro/accessibility branch 3 times, most recently from c0e02d3 to 1fe6e7e Compare August 29, 2018 19:11
@miguelrochefort miguelrochefort merged commit 7e70a42 into master Aug 29, 2018
@carldebilly carldebilly deleted the dev/miro/accessibility branch August 31, 2018 00:15
kazo0 pushed a commit to kazo0/uno that referenced this pull request Mar 6, 2026
…-fix

fix(snackbar): Fixed Error binding nullref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants