Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented accessibilityLiveRegion #2591

Merged
merged 6 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
42 changes: 42 additions & 0 deletions vnext/ReactUWP/Views/FrameworkElementViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
#include <winrt/Windows.UI.Xaml.h>
#include <winrt/Windows.UI.Xaml.Controls.h>
#include <winrt/Windows.UI.Xaml.Automation.h>
#include <winrt/Windows.UI.Xaml.Automation.Peers.h>
#include <WindowsNumerics.h>

namespace winrt {
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Automation;
using namespace Windows::UI::Xaml::Automation::Peers;
}

namespace react { namespace uwp {
Expand Down Expand Up @@ -56,6 +58,7 @@ void FrameworkElementViewManager::TransferProperties(XamlView oldView, XamlView

// Accessibility Properties
TransferProperty(oldView, newView, winrt::AutomationProperties::NameProperty());
TransferProperty(oldView, newView, winrt::AutomationProperties::LiveSettingProperty());
auto accessibilityView = winrt::AutomationProperties::GetAccessibilityView(oldView);
winrt::AutomationProperties::SetAccessibilityView(newView, accessibilityView);

Expand Down Expand Up @@ -261,6 +264,7 @@ void FrameworkElementViewManager::UpdateProperties(ShadowNodeBase* nodeToUpdate,
{
element.ClearValue(winrt::AutomationProperties::NameProperty());
}
AnnounceIfNeeded(element);
}
else if (propertyName == "accessible")
{
Expand All @@ -270,6 +274,31 @@ void FrameworkElementViewManager::UpdateProperties(ShadowNodeBase* nodeToUpdate,
winrt::AutomationProperties::SetAccessibilityView(element, winrt::Peers::AccessibilityView::Raw);
}
}
else if (propertyName == "accessibilityLiveRegion")
{
if (propertyValue.isString())
{
auto value = propertyValue.asString();

auto liveSetting = winrt::AutomationLiveSetting::Off;

if (value == "polite")
{
liveSetting = winrt::AutomationLiveSetting::Polite;
}
else if (value == "assertive")
{
liveSetting = winrt::AutomationLiveSetting::Assertive;
}

element.SetValue(winrt::AutomationProperties::LiveSettingProperty(), winrt::box_value(liveSetting));
}
else if (propertyValue.isNull())
{
element.ClearValue(winrt::AutomationProperties::LiveSettingProperty());
}
AnnounceIfNeeded(element);
}
else if (propertyName == "testID")
{
if (propertyValue.isString())
Expand Down Expand Up @@ -317,4 +346,17 @@ void FrameworkElementViewManager::UpdateProperties(ShadowNodeBase* nodeToUpdate,
Super::UpdateProperties(nodeToUpdate, reactDiffMap);
}

void FrameworkElementViewManager::AnnounceIfNeeded(winrt::FrameworkElement element)
{
if (winrt::AutomationProperties::GetLiveSetting(element) != winrt::AutomationLiveSetting::Off
&& !winrt::AutomationProperties::GetName(element).empty())
{
auto peer = winrt::FrameworkElementAutomationPeer::FromElement(element);
if (nullptr != peer)
{
peer.RaiseAutomationEvent(winrt::AutomationEvents::LiveRegionChanged);
}
}
}

} }
2 changes: 2 additions & 0 deletions vnext/include/ReactUWP/Views/FrameworkElementViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class REACTWINDOWS_EXPORT FrameworkElementViewManager : public ViewManagerBase
virtual void TransferProperties(XamlView oldView, XamlView newView) override;

void TransferProperty(XamlView oldView, XamlView newView, winrt::Windows::UI::Xaml::DependencyProperty dp);

void AnnounceIfNeeded(winrt::FrameworkElement element);
};

} }
2 changes: 1 addition & 1 deletion vnext/src/RNTester/AccessibilityExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TouchableExamples extends React.Component<{}, any> {
>
<Text>Blue</Text>
</TouchableHighlight>
<Text>Pressed {this.state.pressedCount} times</Text>
<Text accessibilityLiveRegion="polite">Pressed {this.state.pressedCount} times</Text>
</View>
);
}
Expand Down