diff --git a/ReactCommon/fabric/attributedstring/ParagraphAttributes.cpp b/ReactCommon/fabric/attributedstring/ParagraphAttributes.cpp index 43d895e7608..f3382a54d4c 100644 --- a/ReactCommon/fabric/attributedstring/ParagraphAttributes.cpp +++ b/ReactCommon/fabric/attributedstring/ParagraphAttributes.cpp @@ -7,10 +7,8 @@ #include "ParagraphAttributes.h" -#include -#include - -#include "debugStringConvertibleUtils.h" +#include +#include namespace facebook { namespace react { diff --git a/ReactCommon/fabric/attributedstring/ParagraphAttributes.h b/ReactCommon/fabric/attributedstring/ParagraphAttributes.h index baa47c0c363..b6271999a2d 100644 --- a/ReactCommon/fabric/attributedstring/ParagraphAttributes.h +++ b/ReactCommon/fabric/attributedstring/ParagraphAttributes.h @@ -9,7 +9,7 @@ #include -#include +#include #include #include diff --git a/ReactCommon/fabric/attributedstring/TextAttributes.cpp b/ReactCommon/fabric/attributedstring/TextAttributes.cpp index 0373f5f2a3b..fe696774904 100644 --- a/ReactCommon/fabric/attributedstring/TextAttributes.cpp +++ b/ReactCommon/fabric/attributedstring/TextAttributes.cpp @@ -7,10 +7,10 @@ #include "TextAttributes.h" +#include #include #include #include -#include "debugStringConvertibleUtils.h" namespace facebook { namespace react { diff --git a/ReactCommon/fabric/attributedstring/TextAttributes.h b/ReactCommon/fabric/attributedstring/TextAttributes.h index 30159eb5c8f..c474e7e2aa6 100644 --- a/ReactCommon/fabric/attributedstring/TextAttributes.h +++ b/ReactCommon/fabric/attributedstring/TextAttributes.h @@ -9,7 +9,7 @@ #include -#include +#include #include #include #include diff --git a/ReactCommon/fabric/attributedstring/conversions.h b/ReactCommon/fabric/attributedstring/conversions.h new file mode 100644 index 00000000000..478d423517f --- /dev/null +++ b/ReactCommon/fabric/attributedstring/conversions.h @@ -0,0 +1,192 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include +#include + +namespace facebook { +namespace react { + +inline std::string toString(const EllipsizeMode &ellipsisMode) { + switch (ellipsisMode) { + case EllipsizeMode::Clip: return "clip"; + case EllipsizeMode::Head: return "head"; + case EllipsizeMode::Tail: return "tail"; + case EllipsizeMode::Middle: return "middle"; + } +} + +inline void fromDynamic(const folly::dynamic &value, EllipsizeMode &result) { + auto string = value.getString(); + if (string == "clip") { result = EllipsizeMode::Clip; return; } + if (string == "head") { result = EllipsizeMode::Head; return; } + if (string == "tail") { result = EllipsizeMode::Tail; return; } + if (string == "middle") { result = EllipsizeMode::Middle; return; } + abort(); +} + +inline void fromDynamic(const folly::dynamic &value, FontWeight &result) { + auto string = value.asString(); + if (string == "normal") { result = FontWeight::Regular; return; } + if (string == "regular") { result = FontWeight::Regular; return; } + if (string == "bold") { result = FontWeight::Bold; return; } + if (string == "100") { result = FontWeight::Weight100; return; } + if (string == "200") { result = FontWeight::Weight200; return; } + if (string == "300") { result = FontWeight::Weight300; return; } + if (string == "400") { result = FontWeight::Weight400; return; } + if (string == "500") { result = FontWeight::Weight500; return; } + if (string == "600") { result = FontWeight::Weight600; return; } + if (string == "700") { result = FontWeight::Weight700; return; } + if (string == "800") { result = FontWeight::Weight800; return; } + if (string == "900") { result = FontWeight::Weight900; return; } + abort(); +} + +inline std::string toString(const FontWeight &fontWeight) { + return std::to_string((int)fontWeight); +} + +inline void fromDynamic(const folly::dynamic &value, FontStyle &result) { + auto string = value.asString(); + if (string == "normal") { result = FontStyle::Normal; return; } + if (string == "italic") { result = FontStyle::Italic; return; } + if (string == "oblique") { result = FontStyle::Oblique; return; } + abort(); +} + +inline std::string toString(const FontStyle &fontStyle) { + switch (fontStyle) { + case FontStyle::Normal: return "normal"; + case FontStyle::Italic: return "italic"; + case FontStyle::Oblique: return "oblique"; + } +} + +inline void fromDynamic(const folly::dynamic &value, FontVariant &result) { + assert(value.isArray()); + result = FontVariant::Default; + for (auto &&item : value) { + auto string = item.asString(); + if (string == "small-caps") { result = (FontVariant)((int)result | (int)FontVariant::SmallCaps); continue; } + if (string == "oldstyle-nums") { result = (FontVariant)((int)result | (int)FontVariant::OldstyleNums); continue; } + if (string == "lining-nums") { result = (FontVariant)((int)result | (int)FontVariant::LiningNums); continue; } + if (string == "tabular-nums") { result = (FontVariant)((int)result | (int)FontVariant::TabularNums); continue; } + if (string == "proportional-nums") { result = (FontVariant)((int)result | (int)FontVariant::ProportionalNums); continue; } + } +} + +inline std::string toString(const FontVariant &fontVariant) { + std::string result; + std::string separator = ", "; + if ((int)fontVariant & (int)FontVariant::SmallCaps) { result += "small-caps" + separator; } + if ((int)fontVariant & (int)FontVariant::OldstyleNums) { result += "oldstyle-nums" + separator; } + if ((int)fontVariant & (int)FontVariant::LiningNums) { result += "lining-nums" + separator; } + if ((int)fontVariant & (int)FontVariant::TabularNums) { result += "tabular-nums" + separator; } + if ((int)fontVariant & (int)FontVariant::ProportionalNums) { result += "proportional-nums" + separator; } + + if (!result.empty()) { + result.erase(result.length() - separator.length()); + } + + return result; +} + +inline void fromDynamic(const folly::dynamic &value, TextAlignment &result) { + auto string = value.asString(); + if (string == "natural") { result = TextAlignment::Natural; return; } + if (string == "left") { result = TextAlignment::Left; return; } + if (string == "center") { result = TextAlignment::Center; return; } + if (string == "right") { result = TextAlignment::Right; return; } + if (string == "justified") { result = TextAlignment::Justified; return; } + abort(); +} + +inline std::string toString(const TextAlignment &textAlignment) { + switch (textAlignment) { + case TextAlignment::Natural: return "natural"; + case TextAlignment::Left: return "left"; + case TextAlignment::Center: return "center"; + case TextAlignment::Right: return "right"; + case TextAlignment::Justified: return "justified"; + } +} + +inline void fromDynamic(const folly::dynamic &value, WritingDirection &result) { + auto string = value.asString(); + if (string == "natural") { result = WritingDirection::Natural; return; } + if (string == "ltr") { result = WritingDirection::LeftToRight; return; } + if (string == "rtl") { result = WritingDirection::RightToLeft; return; } + abort(); +} + +inline std::string toString(const WritingDirection &writingDirection) { + switch (writingDirection) { + case WritingDirection::Natural: return "natural"; + case WritingDirection::LeftToRight: return "ltr"; + case WritingDirection::RightToLeft: return "rtl"; + } +} + +inline void fromDynamic(const folly::dynamic &value, TextDecorationLineType &result) { + auto string = value.asString(); + if (string == "none") { result = TextDecorationLineType::None; return; } + if (string == "underline") { result = TextDecorationLineType::Underline; return; } + if (string == "strikethrough") { result = TextDecorationLineType::Strikethrough; return; } + if (string == "underline-strikethrough") { result = TextDecorationLineType::UnderlineStrikethrough; return; } + abort(); +} + +inline std::string toString(const TextDecorationLineType &textDecorationLineType) { + switch (textDecorationLineType) { + case TextDecorationLineType::None: return "none"; + case TextDecorationLineType::Underline: return "underline"; + case TextDecorationLineType::Strikethrough: return "strikethrough"; + case TextDecorationLineType::UnderlineStrikethrough: return "underline-strikethrough"; + } +} + +inline void fromDynamic(const folly::dynamic &value, TextDecorationLineStyle &result) { + auto string = value.asString(); + if (string == "single") { result = TextDecorationLineStyle::Single; return; } + if (string == "thick") { result = TextDecorationLineStyle::Thick; return; } + if (string == "double") { result = TextDecorationLineStyle::Double; return; } + abort(); +} + +inline std::string toString(const TextDecorationLineStyle &textDecorationLineStyle) { + switch (textDecorationLineStyle) { + case TextDecorationLineStyle::Single: return "single"; + case TextDecorationLineStyle::Thick: return "thick"; + case TextDecorationLineStyle::Double: return "double"; + } +} + +inline void fromDynamic(const folly::dynamic &value, TextDecorationLinePattern &result) { + auto string = value.asString(); + if (string == "solid") { result = TextDecorationLinePattern::Solid; return; } + if (string == "dot") { result = TextDecorationLinePattern::Dot; return; } + if (string == "dash") { result = TextDecorationLinePattern::Dash; return; } + if (string == "dash-dot") { result = TextDecorationLinePattern::DashDot; return; } + if (string == "dash-dot-dot") { result = TextDecorationLinePattern::DashDotDot; return; } + abort(); +} + +inline std::string toString(const TextDecorationLinePattern &textDecorationLinePattern) { + switch (textDecorationLinePattern) { + case TextDecorationLinePattern::Solid: return "solid"; + case TextDecorationLinePattern::Dot: return "dot"; + case TextDecorationLinePattern::Dash: return "dash"; + case TextDecorationLinePattern::DashDot: return "dash-dot"; + case TextDecorationLinePattern::DashDotDot: return "dash-dot-dot"; + } +} + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/attributedstring/debugStringConvertibleUtils.h b/ReactCommon/fabric/attributedstring/debugStringConvertibleUtils.h deleted file mode 100644 index 3f303cd0668..00000000000 --- a/ReactCommon/fabric/attributedstring/debugStringConvertibleUtils.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -namespace facebook { -namespace react { - -DEBUG_STRING_CONVERTIBLE_TEMPLATE(EllipsizeMode, stringFromEllipsizeMode) -DEBUG_STRING_CONVERTIBLE_TEMPLATE(FontWeight, stringFromFontWeight) -DEBUG_STRING_CONVERTIBLE_TEMPLATE(FontStyle, stringFromFontStyle) -DEBUG_STRING_CONVERTIBLE_TEMPLATE(FontVariant, stringFromFontVariant) -DEBUG_STRING_CONVERTIBLE_TEMPLATE(TextAlignment, stringFromTextAlignment) -DEBUG_STRING_CONVERTIBLE_TEMPLATE(WritingDirection, stringFromWritingDirection) -DEBUG_STRING_CONVERTIBLE_TEMPLATE(TextDecorationLineType, stringFromTextDecorationLineType) -DEBUG_STRING_CONVERTIBLE_TEMPLATE(TextDecorationLineStyle, stringFromTextDecorationLineStyle) -DEBUG_STRING_CONVERTIBLE_TEMPLATE(TextDecorationLinePattern, stringFromTextDecorationLinePattern) - -} // namespace react -} // namespace facebook diff --git a/ReactCommon/fabric/attributedstring/TextPrimitives.h b/ReactCommon/fabric/attributedstring/primitives.h similarity index 100% rename from ReactCommon/fabric/attributedstring/TextPrimitives.h rename to ReactCommon/fabric/attributedstring/primitives.h diff --git a/ReactCommon/fabric/attributedstring/tests/AttributedStringTest.cpp b/ReactCommon/fabric/attributedstring/tests/AttributedStringTest.cpp index b3a8eddd343..a04597a7455 100644 --- a/ReactCommon/fabric/attributedstring/tests/AttributedStringTest.cpp +++ b/ReactCommon/fabric/attributedstring/tests/AttributedStringTest.cpp @@ -9,10 +9,6 @@ #include -#include - -using namespace facebook::react; - TEST(AttributedStringTest, testSomething) { // TODO } diff --git a/ReactCommon/fabric/attributedstring/textValuesConversions.h b/ReactCommon/fabric/attributedstring/textValuesConversions.h deleted file mode 100644 index bae4eb65be9..00000000000 --- a/ReactCommon/fabric/attributedstring/textValuesConversions.h +++ /dev/null @@ -1,193 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include - -namespace facebook { -namespace react { - -inline std::string stringFromEllipsizeMode(const EllipsizeMode &ellipsisMode) { - switch (ellipsisMode) { - case EllipsizeMode::Clip: return "clip"; - case EllipsizeMode::Head: return "head"; - case EllipsizeMode::Tail: return "tail"; - case EllipsizeMode::Middle: return "middle"; - } -} - -inline EllipsizeMode ellipsizeModeFromDynamic(const folly::dynamic &value) { - auto string = value.getString(); - if (string == "clip") { return EllipsizeMode::Clip; } - if (string == "head") { return EllipsizeMode::Head; } - if (string == "tail") { return EllipsizeMode::Tail; } - if (string == "middle") { return EllipsizeMode::Middle; } - abort(); -} - -inline FontWeight fontWeightFromDynamic(const folly::dynamic &value) { - auto string = value.asString(); - if (string == "normal") { return FontWeight::Regular; } - if (string == "regular") { return FontWeight::Regular; } - if (string == "bold") { return FontWeight::Bold; } - if (string == "100") { return FontWeight::Weight100; } - if (string == "200") { return FontWeight::Weight200; } - if (string == "300") { return FontWeight::Weight300; } - if (string == "400") { return FontWeight::Weight400; } - if (string == "500") { return FontWeight::Weight500; } - if (string == "600") { return FontWeight::Weight600; } - if (string == "700") { return FontWeight::Weight700; } - if (string == "800") { return FontWeight::Weight800; } - if (string == "900") { return FontWeight::Weight900; } - abort(); -} - -inline std::string stringFromFontWeight(const FontWeight &fontWeight) { - return std::to_string((int)fontWeight); -} - -inline FontStyle fontStyleFromDynamic(const folly::dynamic &value) { - auto string = value.asString(); - if (string == "normal") { return FontStyle::Normal; } - if (string == "italic") { return FontStyle::Italic; } - if (string == "oblique") { return FontStyle::Oblique; } - abort(); -} - -inline std::string stringFromFontStyle(const FontStyle &fontStyle) { - switch (fontStyle) { - case FontStyle::Normal: return "normal"; - case FontStyle::Italic: return "italic"; - case FontStyle::Oblique: return "oblique"; - } -} - -inline FontVariant fontVariantFromDynamic(const folly::dynamic &value) { - assert(value.isArray()); - FontVariant fontVariant = FontVariant::Default; - for (auto &&item : value) { - auto string = item.asString(); - if (string == "small-caps") { fontVariant = (FontVariant)((int)fontVariant | (int)FontVariant::SmallCaps); continue; } - if (string == "oldstyle-nums") { fontVariant = (FontVariant)((int)fontVariant | (int)FontVariant::OldstyleNums); continue; } - if (string == "lining-nums") { fontVariant = (FontVariant)((int)fontVariant | (int)FontVariant::LiningNums); continue; } - if (string == "tabular-nums") { fontVariant = (FontVariant)((int)fontVariant | (int)FontVariant::TabularNums); continue; } - if (string == "proportional-nums") { fontVariant = (FontVariant)((int)fontVariant | (int)FontVariant::ProportionalNums); continue; } - } - return fontVariant; -} - -inline std::string stringFromFontVariant(const FontVariant &fontVariant) { - std::string result; - std::string separator = ", "; - if ((int)fontVariant & (int)FontVariant::SmallCaps) { result += "small-caps" + separator; } - if ((int)fontVariant & (int)FontVariant::OldstyleNums) { result += "oldstyle-nums" + separator; } - if ((int)fontVariant & (int)FontVariant::LiningNums) { result += "lining-nums" + separator; } - if ((int)fontVariant & (int)FontVariant::TabularNums) { result += "tabular-nums" + separator; } - if ((int)fontVariant & (int)FontVariant::ProportionalNums) { result += "proportional-nums" + separator; } - - if (!result.empty()) { - result.erase(result.length() - separator.length()); - } - - return result; -} - -inline TextAlignment textAlignmentFromDynamic(const folly::dynamic &value) { - auto string = value.asString(); - if (string == "natural") { return TextAlignment::Natural; } - if (string == "left") { return TextAlignment::Left; } - if (string == "center") { return TextAlignment::Center; } - if (string == "right") { return TextAlignment::Right; } - if (string == "justified") { return TextAlignment::Justified; } - abort(); -} - -inline std::string stringFromTextAlignment(const TextAlignment &textAlignment) { - switch (textAlignment) { - case TextAlignment::Natural: return "natural"; - case TextAlignment::Left: return "left"; - case TextAlignment::Center: return "center"; - case TextAlignment::Right: return "right"; - case TextAlignment::Justified: return "justified"; - } -} - -inline WritingDirection writingDirectionFromDynamic(const folly::dynamic &value) { - auto string = value.asString(); - if (string == "natural") { return WritingDirection::Natural; } - if (string == "ltr") { return WritingDirection::LeftToRight; } - if (string == "rtl") { return WritingDirection::RightToLeft; } - abort(); -} - -inline std::string stringFromWritingDirection(const WritingDirection &writingDirection) { - switch (writingDirection) { - case WritingDirection::Natural: return "natural"; - case WritingDirection::LeftToRight: return "ltr"; - case WritingDirection::RightToLeft: return "rtl"; - } -} - -inline TextDecorationLineType textDecorationLineTypeFromDynamic(const folly::dynamic &value) { - auto string = value.asString(); - if (string == "none") { return TextDecorationLineType::None; } - if (string == "underline") { return TextDecorationLineType::Underline; } - if (string == "strikethrough") { return TextDecorationLineType::Strikethrough; } - if (string == "underline-strikethrough") { return TextDecorationLineType::UnderlineStrikethrough; } - abort(); -} - -inline std::string stringFromTextDecorationLineType(const TextDecorationLineType &textDecorationLineType) { - switch (textDecorationLineType) { - case TextDecorationLineType::None: return "none"; - case TextDecorationLineType::Underline: return "underline"; - case TextDecorationLineType::Strikethrough: return "strikethrough"; - case TextDecorationLineType::UnderlineStrikethrough: return "underline-strikethrough"; - } -} - -inline TextDecorationLineStyle textDecorationLineStyleFromDynamic(const folly::dynamic &value) { - auto string = value.asString(); - if (string == "single") { return TextDecorationLineStyle::Single; } - if (string == "thick") { return TextDecorationLineStyle::Thick; } - if (string == "double") { return TextDecorationLineStyle::Double; } - abort(); -} - -inline std::string stringFromTextDecorationLineStyle(const TextDecorationLineStyle &textDecorationLineStyle) { - switch (textDecorationLineStyle) { - case TextDecorationLineStyle::Single: return "single"; - case TextDecorationLineStyle::Thick: return "thick"; - case TextDecorationLineStyle::Double: return "double"; - } -} - -inline TextDecorationLinePattern textDecorationLinePatternFromDynamic(const folly::dynamic &value) { - auto string = value.asString(); - if (string == "solid") { return TextDecorationLinePattern::Solid; } - if (string == "dot") { return TextDecorationLinePattern::Dot; } - if (string == "dash") { return TextDecorationLinePattern::Dash; } - if (string == "dash-dot") { return TextDecorationLinePattern::DashDot; } - if (string == "dash-dot-dot") { return TextDecorationLinePattern::DashDotDot; } - abort(); -} - -inline std::string stringFromTextDecorationLinePattern(const TextDecorationLinePattern &textDecorationLinePattern) { - switch (textDecorationLinePattern) { - case TextDecorationLinePattern::Solid: return "solid"; - case TextDecorationLinePattern::Dot: return "dot"; - case TextDecorationLinePattern::Dash: return "dash"; - case TextDecorationLinePattern::DashDot: return "dash-dot"; - case TextDecorationLinePattern::DashDotDot: return "dash-dot-dot"; - } -} - -} // namespace react -} // namespace facebook diff --git a/ReactCommon/fabric/text/basetext/BaseTextProps.cpp b/ReactCommon/fabric/text/basetext/BaseTextProps.cpp index 73647435587..d900d0ab2f5 100644 --- a/ReactCommon/fabric/text/basetext/BaseTextProps.cpp +++ b/ReactCommon/fabric/text/basetext/BaseTextProps.cpp @@ -7,11 +7,10 @@ #include "BaseTextProps.h" -#include +#include #include #include #include -#include namespace facebook { namespace react { diff --git a/ReactCommon/fabric/text/paragraph/ParagraphLocalData.cpp b/ReactCommon/fabric/text/paragraph/ParagraphLocalData.cpp index c96098981d6..30fc681fd04 100644 --- a/ReactCommon/fabric/text/paragraph/ParagraphLocalData.cpp +++ b/ReactCommon/fabric/text/paragraph/ParagraphLocalData.cpp @@ -8,7 +8,6 @@ #include "ParagraphLocalData.h" #include -#include namespace facebook { namespace react { diff --git a/ReactCommon/fabric/text/paragraph/ParagraphProps.cpp b/ReactCommon/fabric/text/paragraph/ParagraphProps.cpp index 628ee1eff74..a6ea79c6e71 100644 --- a/ReactCommon/fabric/text/paragraph/ParagraphProps.cpp +++ b/ReactCommon/fabric/text/paragraph/ParagraphProps.cpp @@ -7,10 +7,9 @@ #include "ParagraphProps.h" -#include +#include #include #include -#include namespace facebook { namespace react { diff --git a/ReactCommon/fabric/text/propsConversions.h b/ReactCommon/fabric/text/propsConversions.h deleted file mode 100644 index b8362947f43..00000000000 --- a/ReactCommon/fabric/text/propsConversions.h +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include -#include - -namespace facebook { -namespace react { - -CONVERT_RAW_PROP_TEMPLATE(EllipsizeMode, ellipsizeModeFromDynamic) -CONVERT_RAW_PROP_TEMPLATE(FontWeight, fontWeightFromDynamic) -CONVERT_RAW_PROP_TEMPLATE(FontStyle, fontStyleFromDynamic) -CONVERT_RAW_PROP_TEMPLATE(FontVariant, fontVariantFromDynamic) -CONVERT_RAW_PROP_TEMPLATE(WritingDirection, writingDirectionFromDynamic) -CONVERT_RAW_PROP_TEMPLATE(TextAlignment, textAlignmentFromDynamic) -CONVERT_RAW_PROP_TEMPLATE(TextDecorationLineType, textDecorationLineTypeFromDynamic) -CONVERT_RAW_PROP_TEMPLATE(TextDecorationLineStyle, textDecorationLineStyleFromDynamic) -CONVERT_RAW_PROP_TEMPLATE(TextDecorationLinePattern, textDecorationLinePatternFromDynamic) - -} // namespace react -} // namespace facebook diff --git a/ReactCommon/fabric/text/text/TextProps.cpp b/ReactCommon/fabric/text/text/TextProps.cpp index 5e8a3e1c669..443fe48c045 100644 --- a/ReactCommon/fabric/text/text/TextProps.cpp +++ b/ReactCommon/fabric/text/text/TextProps.cpp @@ -7,12 +7,6 @@ #include "TextProps.h" -#include -#include -#include -#include -#include - namespace facebook { namespace react {