Skip to content

Commit

Permalink
Fix Control Bug Accessible/Focusable Adjustment Code (#11032)
Browse files Browse the repository at this point in the history
* Refactor Code

* Change files

* Update Locations
  • Loading branch information
chiaramooney committed Jan 30, 2023
1 parent 51c9f0f commit 031d0d7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Refactor Code",
"packageName": "react-native-windows",
"email": "34109996+chiaramooney@users.noreply.github.com",
"dependentChangeType": "patch"
}
32 changes: 8 additions & 24 deletions vnext/Microsoft.ReactNative/Views/ControlViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,14 @@ bool ControlViewManager::UpdateProperty(
}
} else if (propertyName == "focusable") {
if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::Boolean) {
IsFocusable(propertyValue.AsBoolean());
control.IsTabStop(propertyValue.AsBoolean());
nodeToUpdate->IsFocusable(propertyValue.AsBoolean());
} else if (propertyValue.IsNull()) {
control.ClearValue(TAB_STOP_PROPERTY());
IsFocusable(false);
nodeToUpdate->IsFocusable(false);
}
} else {
if (propertyName == "accessible") {
if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::Boolean) {
IsAccessible(propertyValue.AsBoolean());
nodeToUpdate->IsAccessible(propertyValue.AsBoolean());
}
}
ret = Super::UpdateProperty(nodeToUpdate, propertyName, propertyValue);
Expand Down Expand Up @@ -126,12 +124,11 @@ void ControlViewManager::OnPropertiesUpdated(ShadowNodeBase *node) {

// If developer specifies either the accessible and focusable prop to be false
// remove accessibility and keyboard focus for component.
if (IsAccessible() != IsFocusable()) {
control.IsTabStop(false);
xaml::Automation::AutomationProperties::SetAccessibilityView(
control, xaml::Automation::Peers::AccessibilityView::Raw);
control.IsEnabled(false);
}
const auto isTabStop = (node->IsAccessible() && node->IsFocusable());
const auto accessibilityView =
isTabStop ? xaml::Automation::Peers::AccessibilityView::Content : xaml::Automation::Peers::AccessibilityView::Raw;
control.IsTabStop(isTabStop);
xaml::Automation::AutomationProperties::SetAccessibilityView(control, accessibilityView);
}

void ControlViewManager::OnViewCreated(XamlView view) {
Expand All @@ -142,17 +139,4 @@ void ControlViewManager::OnViewCreated(XamlView view) {
}
}

void ControlViewManager::IsAccessible(bool accessible) {
m_isAccessible = accessible;
}
bool ControlViewManager::IsAccessible() {
return m_isAccessible;
}
void ControlViewManager::IsFocusable(bool focusable) {
m_isFocusable = focusable;
}
bool ControlViewManager::IsFocusable() {
return m_isFocusable;
}

} // namespace Microsoft::ReactNative
9 changes: 0 additions & 9 deletions vnext/Microsoft.ReactNative/Views/ControlViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ class REACTWINDOWS_EXPORT ControlViewManager : public FrameworkElementViewManage
void OnViewCreated(XamlView view) override;

void OnPropertiesUpdated(ShadowNodeBase *node) override;

private:
void IsAccessible(bool accessible);
bool IsAccessible();
void IsFocusable(bool focusable);
bool IsFocusable();

bool m_isAccessible = true;
bool m_isFocusable = true;
};

} // namespace Microsoft::ReactNative
13 changes: 13 additions & 0 deletions vnext/Microsoft.ReactNative/Views/ShadowNodeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,17 @@ void ShadowNodeBase::RedBox(const std::string &message) const noexcept {
GetViewManager()->GetReactContext().CallJSFunction("RCTLog", "logToConsole", folly::dynamic::array("error", message));
}

void ShadowNodeBase::IsAccessible(bool accessible) {
m_isAccessible = accessible;
}
bool ShadowNodeBase::IsAccessible() {
return m_isAccessible;
}
void ShadowNodeBase::IsFocusable(bool focusable) {
m_isFocusable = focusable;
}
bool ShadowNodeBase::IsFocusable() {
return m_isFocusable;
}

} // namespace Microsoft::ReactNative
7 changes: 7 additions & 0 deletions vnext/Microsoft.ReactNative/Views/ShadowNodeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,16 @@ struct REACTWINDOWS_EXPORT ShadowNodeBase : public ShadowNode {
return m_onMouseEnterRegistered || m_onMouseLeaveRegistered;
}

void IsAccessible(bool accessible);
bool IsAccessible();
void IsFocusable(bool focusable);
bool IsFocusable();

protected:
XamlView m_view;
bool m_updating = false;
bool m_isFocusable = true;
bool m_isAccessible = true;
comp::CompositionPropertySet m_transformPS{nullptr};

public:
Expand Down
19 changes: 2 additions & 17 deletions vnext/Microsoft.ReactNative/Views/ViewViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class ViewShadowNode : public ShadowNodeBase {
Super::createView(props);

auto panel = GetPanel();
IsAccessible(false);
IsFocusable(false);

DynamicAutomationProperties::SetAccessibilityInvokeEventHandler(panel, [=]() {
if (OnClick())
Expand Down Expand Up @@ -121,21 +123,6 @@ class ViewShadowNode : public ShadowNodeBase {
m_onClick = isSet;
}

bool IsFocusable() const {
return m_isFocusable;
}
void IsFocusable(bool isFocusable) {
m_isFocusable = isFocusable;
}

bool IsAccessible() const {
return m_isAccessible;
}

void IsAccessible(bool isAccessible) {
m_isAccessible = isAccessible;
}

bool IsHitTestBrushRequired() const {
return IsRegisteredForMouseEvents();
}
Expand Down Expand Up @@ -259,8 +246,6 @@ class ViewShadowNode : public ShadowNodeBase {

bool m_enableFocusRing = true;
bool m_onClick = false;
bool m_isFocusable = false;
bool m_isAccessible = false;
int32_t m_tabIndex = std::numeric_limits<std::int32_t>::max();

xaml::Controls::ContentControl::GotFocus_revoker m_contentControlGotFocusRevoker{};
Expand Down

0 comments on commit 031d0d7

Please sign in to comment.