mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Implement textTransform prop
Summary: Added to C++ props, but realized this is already implemented using C++ state in Android, so added to C++ state to keep this diff simpler. Keeping the C++ props change for future use. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D29805267 fbshipit-source-id: c1fe2dc34af8bc69352ee48a5d60ba998194e3f7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
998cadd523
commit
e1d17c785b
@@ -50,6 +50,9 @@ void TextAttributes::apply(TextAttributes textAttributes) {
|
||||
letterSpacing = !std::isnan(textAttributes.letterSpacing)
|
||||
? textAttributes.letterSpacing
|
||||
: letterSpacing;
|
||||
textTransform = textAttributes.textTransform.hasValue()
|
||||
? textAttributes.textTransform
|
||||
: textTransform;
|
||||
|
||||
// Paragraph Styles
|
||||
lineHeight = !std::isnan(textAttributes.lineHeight)
|
||||
@@ -120,7 +123,8 @@ bool TextAttributes::operator==(const TextAttributes &rhs) const {
|
||||
textShadowColor,
|
||||
isHighlighted,
|
||||
layoutDirection,
|
||||
accessibilityRole) ==
|
||||
accessibilityRole,
|
||||
textTransform) ==
|
||||
std::tie(
|
||||
rhs.foregroundColor,
|
||||
rhs.backgroundColor,
|
||||
@@ -139,7 +143,8 @@ bool TextAttributes::operator==(const TextAttributes &rhs) const {
|
||||
rhs.textShadowColor,
|
||||
rhs.isHighlighted,
|
||||
rhs.layoutDirection,
|
||||
rhs.accessibilityRole) &&
|
||||
rhs.accessibilityRole,
|
||||
rhs.textTransform) &&
|
||||
floatEquality(opacity, rhs.opacity) &&
|
||||
floatEquality(fontSize, rhs.fontSize) &&
|
||||
floatEquality(fontSizeMultiplier, rhs.fontSizeMultiplier) &&
|
||||
|
||||
@@ -51,6 +51,7 @@ class TextAttributes : public DebugStringConvertible {
|
||||
better::optional<FontVariant> fontVariant{};
|
||||
better::optional<bool> allowFontScaling{};
|
||||
Float letterSpacing{std::numeric_limits<Float>::quiet_NaN()};
|
||||
better::optional<TextTransform> textTransform{};
|
||||
|
||||
// Paragraph Styles
|
||||
Float lineHeight{std::numeric_limits<Float>::quiet_NaN()};
|
||||
@@ -117,6 +118,7 @@ struct hash<facebook::react::TextAttributes> {
|
||||
textAttributes.fontVariant,
|
||||
textAttributes.allowFontScaling,
|
||||
textAttributes.letterSpacing,
|
||||
textAttributes.textTransform,
|
||||
textAttributes.lineHeight,
|
||||
textAttributes.alignment,
|
||||
textAttributes.baseWritingDirection,
|
||||
|
||||
@@ -260,6 +260,55 @@ inline std::string toString(const FontVariant &fontVariant) {
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void fromRawValue(const RawValue &value, TextTransform &result) {
|
||||
react_native_assert(value.hasType<std::string>());
|
||||
if (value.hasType<std::string>()) {
|
||||
auto string = (std::string)value;
|
||||
if (string == "none") {
|
||||
result = TextTransform::None;
|
||||
} else if (string == "uppercase") {
|
||||
result = TextTransform::Uppercase;
|
||||
} else if (string == "lowercase") {
|
||||
result = TextTransform::Lowercase;
|
||||
} else if (string == "capitalize") {
|
||||
result = TextTransform::Capitalize;
|
||||
} else if (string == "unset") {
|
||||
result = TextTransform::Unset;
|
||||
} else {
|
||||
LOG(ERROR) << "Unsupported TextTransform value: " << string;
|
||||
react_native_assert(false);
|
||||
// sane default for prod
|
||||
result = TextTransform::None;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(ERROR) << "Unsupported TextTransform type";
|
||||
react_native_assert(false);
|
||||
// sane default for prod
|
||||
result = TextTransform::None;
|
||||
}
|
||||
|
||||
inline std::string toString(const TextTransform &textTransform) {
|
||||
switch (textTransform) {
|
||||
case TextTransform::None:
|
||||
return "none";
|
||||
case TextTransform::Uppercase:
|
||||
return "uppercase";
|
||||
case TextTransform::Lowercase:
|
||||
return "lowercase";
|
||||
case TextTransform::Capitalize:
|
||||
return "capitalize";
|
||||
case TextTransform::Unset:
|
||||
return "unset";
|
||||
}
|
||||
|
||||
LOG(ERROR) << "Unsupported TextTransform value";
|
||||
react_native_assert(false);
|
||||
// sane default for prod
|
||||
return "none";
|
||||
}
|
||||
|
||||
inline void fromRawValue(const RawValue &value, TextAlignment &result) {
|
||||
react_native_assert(value.hasType<std::string>());
|
||||
if (value.hasType<std::string>()) {
|
||||
@@ -765,6 +814,9 @@ inline folly::dynamic toDynamic(const TextAttributes &textAttributes) {
|
||||
if (!std::isnan(textAttributes.letterSpacing)) {
|
||||
_textAttributes("letterSpacing", textAttributes.letterSpacing);
|
||||
}
|
||||
if (textAttributes.textTransform.hasValue()) {
|
||||
_textAttributes("textTransform", toString(*textAttributes.textTransform));
|
||||
}
|
||||
if (!std::isnan(textAttributes.lineHeight)) {
|
||||
_textAttributes("lineHeight", textAttributes.lineHeight);
|
||||
}
|
||||
|
||||
@@ -117,6 +117,14 @@ enum class AccessibilityRole {
|
||||
Toolbar,
|
||||
};
|
||||
|
||||
enum class TextTransform {
|
||||
None,
|
||||
Uppercase,
|
||||
Lowercase,
|
||||
Capitalize,
|
||||
Unset,
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
@@ -197,4 +205,11 @@ struct hash<facebook::react::AccessibilityRole> {
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::TextTransform> {
|
||||
size_t operator()(const facebook::react::TextTransform &v) const {
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
@@ -79,6 +79,11 @@ static TextAttributes convertRawProp(
|
||||
"letterSpacing",
|
||||
sourceTextAttributes.letterSpacing,
|
||||
defaultTextAttributes.letterSpacing);
|
||||
textAttributes.textTransform = convertRawProp(
|
||||
rawProps,
|
||||
"textTransform",
|
||||
sourceTextAttributes.textTransform,
|
||||
defaultTextAttributes.textTransform);
|
||||
|
||||
// Paragraph
|
||||
textAttributes.lineHeight = convertRawProp(
|
||||
|
||||
Reference in New Issue
Block a user