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

Add changes to disabled property for components (e.g TouchableHighlight) #11278

Merged
merged 13 commits into from
Mar 2, 2023
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@office-iss/react-native-win32",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@react-native-windows/automation",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@react-native-windows/automation-channel",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@react-native-windows/automation-commands",
"email": "email not defined",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@react-native-windows/cli",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@react-native-windows/codegen",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@react-native-windows/find-repo-root",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@react-native-windows/fs",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@react-native-windows/package-utils",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@react-native-windows/telemetry",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@rnw-scripts/create-github-releases",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@rnw-scripts/doxysaurus",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@rnw-scripts/integrate-rn",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@rnw-scripts/promote-release",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "@rnw-scripts/take-screenshot",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "react-native-platform-override",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Resolved nits",
"packageName": "react-native-windows",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Merge branch 'YajurG-8875' of https://github.com/YajurG/react-native-windows into YajurG-8875",
"packageName": "react-native-windows-init",
"email": "email not defined",
"dependentChangeType": "patch"
}
8 changes: 6 additions & 2 deletions vnext/Microsoft.ReactNative/Views/ControlViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void ControlViewManager::GetNativeProps(const winrt::Microsoft::ReactNative::IJS
Super::GetNativeProps(writer);
winrt::Microsoft::ReactNative::WriteProperty(writer, L"tabIndex", L"number");
winrt::Microsoft::ReactNative::WriteProperty(writer, L"focusable", L"boolean");
winrt::Microsoft::ReactNative::WriteProperty(writer, L"disabled", L"boolean");
}
void ControlViewManager::TransferProperties(const XamlView &oldView, const XamlView &newView) {
TransferProperty(oldView, newView, xaml::Controls::Control::FontSizeProperty());
Expand Down Expand Up @@ -86,6 +87,10 @@ bool ControlViewManager::UpdateProperty(
} else if (propertyValue.IsNull()) {
nodeToUpdate->IsFocusable(false);
}
} else if (propertyName == "disabled") {
if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::Boolean) {
nodeToUpdate->IsDisable(propertyValue.AsBoolean());
}
} else {
if (propertyName == "accessible") {
if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::Boolean) {
Expand All @@ -95,7 +100,6 @@ bool ControlViewManager::UpdateProperty(
ret = Super::UpdateProperty(nodeToUpdate, propertyName, propertyValue);
}
}

if (finalizeBorderRadius && control.try_as<xaml::Controls::IControl7>()) {
// Control.CornerRadius is only supported on >= RS5, setting borderRadius on Controls have no effect < RS5
UpdateCornerRadiusOnElement(nodeToUpdate, control);
Expand Down Expand Up @@ -124,7 +128,7 @@ void ControlViewManager::OnPropertiesUpdated(ShadowNodeBase *node) {

// If developer specifies either the accessible and focusable prop to be false
// remove accessibility and keyboard focus for component.
const auto isTabStop = (node->IsAccessible() && node->IsFocusable());
const auto isTabStop = !node->IsDisable() && (node->IsAccessible() && node->IsFocusable());
const auto accessibilityView =
isTabStop ? xaml::Automation::Peers::AccessibilityView::Content : xaml::Automation::Peers::AccessibilityView::Raw;
control.IsTabStop(isTabStop);
Expand Down
7 changes: 7 additions & 0 deletions vnext/Microsoft.ReactNative/Views/ShadowNodeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,11 @@ bool ShadowNodeBase::IsFocusable() {
return m_isFocusable;
}

void ShadowNodeBase::IsDisable(bool disable) {
m_isDisabled = disable;
}
bool ShadowNodeBase::IsDisable() {
return m_isDisabled;
}

} // namespace Microsoft::ReactNative
3 changes: 3 additions & 0 deletions vnext/Microsoft.ReactNative/Views/ShadowNodeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@ struct REACTWINDOWS_EXPORT ShadowNodeBase : public ShadowNode {
bool IsAccessible();
void IsFocusable(bool focusable);
bool IsFocusable();
void IsDisable(bool disable);
bool IsDisable();

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

public:
Expand Down
14 changes: 11 additions & 3 deletions vnext/Microsoft.ReactNative/Views/ViewViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ void ViewViewManager::GetNativeProps(const winrt::Microsoft::ReactNative::IJSVal
winrt::Microsoft::ReactNative::WriteProperty(writer, L"focusable", L"boolean");
winrt::Microsoft::ReactNative::WriteProperty(writer, L"enableFocusRing", L"boolean");
winrt::Microsoft::ReactNative::WriteProperty(writer, L"tabIndex", L"number");
winrt::Microsoft::ReactNative::WriteProperty(writer, L"disabled", L"boolean");
winrt::Microsoft::ReactNative::WriteProperty(writer, L"collapsable", L"boolean");
}

Expand Down Expand Up @@ -437,6 +438,9 @@ bool ViewViewManager::UpdateProperty(
if (propertyName == "accessible") {
pViewShadowNode->IsAccessible(propertyValue.AsBoolean());
}
if (propertyName == "disabled") {
pViewShadowNode->IsDisable(propertyValue.AsBoolean());
}
ret = Super::UpdateProperty(nodeToUpdate, propertyName, propertyValue);
}
}
Expand All @@ -462,8 +466,10 @@ void ViewViewManager::OnPropertiesUpdated(ShadowNodeBase *node) {

// If component is focusable, it should be a ViewControl.
// If component is a View with accessible set to true, the component should be focusable, thus we need a ViewControl.
bool shouldBeControl =
(viewShadowNode->IsFocusable() || (viewShadowNode->IsAccessible() && !viewShadowNode->OnClick()));
bool shouldBeControl = viewShadowNode->IsDisable()
? false
: ((viewShadowNode->IsFocusable() || (viewShadowNode->IsAccessible() && !viewShadowNode->OnClick())));

if (auto view = viewShadowNode->GetView().try_as<xaml::UIElement>()) {
// If we have DynamicAutomationProperties, we need a ViewControl with a
// DynamicAutomationPeer
Expand Down Expand Up @@ -597,8 +603,10 @@ void ViewViewManager::SyncFocusableAndAccessible(ViewShadowNode *pViewShadowNode
const auto isFocusable = pViewShadowNode->IsFocusable();
const auto isAccessible = pViewShadowNode->IsAccessible();
const auto isPressable = pViewShadowNode->OnClick();
const auto isDisabled = pViewShadowNode->IsDisable();
const auto isTabStop =
(isPressable && isFocusable && isAccessible) || (!isPressable && (isFocusable || isAccessible));
(!isDisabled &&
Copy link
Contributor

Choose a reason for hiding this comment

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

If you haven't already, I'd also double check that this issue (#10687) isn't being reintroduced just with the disabled prop causing it now

((isPressable && isFocusable && isAccessible) || (!isPressable && (isFocusable || isAccessible))));
const auto accessibilityView = isTabStop ? xaml::Automation::Peers::AccessibilityView::Content
: xaml::Automation::Peers::AccessibilityView::Raw;
pViewShadowNode->GetControl().IsTabStop(isTabStop);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class TouchableHighlight extends React.Component<Props, State> {
accessibilityValue={accessibilityValue}
accessibilityActions={this.props.accessibilityActions}
onAccessibilityAction={this.props.onAccessibilityAction}
disabled={this.props.disabled}
importantForAccessibility={
this.props['aria-hidden'] === true
? 'no-hide-descendants'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class TouchableOpacity extends React.Component<Props, State> {
accessibilityElementsHidden={
this.props['aria-hidden'] ?? this.props.accessibilityElementsHidden
}
disabled={this.props.disabled}
style={[this.props.style, {opacity: this.state.anim}]}
nativeID={this.props.nativeID}
testID={this.props.testID}
Expand Down
2 changes: 2 additions & 0 deletions vnext/src/Libraries/Components/View/View.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const View: React.AbstractComponent<
'aria-valuenow': ariaValueNow,
'aria-valuetext': ariaValueText,
focusable,
disabled,
id,
importantForAccessibility,
nativeID,
Expand Down Expand Up @@ -205,6 +206,7 @@ const View: React.AbstractComponent<
}
accessibilityLabel={ariaLabel ?? accessibilityLabel}
focusable={tabIndex !== undefined ? !tabIndex : focusable}
disabled={disabled}
accessibilityState={_accessibilityState}
accessibilityRole={
role ? getAccessibilityRoleFromRole(role) : accessibilityRole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ type WindowsViewProps = $ReadOnly<{|

tabIndex?: ?number,

disabled?: ?boolean,

accessibilityPosInSet?: ?number,
accessibilitySetSize?: ?number,

Expand Down