Skip to content

Commit 6fa9dba

Browse files
ZHUANGPPfacebook-github-bot
authored andcommitted
Update accessibilityState prop
Summary: Changelog: [Internal] - Add default value for accessibilityState "checked" and handle unhandled states. It is also work for the case that accessibilityRole = "switch" and accessibilityState is set. Reviewed By: sammy-SC Differential Revision: D22914427 fbshipit-source-id: 4767a21f3bd109019b57bc09918758a38fbdea93
1 parent 5c9c522 commit 6fa9dba

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

+24
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,30 @@ - (NSString *)accessibilityLabel
516516
return RCTRecursiveAccessibilityLabel(self);
517517
}
518518

519+
- (NSString *)accessibilityValue
520+
{
521+
auto const &props = *std::static_pointer_cast<ViewProps const>(_props);
522+
523+
// Handle states which haven't already been handled.
524+
if (props.accessibilityState.checked == AccessibilityState::Checked) {
525+
return @"checked";
526+
}
527+
if (props.accessibilityState.checked == AccessibilityState::Unchecked) {
528+
return @"unchecked";
529+
}
530+
if (props.accessibilityState.checked == AccessibilityState::Mixed) {
531+
return @"mixed";
532+
}
533+
if (props.accessibilityState.expanded) {
534+
return @"expanded";
535+
}
536+
if (props.accessibilityState.busy) {
537+
return @"busy";
538+
}
539+
540+
return nil;
541+
}
542+
519543
#pragma mark - Accessibility Events
520544

521545
- (NSArray<UIAccessibilityCustomAction *> *)accessibilityCustomActions

ReactCommon/react/renderer/components/view/AccessibilityPrimitives.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ constexpr enum AccessibilityTraits operator&(
4747
struct AccessibilityState {
4848
bool disabled{false};
4949
bool selected{false};
50-
enum { Unchecked, Checked, Mixed } checked{Unchecked};
50+
enum { Unchecked, Checked, Mixed, None } checked{None};
5151
bool busy{false};
5252
bool expanded{false};
5353
};

ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h

+4
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,17 @@ inline void fromRawValue(const RawValue &value, AccessibilityState &result) {
125125
if (checked->second.hasType<std::string>()) {
126126
if ((std::string)checked->second == "mixed") {
127127
result.checked = AccessibilityState::Mixed;
128+
} else {
129+
result.checked = AccessibilityState::None;
128130
}
129131
} else if (checked->second.hasType<bool>()) {
130132
if ((bool)checked->second == true) {
131133
result.checked = AccessibilityState::Checked;
132134
} else {
133135
result.checked = AccessibilityState::Unchecked;
134136
}
137+
} else {
138+
result.checked = AccessibilityState::None;
135139
}
136140
}
137141
auto busy = map.find("busy");

0 commit comments

Comments
 (0)