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

Support accessibilityState 'checked' #13962

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
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": "Implement accessibilityState checked",
"packageName": "react-native-windows",
"email": "34109996+chiaramooney@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ class AccessibilityExample extends React.Component<
{name: 'expand', label: 'expand'},
{name: 'collapse', label: 'collapse'},
]}
accessibilityState={{expanded: this.state.expanded, busy: true}}
accessibilityState={{expanded: this.state.expanded, busy: true, checked: true}}
accessibilityPosInSet={1}
accessibilitySetSize={1}
accessibilityLiveRegion="polite"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ exports[`View Tests Views can have customized accessibility 1`] = `
"Name": "A View with accessibility values",
"PositionInSet": 1,
"SizeofSet": 1,
"TogglePattern.ToggleState": "On",
"ValuePattern.Value": "0",
"__Children": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77781,6 +77781,7 @@ exports[`snapshotAllPages View 22`] = `
accessibilityState={
{
"busy": true,
"checked": true,
"expanded": true,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ exports[`ViewTests Views can have accessibility customization 1`] = `
{
"AccessibilityRole": "Button",
"AccessibilityStateBusy": true,
"AccessibilityStateChecked": "Checked",
"AccessibilityStateExpanded": true,
"AutomationId": "accessibility",
"AutomationPositionInSet": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,14 @@
}
},
"common": {
"type": "Project",
"dependencies": {
"boost": "[1.83.0, )"
}
"type": "Project"
},
"fmt": {
"type": "Project"
},
"folly": {
"type": "Project",
"dependencies": {
"boost": "[1.83.0, )",
"fmt": "[1.0.0, )"
}
},
Expand All @@ -86,7 +82,6 @@
"playground-composition": {
"type": "Project",
"dependencies": {
"Microsoft.JavaScript.Hermes": "[0.1.23, )",
"Microsoft.ReactNative": "[1.0.0, )",
"Microsoft.VCRTForwarders.140": "[1.0.2-rc, )",
"Microsoft.WindowsAppSDK": "[1.6.240923002, )",
Expand All @@ -97,8 +92,7 @@
"reactcommon": {
"type": "Project",
"dependencies": {
"Folly": "[1.0.0, )",
"boost": "[1.83.0, )"
"Folly": "[1.0.0, )"
}
},
"samplecustomcomponent": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ bool expandableControl(const facebook::react::SharedViewProps props) {
return false;
}

bool togglableControl(const facebook::react::SharedViewProps props) {
if (props->accessibilityState.has_value() &&
props->accessibilityState->checked != facebook::react::AccessibilityState::None) {
return true;
}
auto accessibilityActions = props->accessibilityActions;
for (size_t i = 0; i < accessibilityActions.size(); i++) {
if (accessibilityActions[i].name == "toggle") {
return true;
}
}
return false;
}

HRESULT __stdcall CompositionDynamicAutomationProvider::GetPatternProvider(PATTERNID patternId, IUnknown **pRetVal) {
if (pRetVal == nullptr)
return E_POINTER;
Expand Down Expand Up @@ -182,7 +196,7 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::GetPatternProvider(PATTE
}

if (patternId == UIA_TogglePatternId &&
strongView.try_as<winrt::Microsoft::ReactNative::Composition::implementation::SwitchComponentView>()) {
(strongView.try_as<winrt::Microsoft::ReactNative::Composition::implementation::SwitchComponentView>() || togglableControl(props))) {
*pRetVal = static_cast<IToggleProvider *>(this);
AddRef();
}
Expand Down Expand Up @@ -498,8 +512,13 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::get_ToggleState(ToggleSt
if (!strongView)
return UIA_E_ELEMENTNOTAVAILABLE;

*pRetVal =
winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(strongView)->getToggleState();
auto props = std::static_pointer_cast<const facebook::react::ViewProps>(
winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(strongView)->props());

*pRetVal = (props->accessibilityState.has_value() &&
props->accessibilityState->checked != facebook::react::AccessibilityState::None)
? GetToggleState(props->accessibilityState)
: winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(strongView)->getToggleState();
return S_OK;
}

Expand Down
11 changes: 11 additions & 0 deletions vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,15 @@ ExpandCollapseState GetExpandCollapseState(const bool &expanded) noexcept {
}
}

ToggleState GetToggleState(const std::optional<facebook::react::AccessibilityState> &state) noexcept {
if (state.has_value()) {
if (state->checked == facebook::react::AccessibilityState::Checked) {
return ToggleState::ToggleState_On;
} else if (state->checked == facebook::react::AccessibilityState::Mixed) {
return ToggleState::ToggleState_Indeterminate;
}
}
return ToggleState::ToggleState_Off;
}

} // namespace winrt::Microsoft::ReactNative::implementation
2 changes: 2 additions & 0 deletions vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ std::string extractAccessibilityValue(const facebook::react::AccessibilityValue
void DispatchAccessibilityAction(::Microsoft::ReactNative::ReactTaggedView &view, const std::string &action) noexcept;

ExpandCollapseState GetExpandCollapseState(const bool &expanded) noexcept;

ToggleState GetToggleState(const std::optional<facebook::react::AccessibilityState> &state) noexcept;
} // namespace winrt::Microsoft::ReactNative::implementation
Loading