Skip to content

Commit

Permalink
[Fabric] Add Support for accessibilityActions and onAccessibilityActi…
Browse files Browse the repository at this point in the history
…on (#13674)

* Add Implementation for accessibilityActions

* Add activate action

* Format

* Change files
  • Loading branch information
chiaramooney authored Sep 9, 2024
1 parent 0ec2b30 commit f756797
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
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": "[email protected]",
"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");
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

0 comments on commit f756797

Please sign in to comment.