Skip to content

Commit a00ea41

Browse files
authored
[WIP] Implement UIA Invoke Method (#11874)
* Implement Invoke * Change files * Format * Adjust Call * Adjust Call * Address Feedback * Format * Fix * Merge * Address Feedback * Fix * Remove * Fix * Format * Fix UIA Tree Issue * Address Feedback * Implement Invoke * Change files * Remove Unneeded * Format
1 parent 13435fa commit a00ea41

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Implement Invoke",
4+
"packageName": "react-native-windows",
5+
"email": "34109996+chiaramooney@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::GetPatternProvider(PATTE
129129

130130
*pRetVal = nullptr;
131131

132+
auto strongView = m_view.view();
133+
if (strongView == nullptr)
134+
return UIA_E_ELEMENTNOTAVAILABLE;
135+
136+
auto props = std::static_pointer_cast<const facebook::react::ViewProps>(strongView->props());
137+
if (props == nullptr)
138+
return UIA_E_ELEMENTNOTAVAILABLE;
139+
auto accessibilityRole = props->accessibilityRole;
140+
// Invoke control pattern is used to support controls that do not maintain state
141+
// when activated but rather initiate or perform a single, unambiguous action.
142+
if (patternId == UIA_InvokePatternId &&
143+
(accessibilityRole == "button" || accessibilityRole == "imagebutton" || accessibilityRole == "link" ||
144+
accessibilityRole == "splitbutton" || (accessibilityRole == "menuitem" && props->onAccessibilityTap) ||
145+
(accessibilityRole == "treeitem" && props->onAccessibilityTap))) {
146+
*pRetVal = static_cast<IInvokeProvider *>(this);
147+
AddRef();
148+
}
149+
132150
return S_OK;
133151
}
134152

@@ -278,4 +296,24 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::get_HostRawElementProvid
278296
return S_OK;
279297
}
280298

299+
HRESULT __stdcall CompositionDynamicAutomationProvider::Invoke() {
300+
auto strongView = m_view.view();
301+
302+
if (!strongView)
303+
return UIA_E_ELEMENTNOTAVAILABLE;
304+
305+
auto baseView = std::static_pointer_cast<::Microsoft::ReactNative::CompositionBaseComponentView>(strongView);
306+
if (baseView == nullptr)
307+
return UIA_E_ELEMENTNOTAVAILABLE;
308+
309+
baseView.get()->GetEventEmitter().get()->onAccessibilityTap();
310+
auto uiaProvider = baseView->EnsureUiaProvider();
311+
auto spProviderSimple = uiaProvider.try_as<IRawElementProviderSimple>();
312+
if (spProviderSimple != nullptr) {
313+
UiaRaiseAutomationEvent(spProviderSimple.get(), UIA_Invoke_InvokedEventId);
314+
}
315+
316+
return S_OK;
317+
}
318+
281319
} // namespace winrt::Microsoft::ReactNative::implementation

vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
#include <Fabric/ReactTaggedView.h>
55
#include <UIAutomation.h>
66
#include <inspectable.h>
7+
#include <uiautomationcore.h>
78

89
namespace winrt::Microsoft::ReactNative::implementation {
910

1011
class CompositionDynamicAutomationProvider : public winrt::implements<
1112
CompositionDynamicAutomationProvider,
1213
IInspectable,
1314
IRawElementProviderFragment,
14-
IRawElementProviderSimple> {
15+
IRawElementProviderSimple,
16+
IInvokeProvider> {
1517
public:
1618
CompositionDynamicAutomationProvider(
1719
const std::shared_ptr<::Microsoft::ReactNative::CompositionBaseComponentView> &componentView) noexcept;
@@ -31,6 +33,9 @@ class CompositionDynamicAutomationProvider : public winrt::implements<
3133
virtual HRESULT __stdcall get_HostRawElementProvider(IRawElementProviderSimple **pRetVal) override;
3234
// virtual HRESULT __stdcall ShowContextMenu() noexcept override;
3335

36+
// inherited via IInvokeProvider
37+
virtual HRESULT __stdcall Invoke() override;
38+
3439
private:
3540
::Microsoft::ReactNative::ReactTaggedView m_view;
3641
};

0 commit comments

Comments
 (0)