Skip to content

Commit

Permalink
Back out "Change accessibilityRole to an enum"
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[Internal] - Revert "Change the accessibilityRole from a string to an enum."
Original commit changeset: b46ce0bd156c

Reviewed By: PeteTheHeat

Differential Revision: D22540391

fbshipit-source-id: df4a62c7bb4525782121dea2c70a9101cf0d8e9f
  • Loading branch information
ZHUANGPP authored and facebook-github-bot committed Jul 15, 2020
1 parent 61cd596 commit 7485e93
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 57 deletions.
2 changes: 1 addition & 1 deletion ReactCommon/fabric/attributedstring/TextAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void TextAttributes::apply(TextAttributes textAttributes) {
layoutDirection = textAttributes.layoutDirection.hasValue()
? textAttributes.layoutDirection
: layoutDirection;
accessibilityRole = textAttributes.accessibilityRole.hasValue()
accessibilityRole = !textAttributes.accessibilityRole.empty()
? textAttributes.accessibilityRole
: accessibilityRole;
}
Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/fabric/attributedstring/TextAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class TextAttributes : public DebugStringConvertible {
// Currently, it is intentionally *not* being set as part of BaseTextProps
// construction.
folly::Optional<LayoutDirection> layoutDirection{};
folly::Optional<AccessibilityRole> accessibilityRole{};
std::string accessibilityRole{""};

#pragma mark - Operations

Expand Down
28 changes: 0 additions & 28 deletions ReactCommon/fabric/attributedstring/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,34 +412,6 @@ inline std::string toString(
}
}

inline std::string toString(const AccessibilityRole &accessibilityRole) {
switch (accessibilityRole) {
case AccessibilityRole::Link:
return "link";
case AccessibilityRole::Button:
return "button";
case AccessibilityRole::Image:
return "image";
}
}

inline void fromRawValue(const RawValue &value, AccessibilityRole &result) {
auto string = (std::string)value;
if (string == "link") {
result = AccessibilityRole::Link;
return;
}
if (string == "button") {
result = AccessibilityRole::Button;
return;
}
if (string == "image") {
result = AccessibilityRole::Image;
return;
}
abort();
}

inline ParagraphAttributes convertRawProp(
RawProps const &rawProps,
ParagraphAttributes const &sourceParagraphAttributes,
Expand Down
14 changes: 0 additions & 14 deletions ReactCommon/fabric/attributedstring/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ enum class TextDecorationLinePattern {
DashDotDot,
};

enum class AccessibilityRole {
Link,
Button,
Image,
};

} // namespace react
} // namespace facebook

Expand Down Expand Up @@ -166,12 +160,4 @@ struct hash<facebook::react::TextBreakStrategy> {
return hash<int>()(static_cast<int>(v));
}
};

template <>
struct hash<facebook::react::AccessibilityRole> {
size_t operator()(const facebook::react::AccessibilityRole &v) const {
return hash<int>()(static_cast<int>(v));
}
};

} // namespace std
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,9 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex
attributes[RCTAttributedStringIsHighlightedAttributeName] = @YES;
}

if (textAttributes.accessibilityRole.hasValue()) {
auto accessibilityRole = textAttributes.accessibilityRole.value();
switch (accessibilityRole) {
case AccessibilityRole::Link:
attributes[RCTTextAttributesAccessibilityRoleAttributeName] = @("link");
break;
case AccessibilityRole::Button:
attributes[RCTTextAttributesAccessibilityRoleAttributeName] = @("button");
break;
case AccessibilityRole::Image:
attributes[RCTTextAttributesAccessibilityRoleAttributeName] = @("image");
break;
};
if (!textAttributes.accessibilityRole.empty()) {
attributes[RCTTextAttributesAccessibilityRoleAttributeName] =
[NSString stringWithCString:textAttributes.accessibilityRole.c_str() encoding:NSUTF8StringEncoding];
}

return [attributes copy];
Expand Down

0 comments on commit 7485e93

Please sign in to comment.