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": "Implement announceForAccessibility for Fabric using Win32 UIA",
"packageName": "react-native-windows",
"email": "198982749+Copilot@users.noreply.github.com",
"dependentChangeType": "patch"
}
48 changes: 48 additions & 0 deletions vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,54 @@ void AccessibilityInfo::announceForAccessibility(std::wstring announcement) noex
xaml::Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent,
hstr,
hstr);
#else
// Fabric implementation using Win32 UIA
if (!UiaClientsAreListening()) {
return;
}

HWND hwnd = ::GetActiveWindow();
if (!hwnd) {
return;
}

IRawElementProviderSimple *provider = nullptr;
HRESULT hrProvider = UiaHostProviderFromHwnd(hwnd, &provider);
if (FAILED(hrProvider) || !provider) {
return;
}

// Convert announcement string to BSTR
BSTR bstrAnnouncement = SysAllocString(announcement.c_str());
if (!bstrAnnouncement) {
provider->Release();
return;
}

// Create a GUID and get string form for activityId
GUID guid;
wchar_t guidString[40] = {};
BSTR bstrActivityId = nullptr;

if (SUCCEEDED(CoCreateGuid(&guid))) {
int len = StringFromGUID2(guid, guidString, ARRAYSIZE(guidString));
if (len > 1) {
bstrActivityId = SysAllocString(guidString);
}
}

if (!bstrActivityId) {
SysFreeString(bstrAnnouncement);
provider->Release();
return;
}

HRESULT hr = UiaRaiseNotificationEvent(
provider, NotificationKind_Other, NotificationProcessing_ImportantMostRecent, bstrAnnouncement, bstrActivityId);

SysFreeString(bstrAnnouncement);
SysFreeString(bstrActivityId);
provider->Release();
#endif
});
}
Expand Down
Loading