Skip to content
Closed
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": "value provider changes",
"packageName": "react-native-windows",
"email": "yajurgrover24@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::GetPatternProvider(PATTE
if (props == nullptr)
return UIA_E_ELEMENTNOTAVAILABLE;
auto accessibilityRole = props->accessibilityRole;
auto accessibilityValue = props->accessibilityValue;
// Invoke control pattern is used to support controls that do not maintain state
// when activated but rather initiate or perform a single, unambiguous action.
if (patternId == UIA_InvokePatternId &&
Expand All @@ -147,6 +148,11 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::GetPatternProvider(PATTE
AddRef();
}

if (patternId == UIA_ValuePatternId && accessibilityValue.text.has_value()) {
*pRetVal = static_cast<IValueProvider *>(this);
AddRef();
}

return S_OK;
}

Expand Down Expand Up @@ -327,4 +333,53 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::Invoke() {
return S_OK;
}

BSTR StringToBSTR(const std::string &str) {
// Calculate the required BSTR size in bytes
int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
if (len == 0) {
return nullptr; // Conversion error
}

// Allocate memory for the BSTR
BSTR bstr = SysAllocStringLen(nullptr, len - 1); // len includes the null terminator

// Convert the std::string to BSTR
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, bstr, len);

return bstr;
}

HRESULT __stdcall CompositionDynamicAutomationProvider::SetValue(LPCWSTR val) {
auto strongView = m_view.view();

if (!strongView)
return UIA_E_ELEMENTNOTAVAILABLE;

auto props = std::static_pointer_cast<const facebook::react::ViewProps>(strongView->props());
std::string value = winrt::to_string(val);
auto baseView = std::static_pointer_cast<::Microsoft::ReactNative::CompositionBaseComponentView>(strongView);
if (baseView == nullptr)
return UIA_E_ELEMENTNOTAVAILABLE;
baseView->updateAccessibilityValue(value);
return S_OK;
}

HRESULT __stdcall CompositionDynamicAutomationProvider::get_Value(BSTR *pRetVal) {
if (pRetVal == nullptr)
return E_POINTER;
auto strongView = m_view.view();

if (!strongView)
return UIA_E_ELEMENTNOTAVAILABLE;

auto props = std::static_pointer_cast<const facebook::react::ViewProps>(strongView->props());
*pRetVal = StringToBSTR(*props->accessibilityValue.text);

return S_OK;
}

HRESULT __stdcall CompositionDynamicAutomationProvider::get_IsReadOnly(BOOL *pRetVal) {
return S_OK;
}

} // namespace winrt::Microsoft::ReactNative::implementation
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class CompositionDynamicAutomationProvider : public winrt::implements<
IInspectable,
IRawElementProviderFragment,
IRawElementProviderSimple,
IInvokeProvider> {
IInvokeProvider,
IValueProvider> {
public:
CompositionDynamicAutomationProvider(
const std::shared_ptr<::Microsoft::ReactNative::CompositionBaseComponentView> &componentView) noexcept;
Expand All @@ -36,8 +37,13 @@ class CompositionDynamicAutomationProvider : public winrt::implements<
// inherited via IInvokeProvider
virtual HRESULT __stdcall Invoke() override;

// inherited via IValueProvider
virtual HRESULT __stdcall SetValue(LPCWSTR val) override;
virtual HRESULT __stdcall get_Value(BSTR *pRetVal) override;
virtual HRESULT __stdcall get_IsReadOnly(BOOL *pRetVal) override;

private:
::Microsoft::ReactNative::ReactTaggedView m_view;
};

} // namespace winrt::Microsoft::ReactNative::implementation
} // namespace winrt::Microsoft::ReactNative::implementation
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,17 @@ void CompositionBaseComponentView::EnsureTransformMatrixFacade() noexcept {
}
}

void CompositionBaseComponentView::updateAccessibilityValue(std::string newValue) noexcept {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@acoates-ms The value being set in SetValue() goes here and then is modified through a call to UpdateUiaProperty() - which from my understanding also calls the UiaRaiseAutomationPropertyChangedEvent(), updating insights that the property has changed. Do I still need to add a UiaRaiseAutomationEvent() here as well?

auto props = std::static_pointer_cast<const facebook::react::ViewProps>(this->props());
if (newValue != props->accessibilityValue.text) {
auto provider = EnsureUiaProvider();
if (provider != nullptr) {
winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty(
provider, UIA_ValueValuePropertyId, *props->accessibilityValue.text, newValue);
}
}
}

facebook::react::SharedViewEventEmitter CompositionBaseComponentView::eventEmitter() noexcept {
return m_eventEmitter;
}
Expand Down Expand Up @@ -1387,6 +1398,11 @@ void CompositionViewComponentView::updateProps(
m_visual.Opacity(newViewProps.opacity);
}

if (oldViewProps.accessibilityValue.text.has_value() && newViewProps.accessibilityValue.text.has_value() &&
oldViewProps.accessibilityValue.text != newViewProps.accessibilityValue.text) {
updateAccessibilityValue(*newViewProps.accessibilityValue.text);
}

// update BaseComponentView props
updateAccessibilityProps(oldViewProps, newViewProps);
updateShadowProps(oldViewProps, newViewProps, m_visual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct CompositionBaseComponentView : public IComponentView,
bool runOnChildren(bool forward, Mso::Functor<bool(IComponentView &)> &fn) noexcept override;
void onFocusLost() noexcept override;
void onFocusGained() noexcept override;
void updateAccessibilityValue(std::string newValue) noexcept;
void onPointerEntered(
const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept override;
void onPointerExited(
Expand Down