Skip to content

Conversation

@chiaramooney
Copy link
Contributor

@chiaramooney chiaramooney commented Feb 25, 2021

Resolve #5908

Why
announceForAccessibility method in the AccessibilityInfo module failed to announce messages.

What
The API for the method does not include a reference to a RN component as a parameter but Windows requires an element to announce from. The previous implementation tried to pass in Xaml::Window::Content into FrameworkElementAutomationPeer::FromElement to create an automation peer, but this approach always resulted in the peer being null and no announcement could be made.

Altered the code such that a Xaml Control (TextBlock) is passed into FrameworkElementAutomationPeer::FromElement instead. This caused the peer returned to be non-null and the announcement could be fired.

Testing
Created an RNW app and altered Microsoft.ReactNative inside of tester app with the changes to AccessibilityInfo. Was able to hear announcement when announceForAccessibility was called.

Microsoft Reviewers: Open in CodeFlow

@chiaramooney chiaramooney requested a review from a team as a code owner February 25, 2021 19:25
@ghost ghost added the Area: Accessibility label Feb 25, 2021
element = xamlRoot.Content();
}
}
auto textBlock = xaml::Controls::TextBlock();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: seems like a UIElement might be enough - https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.automation.peers.frameworkelementautomationpeer.fromelement?view=winrt-19041
Would be a little cheaper to create - can you try that?

Copy link
Member

Choose a reason for hiding this comment

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

you can't instantiate UIElement directly, only subclasses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I leave it as is? Or is there a cheaper subclass I should instantiate instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might work with a Control

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok looks like Control also can't be instantiated directly only its subclasses.

@chiaramooney chiaramooney requested a review from asklar February 25, 2021 20:41
@chiaramooney chiaramooney merged commit 72ad78a into microsoft:master Mar 1, 2021
@chiaramooney chiaramooney deleted the cm-fix-accessibility-announce branch March 1, 2021 17:01
rozele pushed a commit to rozele/react-native-windows that referenced this pull request Oct 6, 2021
Summary:
Cherry picks:
microsoft#5849
microsoft#7220
microsoft#7290

Test Plan: See D29689294 Test Plan

Reviewers: ericroz

Reviewed By: ericroz

Subscribers: eliwhite

Differential Revision: https://phabricator.intern.facebook.com/D30940769

Tasks: T85606613

Signature: 30940769:1631724353:41db1d978132f06502803cfb4df0323f6da84732
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AccessibilityInfo::announceForAccessibility fails to announce

3 participants