From 65fcd4a0cef3d35b519967e8e0a36c102e325f4b Mon Sep 17 00:00:00 2001 From: Chiara Mooney <34109996+chiaramooney@users.noreply.github.com> Date: Thu, 25 Feb 2021 11:12:14 -0800 Subject: [PATCH 1/3] Fix announceForAccessibility --- .../Modules/AccessibilityInfoModule.cpp | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp b/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp index a09dfe49deb..7cb65e12a1a 100644 --- a/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp @@ -41,27 +41,17 @@ 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 find something to try 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 add a temporary control to raise the notification event from. - 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(); - } - } + auto textBlock = xaml::Controls::TextBlock(); - if (!element) { + if (!textBlock) { return; } - auto peer = xaml::Automation::Peers::FrameworkElementAutomationPeer::FromElement(element); + auto peer = xaml::Automation::Peers::FrameworkElementAutomationPeer::FromElement(textBlock); if (!peer) { return; From a756e8f8b32948a9fbd28c067598207dffbfab90 Mon Sep 17 00:00:00 2001 From: Chiara Mooney <34109996+chiaramooney@users.noreply.github.com> Date: Thu, 25 Feb 2021 11:15:46 -0800 Subject: [PATCH 2/3] Change files --- ...ative-windows-29f65fa8-43ca-4485-9da4-0168ac84cd17.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-29f65fa8-43ca-4485-9da4-0168ac84cd17.json diff --git a/change/react-native-windows-29f65fa8-43ca-4485-9da4-0168ac84cd17.json b/change/react-native-windows-29f65fa8-43ca-4485-9da4-0168ac84cd17.json new file mode 100644 index 00000000000..87a580ff0c8 --- /dev/null +++ b/change/react-native-windows-29f65fa8-43ca-4485-9da4-0168ac84cd17.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Fix announceForAccessibility", + "packageName": "react-native-windows", + "email": "34109996+chiaramooney@users.noreply.github.com", + "dependentChangeType": "patch" +} From 95328446fad1af4227074d294051df3fe4fd517d Mon Sep 17 00:00:00 2001 From: Chiara Mooney <34109996+chiaramooney@users.noreply.github.com> Date: Thu, 25 Feb 2021 12:17:25 -0800 Subject: [PATCH 3/3] Fix Formatting Issues --- vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp b/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp index 7cb65e12a1a..ee4e68f5674 100644 --- a/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp @@ -41,7 +41,6 @@ void AccessibilityInfo::setAccessibilityFocus(double /*reactTag*/) noexcept { void AccessibilityInfo::announceForAccessibility(std::string announcement) noexcept { m_context.UIDispatcher().Post([context = m_context, announcement = std::move(announcement)] { - // 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.