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": "[Fabric] Fix for Text and TextInput focus issue with screen readers.",
"packageName": "react-native-windows",
"email": "kvineeth@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "[Fabric] Implement announceForAccessibility in AccessibilityInfo Module",
"packageName": "react-native-windows",
"email": "kvineeth@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "[Fabric] Raising UIA Event if Toggle State Changes in Switch Component",
"packageName": "react-native-windows",
"email": "kvineeth@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,30 @@ CompositionTextRangeProvider::CompositionTextRangeProvider(
}

HRESULT __stdcall CompositionTextRangeProvider::Clone(ITextRangeProvider **pRetVal) {
// no-op
*pRetVal = nullptr;
if (pRetVal == nullptr)
return E_POINTER;

auto clone = winrt::make<winrt::Microsoft::ReactNative::implementation::CompositionTextRangeProvider>(
m_view.view().as<winrt::Microsoft::ReactNative::Composition::ComponentView>(), m_parentProvider.get());
*pRetVal = clone.detach();
return S_OK;
}

HRESULT __stdcall CompositionTextRangeProvider::Compare(ITextRangeProvider *range, BOOL *pRetVal) {
// no-op
*pRetVal = false;
if (pRetVal == nullptr)
return E_POINTER;
if (range == nullptr) {
*pRetVal = FALSE;
return S_OK;
}

// Try to cast to our type , considering provider only supports a single range per view
auto other = dynamic_cast<CompositionTextRangeProvider *>(range);
if (other && other->m_view.view() == m_view.view()) {
*pRetVal = TRUE;
} else {
*pRetVal = FALSE;
}
return S_OK;
}

Expand All @@ -34,7 +50,10 @@ HRESULT __stdcall CompositionTextRangeProvider::CompareEndpoints(
ITextRangeProvider *targetRange,
TextPatternRangeEndpoint targetEndpoint,
int *pRetVal) {
// no-op
if (pRetVal == nullptr)
return E_POINTER;

// For a single-range provider, always equal:
*pRetVal = 0;
return S_OK;
}
Expand Down Expand Up @@ -98,13 +117,13 @@ HRESULT __stdcall CompositionTextRangeProvider::GetAttributeValue(TEXTATTRIBUTEI
textTransform = props->textAttributes.textTransform.value();
}
if (fontVariant == facebook::react::FontVariant::SmallCaps) {
return CapStyle_SmallCap;
pRetVal->lVal = CapStyle_SmallCap;
} else if (textTransform == facebook::react::TextTransform::Capitalize) {
return CapStyle_Titling;
pRetVal->lVal = CapStyle_Titling;
} else if (textTransform == facebook::react::TextTransform::Lowercase) {
return CapStyle_None;
pRetVal->lVal = CapStyle_None;
} else if (textTransform == facebook::react::TextTransform::Uppercase) {
return CapStyle_AllCap;
pRetVal->lVal = CapStyle_AllCap;
}
} else if (attributeId == UIA_FontNameAttributeId) {
pRetVal->vt = VT_BSTR;
Expand Down Expand Up @@ -282,6 +301,8 @@ HRESULT __stdcall CompositionTextRangeProvider::ScrollIntoView(BOOL alignToTop)
return S_OK;
}

// All the below methods should be implemented once the selection comes for paragraph and TextInput

HRESULT __stdcall CompositionTextRangeProvider::AddToSelection() {
// no-op
return S_OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@

namespace winrt::Microsoft::ReactNative::implementation {

ReactPropertyId<winrt::Microsoft::ReactNative::ReactNonAbiValue<
winrt::weak_ref<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>>>
ReactNativeIsland::LastFocusedReactNativeIslandProperty() noexcept {
static const ReactPropertyId<winrt::Microsoft::ReactNative::ReactNonAbiValue<
winrt::weak_ref<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>>>
prop{L"ReactNative.Composition", L"ReactNativeIsland"};
return prop;
}
constexpr float loadingActivitySize = 12.0f;
constexpr float loadingActivityHorizontalOffset = 16.0f;
constexpr float loadingBarHeight = 36.0f;
Expand Down Expand Up @@ -861,6 +869,20 @@ winrt::Microsoft::UI::Content::ContentIsland ReactNativeIsland::Island() {
}
}
});
focusController.GotFocus(
[weakThis = get_weak()](const auto &sender, const winrt::Microsoft::UI::Input::FocusChangedEventArgs &args) {
if (auto pThis = weakThis.get()) {
// Set the island to React context so it can be accessed by native modules
if (pThis->m_context && pThis->m_island) {
auto properties = pThis->m_context.Properties();
properties.Set(
ReactNativeIsland::LastFocusedReactNativeIslandProperty(),
winrt::Microsoft::ReactNative::ReactNonAbiValue<
winrt::weak_ref<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>>{
std::in_place, weakThis});
}
}
});

// ContentIsland does not support weak_ref, so we cannot use auto_revoke for these events
m_islandAutomationProviderRequestedToken = m_island.AutomationProviderRequested(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct ReactNativeIsland
~ReactNativeIsland() noexcept;

ReactNativeIsland(const winrt::Microsoft::UI::Composition::Compositor &compositor) noexcept;
static ReactPropertyId<winrt::Microsoft::ReactNative::ReactNonAbiValue<
winrt::weak_ref<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>>>
LastFocusedReactNativeIslandProperty() noexcept;
ReactNativeIsland(const winrt::Microsoft::ReactNative::Composition::PortalComponentView &portal) noexcept;

static winrt::Microsoft::ReactNative::ReactNativeIsland CreatePortal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <Fabric/AbiViewProps.h>
#include "CompositionDynamicAutomationProvider.h"
#include "RootComponentView.h"
#include "UiaHelpers.h"

namespace winrt::Microsoft::ReactNative::Composition::implementation {

Expand Down Expand Up @@ -80,6 +81,16 @@ void SwitchComponentView::updateProps(
m_visualUpdateRequired = true;
}

if (oldViewProps.value != newViewProps.value) {
if (UiaClientsAreListening()) {
winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty(
EnsureUiaProvider(),
UIA_ToggleToggleStatePropertyId,
oldViewProps.value ? ToggleState_On : ToggleState_Off,
newViewProps.value ? ToggleState_On : ToggleState_Off);
}
}

Super::updateProps(props, oldProps);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ void UpdateUiaProperty(winrt::IInspectable provider, PROPERTYID propId, bool old
UiaRaiseAutomationPropertyChangedEvent(spProviderSimple.get(), propId, CComVariant(oldValue), CComVariant(newValue));
}

void UpdateUiaProperty(winrt::IInspectable provider, PROPERTYID propId, int oldValue, int newValue) noexcept {
auto spProviderSimple = provider.try_as<IRawElementProviderSimple>();

if (spProviderSimple == nullptr || oldValue == newValue || !WasUiaPropertyAdvised(spProviderSimple, propId))
return;

UiaRaiseAutomationPropertyChangedEvent(spProviderSimple.get(), propId, CComVariant(oldValue), CComVariant(newValue));
}

void UpdateUiaProperty(
winrt::IInspectable provider,
PROPERTYID propId,
Expand Down
6 changes: 6 additions & 0 deletions vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ void UpdateUiaProperty(
bool oldValue,
bool newValue) noexcept;

void UpdateUiaProperty(
winrt::Windows::Foundation::IInspectable provider,
PROPERTYID propId,
int oldValue,
int newValue) noexcept;

void UpdateUiaProperty(
winrt::Windows::Foundation::IInspectable provider,
PROPERTYID propId,
Expand Down
29 changes: 29 additions & 0 deletions vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <UI.Xaml.Automation.Peers.h>
#include <UI.Xaml.Controls.h>
#include <XamlUtils.h>
#else
#include <Fabric/Composition/ReactNativeIsland.h>
#endif
#include <uiautomationcore.h>
#include <uiautomationcoreapi.h>
Expand Down Expand Up @@ -79,6 +81,33 @@ void AccessibilityInfo::announceForAccessibility(std::wstring announcement) noex
xaml::Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent,
hstr,
hstr);
#else
if (auto weakIslandWrapper = context.Properties().Get(
winrt::Microsoft::ReactNative::implementation::ReactNativeIsland::LastFocusedReactNativeIslandProperty())) {
if (auto weakIsland = weakIslandWrapper.Value()) {
if (auto reactNativeIsland = weakIsland.get()) {
if (auto uiaprovider = reactNativeIsland->GetUiaProvider()) {
if (auto rawProvider = uiaprovider.try_as<IRawElementProviderSimple>()) {
// Convert announcement to BSTR for UIA
winrt::hstring hstrAnnouncement{announcement};
auto bstrAnnouncement = SysAllocString(hstrAnnouncement.c_str());
if (bstrAnnouncement) {
// Raise the UIA notification event
HRESULT hr = UiaRaiseNotificationEvent(
rawProvider.get(),
NotificationKind_Other,
NotificationProcessing_ImportantMostRecent,
bstrAnnouncement,
bstrAnnouncement);
// Clean up BSTRs
SysFreeString(bstrAnnouncement);
}
}
}
}
}
}

#endif
});
}
Expand Down
Loading