Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fix announceForAccessibility",
"packageName": "react-native-windows",
"email": "34109996+chiaramooney@users.noreply.github.com",
"dependentChangeType": "patch"
}
21 changes: 5 additions & 16 deletions vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,16 @@ void AccessibilityInfo::setAccessibilityFocus(double /*reactTag*/) noexcept {

void AccessibilityInfo::announceForAccessibility(std::string announcement) noexcept {
m_context.UIDispatcher().Post([context = m_context, announcement = std::move(announcement)] {
xaml::UIElement element{nullptr};
// Windows requires a specific element to announce from. Unfortunately the react-native API does not provide a tag
// So we need to add a temporary control to raise the notification event from.

// Windows requires a specific element to announce from. Unfortunately the react-native API does not provide a tag
// So we need to find something to try to raise the notification event from
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.


if (auto window = xaml::Window::Current()) {
element = window.Content();
}

if (!element && react::uwp::Is19H1OrHigher()) {
// XamlRoot added in 19H1
if (auto xamlRoot = React::XamlUIService::GetXamlRoot(context.Properties().Handle())) {
element = xamlRoot.Content();
}
}

if (!element) {
if (!textBlock) {
return;
}

auto peer = xaml::Automation::Peers::FrameworkElementAutomationPeer::FromElement(element);
auto peer = xaml::Automation::Peers::FrameworkElementAutomationPeer::FromElement(textBlock);

if (!peer) {
return;
Expand Down