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": "Add Implementation for accessibilityActions",
"packageName": "react-native-windows",
"email": "34109996+chiaramooney@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::Invoke() {
if (spProviderSimple != nullptr) {
UiaRaiseAutomationEvent(spProviderSimple.get(), UIA_Invoke_InvokedEventId);
}
DispatchAccessibilityAction(m_view, "invoke");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a difference between these two?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the action should be the same. "activate" is just the action name that RN is using and "invoke" is the Windows name for the same action. I figured we should just support both names, so the user can either use the windows action name or the cross-plat action name.

DispatchAccessibilityAction(m_view, "activate");

return S_OK;
}
Expand All @@ -394,6 +396,7 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::ScrollIntoView() {
winrt::Microsoft::ReactNative::implementation::BringIntoViewOptions scrollOptions;
winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(strongView)
->StartBringIntoView(std::move(scrollOptions));
DispatchAccessibilityAction(m_view, "scrollIntoView");

return S_OK;
}
Expand Down Expand Up @@ -422,6 +425,7 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::SetValue(LPCWSTR val) {

winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(strongView)
->setAcccessiblityValue(winrt::to_string(val));
DispatchAccessibilityAction(m_view, "setValue");
return S_OK;
}

Expand Down Expand Up @@ -488,6 +492,7 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::Toggle() {
return UIA_E_ELEMENTNOTAVAILABLE;

winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(strongView)->Toggle();
DispatchAccessibilityAction(m_view, "toggle");
return S_OK;
}

Expand Down
22 changes: 22 additions & 0 deletions vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,26 @@ std::string extractAccessibilityValue(const facebook::react::AccessibilityValue
}
}

void DispatchAccessibilityAction(::Microsoft::ReactNative::ReactTaggedView &view, const std::string &action) noexcept {
auto strongView = view.view();

if (!strongView)
return;

auto baseView = strongView.try_as<winrt::Microsoft::ReactNative::Composition::implementation::ComponentView>();
if (baseView == nullptr)
return;

auto props = std::static_pointer_cast<const facebook::react::ViewProps>(baseView->props());
if (props == nullptr)
return;

auto accessibilityActions = props->accessibilityActions;
for (size_t i = 0; i < accessibilityActions.size(); i++) {
if (accessibilityActions[i].name == action) {
baseView->GetEventEmitter()->onAccessibilityAction(action);
}
}
}

} // namespace winrt::Microsoft::ReactNative::implementation
2 changes: 2 additions & 0 deletions vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ long GetLiveSetting(const std::string &liveRegion) noexcept;

std::string extractAccessibilityValue(const facebook::react::AccessibilityValue &value) noexcept;

void DispatchAccessibilityAction(::Microsoft::ReactNative::ReactTaggedView &view, const std::string &action) noexcept;

} // namespace winrt::Microsoft::ReactNative::implementation