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": "[Fabric] Implement announceForAccessibility in AccessibilityInfo Module",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@

namespace winrt::Microsoft::ReactNative::implementation {

ReactPropertyId<winrt::Microsoft::ReactNative::ReactNonAbiValue<
winrt::weak_ref<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>>>
ReactNativeIsland::LastFocusedReactNativeIslandProperty() noexcept {
static const ReactPropertyId<winrt::Microsoft::ReactNative::ReactNonAbiValue<
winrt::weak_ref<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>>>
prop{L"ReactNative.Composition", L"ReactNativeIsland"};
return prop;
}
constexpr float loadingActivitySize = 12.0f;
constexpr float loadingActivityHorizontalOffset = 16.0f;
constexpr float loadingBarHeight = 36.0f;
Expand Down Expand Up @@ -861,6 +869,20 @@ winrt::Microsoft::UI::Content::ContentIsland ReactNativeIsland::Island() {
}
}
});
focusController.GotFocus(
[weakThis = get_weak()](const auto &sender, const winrt::Microsoft::UI::Input::FocusChangedEventArgs &args) {
if (auto pThis = weakThis.get()) {
// Set the island to React context so it can be accessed by native modules
if (pThis->m_context && pThis->m_island) {
auto properties = pThis->m_context.Properties();
properties.Set(
ReactNativeIsland::LastFocusedReactNativeIslandProperty(),
winrt::Microsoft::ReactNative::ReactNonAbiValue<
winrt::weak_ref<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>>{
std::in_place, weakThis});
}
}
});

// ContentIsland does not support weak_ref, so we cannot use auto_revoke for these events
m_islandAutomationProviderRequestedToken = m_island.AutomationProviderRequested(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct ReactNativeIsland
~ReactNativeIsland() noexcept;

ReactNativeIsland(const winrt::Microsoft::UI::Composition::Compositor &compositor) noexcept;
static ReactPropertyId<winrt::Microsoft::ReactNative::ReactNonAbiValue<
winrt::weak_ref<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>>>
LastFocusedReactNativeIslandProperty() noexcept;
ReactNativeIsland(const winrt::Microsoft::ReactNative::Composition::PortalComponentView &portal) noexcept;

static winrt::Microsoft::ReactNative::ReactNativeIsland CreatePortal(
Expand Down
29 changes: 29 additions & 0 deletions vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <UI.Xaml.Automation.Peers.h>
#include <UI.Xaml.Controls.h>
#include <XamlUtils.h>
#else
#include <Fabric/Composition/ReactNativeIsland.h>
#endif
#include <uiautomationcore.h>
#include <uiautomationcoreapi.h>
Expand Down Expand Up @@ -79,6 +81,33 @@ void AccessibilityInfo::announceForAccessibility(std::wstring announcement) noex
xaml::Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent,
hstr,
hstr);
#else
if (auto weakIslandWrapper = context.Properties().Get(
winrt::Microsoft::ReactNative::implementation::ReactNativeIsland::LastFocusedReactNativeIslandProperty())) {
if (auto weakIsland = weakIslandWrapper.Value()) {
if (auto reactNativeIsland = weakIsland.get()) {
if (auto uiaprovider = reactNativeIsland->GetUiaProvider()) {
if (auto rawProvider = uiaprovider.try_as<IRawElementProviderSimple>()) {
// Convert announcement to BSTR for UIA
winrt::hstring hstrAnnouncement{announcement};
auto bstrAnnouncement = SysAllocString(hstrAnnouncement.c_str());
if (bstrAnnouncement) {
// Raise the UIA notification event
HRESULT hr = UiaRaiseNotificationEvent(
rawProvider.get(),
NotificationKind_Other,
NotificationProcessing_ImportantMostRecent,
bstrAnnouncement,
bstrAnnouncement);
// Clean up BSTRs
SysFreeString(bstrAnnouncement);
}
}
}
}
}
}

#endif
});
}
Expand Down
Loading