Skip to content

Commit

Permalink
Update accessibilityState prop
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ZHUANGPP authored and facebook-github-bot committed Aug 6, 2020
1 parent 5c9c522 commit 6fa9dba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
24 changes: 24 additions & 0 deletions React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,30 @@ - (NSString *)accessibilityLabel
return RCTRecursiveAccessibilityLabel(self);
}

- (NSString *)accessibilityValue
{
auto const &props = *std::static_pointer_cast<ViewProps const>(_props);

// Handle states which haven't already been handled.
if (props.accessibilityState.checked == AccessibilityState::Checked) {
return @"checked";
}
if (props.accessibilityState.checked == AccessibilityState::Unchecked) {
return @"unchecked";
}
if (props.accessibilityState.checked == AccessibilityState::Mixed) {
return @"mixed";
}
if (props.accessibilityState.expanded) {
return @"expanded";
}
if (props.accessibilityState.busy) {
return @"busy";
}

return nil;
}

#pragma mark - Accessibility Events

- (NSArray<UIAccessibilityCustomAction *> *)accessibilityCustomActions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ constexpr enum AccessibilityTraits operator&(
struct AccessibilityState {
bool disabled{false};
bool selected{false};
enum { Unchecked, Checked, Mixed } checked{Unchecked};
enum { Unchecked, Checked, Mixed, None } checked{None};
bool busy{false};
bool expanded{false};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,17 @@ inline void fromRawValue(const RawValue &value, AccessibilityState &result) {
if (checked->second.hasType<std::string>()) {
if ((std::string)checked->second == "mixed") {
result.checked = AccessibilityState::Mixed;
} else {
result.checked = AccessibilityState::None;
}
} else if (checked->second.hasType<bool>()) {
if ((bool)checked->second == true) {
result.checked = AccessibilityState::Checked;
} else {
result.checked = AccessibilityState::Unchecked;
}
} else {
result.checked = AccessibilityState::None;
}
}
auto busy = map.find("busy");
Expand Down

0 comments on commit 6fa9dba

Please sign in to comment.