Skip to content

Commit 2f77b71

Browse files
committed
Implement Invoke
1 parent d8c42f3 commit 2f77b71

File tree

6 files changed

+52
-1
lines changed

6 files changed

+52
-1
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,34 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::get_HostRawElementProvid
272272
return S_OK;
273273
}
274274

275+
HRESULT CompositionDynamicAutomationProvider::Invoke() {
276+
auto strongView = m_view.view();
277+
278+
if (!strongView)
279+
return UIA_E_ELEMENTNOTAVAILABLE;
280+
281+
auto baseView = std::static_pointer_cast<::Microsoft::ReactNative::CompositionBaseComponentView>(strongView);
282+
if (baseView == nullptr)
283+
return UIA_E_ELEMENTNOTAVAILABLE;
284+
285+
// Currently calls both onAccessibilityTap and onClick.
286+
// To match Paper behavior, onAccessibilityTap only called if onClick is not defined.
287+
// Events dispatched for any control.
288+
// To match Paper, Event should only dispatch for pressable controls without state.
289+
baseView.get()->GetEventEmitter().get()->onAccessibilityTap();
290+
baseView.get()->GetEventEmitter().get()->onClick();
291+
292+
auto rootCV = strongView->rootComponentView();
293+
if (rootCV == nullptr)
294+
return UIA_E_ELEMENTNOTAVAILABLE;
295+
296+
auto uiaProvider = rootCV->EnsureUiaProvider();
297+
auto spProviderSimple = uiaProvider.try_as<IRawElementProviderSimple>();
298+
if (spProviderSimple != nullptr) {
299+
UiaRaiseAutomationEvent(spProviderSimple.get(), UIA_Invoke_InvokedEventId);
300+
}
301+
302+
return S_OK;
303+
}
304+
275305
} // 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 Invoke() override;
38+
3439
private:
3540
::Microsoft::ReactNative::ReactTaggedView m_view;
3641
};

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ HRESULT __stdcall CompositionRootAutomationProvider::get_HostRawElementProvider(
6565
return S_OK;
6666
}
6767

68+
HRESULT CompositionRootAutomationProvider::Invoke() {
69+
return S_OK;
70+
}
71+
6872
HRESULT __stdcall CompositionRootAutomationProvider::get_BoundingRectangle(UiaRect *pRetVal) {
6973
if (pRetVal == nullptr)
7074
return E_POINTER;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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
struct CompositionRootView;
@@ -14,6 +15,7 @@ class CompositionRootAutomationProvider : public winrt::implements<
1415
IRawElementProviderFragmentRoot,
1516
IRawElementProviderFragment,
1617
IRawElementProviderSimple,
18+
IInvokeProvider,
1719
IRawElementProviderAdviseEvents> {
1820
public:
1921
// inherited via IRawElementProviderFragmentRoot
@@ -35,6 +37,9 @@ class CompositionRootAutomationProvider : public winrt::implements<
3537
virtual HRESULT __stdcall GetPropertyValue(PROPERTYID propertyId, VARIANT *pRetVal) override;
3638
virtual HRESULT __stdcall get_HostRawElementProvider(IRawElementProviderSimple **pRetVal) override;
3739

40+
// inherited via IInvokeProvider
41+
virtual HRESULT Invoke() override;
42+
3843
// IRawElementProviderAdviseEvents
3944
virtual HRESULT __stdcall AdviseEventAdded(EVENTID idEvent, SAFEARRAY *psaProperties) override;
4045
virtual HRESULT __stdcall AdviseEventRemoved(EVENTID idEvent, SAFEARRAY *psaProperties) override;

vnext/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/ViewEventEmitter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,9 @@ void ViewEventEmitter::onKeyDown(KeyboardEvent const &event) const {
156156
});
157157
}
158158

159+
// [Windows]
160+
void ViewEventEmitter::onClick() const {
161+
dispatchEvent("topClick");
162+
}
163+
159164
} // namespace facebook::react

vnext/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/ViewEventEmitter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class ViewEventEmitter : public TouchEventEmitter {
5757
void onKeyUp(KeyboardEvent const &event) const; // [Windows]
5858
void onKeyDown(KeyboardEvent const &event) const; // [Windows]
5959

60+
void onClick() const; // [Windows]
61+
6062
private:
6163
/*
6264
* Contains the most recent `frame` and a `mutex` protecting access to it.

0 commit comments

Comments
 (0)