Skip to content

Commit

Permalink
Parse accessibilityAction props into object
Browse files Browse the repository at this point in the history
Summary:
Android was using rawProps received from JS, so no updates needed.
Updated iOS callsite to use the name of the action.

Changelog:
[General][Fixed] - Parse accessibilityAction props into object instead of string

Reviewed By: mdvacca

Differential Revision: D28614407

fbshipit-source-id: 209134f8fac65ca8516039e10ea502e57d52a7a7
  • Loading branch information
Andrei Shikov authored and facebook-github-bot committed May 24, 2021
1 parent dd96555 commit faaeb77
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ - (BOOL)shouldGroupAccessibilityChildren
NSMutableArray<UIAccessibilityCustomAction *> *customActions = [NSMutableArray array];
for (auto const &accessibilityAction : accessibilityActions) {
[customActions
addObject:[[UIAccessibilityCustomAction alloc] initWithName:RCTNSStringFromString(accessibilityAction)
addObject:[[UIAccessibilityCustomAction alloc] initWithName:RCTNSStringFromString(accessibilityAction.name)
target:self
selector:@selector(didActivateAccessibilityCustomAction:)]];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#pragma once

#include <better/optional.h>
#include <cinttypes>
#include <string>

namespace facebook {
namespace react {
Expand Down Expand Up @@ -45,6 +47,11 @@ constexpr enum AccessibilityTraits operator&(
return (enum AccessibilityTraits)((uint32_t)lhs & (uint32_t)rhs);
}

struct AccessibilityAction {
std::string name{""};
better::optional<std::string> label{};
};

struct AccessibilityState {
bool disabled{false};
bool selected{false};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AccessibilityProps {
AccessibilityState accessibilityState;
std::string accessibilityLabel{""};
std::string accessibilityHint{""};
std::vector<std::string> accessibilityActions{};
std::vector<AccessibilityAction> accessibilityActions{};
bool accessibilityViewIsModal{false};
bool accessibilityElementsHidden{false};
bool accessibilityIgnoresInvertColors{false};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,22 @@ inline void fromRawValue(
}
}

inline void fromRawValue(const RawValue &value, AccessibilityAction &result) {
auto map = (better::map<std::string, RawValue>)value;

auto name = map.find("name");
react_native_assert(name != map.end() && name->second.hasType<std::string>());
if (name != map.end()) {
fromRawValue(name->second, result.name);
}

auto label = map.find("label");
if (label != map.end()) {
if (label->second.hasType<std::string>()) {
result.label = (std::string)label->second;
}
}
}

} // namespace react
} // namespace facebook

0 comments on commit faaeb77

Please sign in to comment.