diff --git a/ReactCommon/fabric/attributedstring/ParagraphAttributes.cpp b/ReactCommon/fabric/attributedstring/ParagraphAttributes.cpp index 3901c18cf..43d895e76 100644 --- a/ReactCommon/fabric/attributedstring/ParagraphAttributes.cpp +++ b/ReactCommon/fabric/attributedstring/ParagraphAttributes.cpp @@ -10,27 +10,21 @@ #include #include +#include "debugStringConvertibleUtils.h" + namespace facebook { namespace react { #pragma mark - DebugStringConvertible SharedDebugStringConvertibleList ParagraphAttributes::getDebugProps() const { - ParagraphAttributes defaultParagraphAttributes = {}; - SharedDebugStringConvertibleList list = {}; - -#define PARAGRAPH_ATTRIBUTE(stringName, propertyName, accessor, convertor) \ - if (propertyName != defaultParagraphAttributes.propertyName) { \ - list.push_back(std::make_shared(#stringName, convertor(propertyName accessor))); \ - } - - PARAGRAPH_ATTRIBUTE(maximumNumberOfLines, maximumNumberOfLines, , std::to_string) - PARAGRAPH_ATTRIBUTE(ellipsizeMode, ellipsizeMode, , stringFromEllipsizeMode) - PARAGRAPH_ATTRIBUTE(adjustsFontSizeToFit, adjustsFontSizeToFit, , std::to_string) - PARAGRAPH_ATTRIBUTE(minimumFontSize, minimumFontSize, , std::to_string) - PARAGRAPH_ATTRIBUTE(maximumFontSize, maximumFontSize, , std::to_string) - - return list; + return { + debugStringConvertibleItem("maximumNumberOfLines", maximumNumberOfLines), + debugStringConvertibleItem("ellipsizeMode", ellipsizeMode), + debugStringConvertibleItem("adjustsFontSizeToFit", adjustsFontSizeToFit), + debugStringConvertibleItem("minimumFontSize", minimumFontSize), + debugStringConvertibleItem("maximumFontSize", maximumFontSize) + }; } } // namespace react diff --git a/ReactCommon/fabric/attributedstring/TextAttributes.cpp b/ReactCommon/fabric/attributedstring/TextAttributes.cpp index 984aba5d3..4f85297dc 100644 --- a/ReactCommon/fabric/attributedstring/TextAttributes.cpp +++ b/ReactCommon/fabric/attributedstring/TextAttributes.cpp @@ -7,8 +7,9 @@ #include "TextAttributes.h" -#include +#include #include +#include "debugStringConvertibleUtils.h" namespace facebook { namespace react { @@ -53,26 +54,44 @@ void TextAttributes::apply(TextAttributes textAttributes) { #pragma mark - DebugStringConvertible SharedDebugStringConvertibleList TextAttributes::getDebugProps() const { - TextAttributes defaultAttributes = {}; - - SharedDebugStringConvertibleList list = {}; - -#define PROPS_ADD_TO_SET(propertyName, accessor, convertor) \ - if (propertyName != defaultAttributes.propertyName) { \ - list.push_back(std::make_shared(#propertyName, convertor(propertyName accessor))); \ - } - - PROPS_ADD_TO_SET(backgroundColor, , colorNameFromColor) - PROPS_ADD_TO_SET(foregroundColor, , colorNameFromColor) - PROPS_ADD_TO_SET(opacity, , std::to_string) - - PROPS_ADD_TO_SET(fontFamily, , ) - PROPS_ADD_TO_SET(fontSize, , std::to_string) - PROPS_ADD_TO_SET(fontSizeMultiplier, , std::to_string) - // TODO: Implement all fields. - return list; + return { + // Color + debugStringConvertibleItem("backgroundColor", backgroundColor), + debugStringConvertibleItem("foregroundColor", foregroundColor), + debugStringConvertibleItem("opacity", opacity), + + // Font + debugStringConvertibleItem("fontFamily", fontFamily), + debugStringConvertibleItem("fontSize", fontSize), + debugStringConvertibleItem("fontSizeMultiplier", fontSizeMultiplier), + debugStringConvertibleItem("fontWeight", fontWeight), + debugStringConvertibleItem("fontStyle", fontStyle), + //debugStringConvertibleItem("fontVariant", fontVariant), + debugStringConvertibleItem("allowFontScaling", allowFontScaling), + debugStringConvertibleItem("letterSpacing", letterSpacing), + + // Paragraph Styles + debugStringConvertibleItem("lineHeight", lineHeight), + //debugStringConvertibleItem("alignment", alignment), + //debugStringConvertibleItem("baseWritingDirection", baseWritingDirection), + + // Decoration + debugStringConvertibleItem("textDecorationColor", textDecorationColor), + //debugStringConvertibleItem("textDecorationLineType", textDecorationLineType), + //debugStringConvertibleItem("textDecorationLineStyle", textDecorationLineStyle), + //debugStringConvertibleItem("textDecorationLinePattern", textDecorationLinePattern), + + // Shadow + debugStringConvertibleItem("textShadowOffset", textShadowOffset), + debugStringConvertibleItem("textShadowRadius", textShadowRadius), + debugStringConvertibleItem("textShadowColor", textShadowColor), + + // Special + debugStringConvertibleItem("isHighlighted", isHighlighted), + //debugStringConvertibleItem("layoutDirection", layoutDirection), + }; } } // namespace react diff --git a/ReactCommon/fabric/attributedstring/debugStringConvertibleUtils.h b/ReactCommon/fabric/attributedstring/debugStringConvertibleUtils.h new file mode 100644 index 000000000..617efb4c1 --- /dev/null +++ b/ReactCommon/fabric/attributedstring/debugStringConvertibleUtils.h @@ -0,0 +1,21 @@ +/** + * 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) + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/attributedstring/textValuesConversions.h b/ReactCommon/fabric/attributedstring/textValuesConversions.h index 88480b6ff..deb5660e2 100644 --- a/ReactCommon/fabric/attributedstring/textValuesConversions.h +++ b/ReactCommon/fabric/attributedstring/textValuesConversions.h @@ -49,6 +49,10 @@ inline FontWeight fontWeightFromDynamic(const folly::dynamic &value) { 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; } @@ -57,6 +61,14 @@ inline FontStyle fontStyleFromDynamic(const folly::dynamic &value) { 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; diff --git a/ReactCommon/fabric/debug/DebugStringConvertible.cpp b/ReactCommon/fabric/debug/DebugStringConvertible.cpp index ce2c91611..08d885d96 100644 --- a/ReactCommon/fabric/debug/DebugStringConvertible.cpp +++ b/ReactCommon/fabric/debug/DebugStringConvertible.cpp @@ -18,6 +18,10 @@ std::string DebugStringConvertible::getDebugChildrenDescription(DebugStringConve std::string childrenString = ""; for (auto child : getDebugChildren()) { + if (!child) { + continue; + } + childrenString += child->getDebugDescription(options, depth + 1); } @@ -32,6 +36,10 @@ std::string DebugStringConvertible::getDebugPropsDescription(DebugStringConverti std::string propsString = ""; for (auto prop : getDebugProps()) { + if (!prop) { + continue; + } + auto name = prop->getDebugName(); auto value = prop->getDebugValue(); auto children = prop->getDebugPropsDescription(options, depth + 1); diff --git a/ReactCommon/fabric/debug/debugStringConvertibleUtils.cpp b/ReactCommon/fabric/debug/debugStringConvertibleUtils.cpp new file mode 100644 index 000000000..de9817d49 --- /dev/null +++ b/ReactCommon/fabric/debug/debugStringConvertibleUtils.cpp @@ -0,0 +1,25 @@ +/** + * 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. + */ + +#include "debugStringConvertibleUtils.h" + +namespace facebook { +namespace react { + +SharedDebugStringConvertibleList operator+(const SharedDebugStringConvertibleList &lhs, const SharedDebugStringConvertibleList &rhs) { + SharedDebugStringConvertibleList result = {}; + std::move(lhs.begin(), lhs.end(), std::back_inserter(result)); + std::move(rhs.begin(), rhs.end(), std::back_inserter(result)); + return result; +} + +SharedDebugStringConvertible debugStringConvertibleItem(std::string name, DebugStringConvertible value, std::string defaultValue) { + return debugStringConvertibleItem(name, value.getDebugDescription(), defaultValue); +} + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/debug/debugStringConvertibleUtils.h b/ReactCommon/fabric/debug/debugStringConvertibleUtils.h new file mode 100644 index 000000000..d6be81b3c --- /dev/null +++ b/ReactCommon/fabric/debug/debugStringConvertibleUtils.h @@ -0,0 +1,53 @@ +/** + * 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 + +#include +#include +#include + +namespace facebook { +namespace react { + +SharedDebugStringConvertibleList operator+(const SharedDebugStringConvertibleList &lhs, const SharedDebugStringConvertibleList &rhs); +SharedDebugStringConvertible debugStringConvertibleItem(std::string name, DebugStringConvertible value, std::string defaultValue = ""); + +#define IS_EQUAL(a, b) ((a) == (b)) +#define IS_EQUAL_FLOAT(a, b) ((isnan(a) == isnan(b)) || ((a) == (b))) + +#define DEBUG_STRING_CONVERTIBLE_TEMPLATE(type, converter) \ +DEBUG_STRING_CONVERTIBLE_TEMPLATE_EX(type, converter, {}, IS_EQUAL) + +#define DEBUG_STRING_CONVERTIBLE_TEMPLATE_EX(type, converter, defaults, comparator) \ +inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, type value, type defaultValue = defaults) { \ + if (comparator(value, defaultValue)) { \ + return nullptr; \ + } \ + return std::make_shared(name, converter(value)); \ +} \ +\ +inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, folly::Optional value, type defaultValue = defaults) { \ + if (value.has_value()) { \ + return nullptr; \ + } \ + return debugStringConvertibleItem(name, value.value_or(defaultValue), defaultValue); \ +} + +DEBUG_STRING_CONVERTIBLE_TEMPLATE(std::string, ) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(int, folly::to) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(bool, folly::to) +DEBUG_STRING_CONVERTIBLE_TEMPLATE_EX(float, folly::to, std::numeric_limits::quiet_NaN(), IS_EQUAL_FLOAT) +DEBUG_STRING_CONVERTIBLE_TEMPLATE_EX(double, folly::to, std::numeric_limits::quiet_NaN(), IS_EQUAL_FLOAT) + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/graphics/debugStringConvertibleUtils.h b/ReactCommon/fabric/graphics/debugStringConvertibleUtils.h new file mode 100644 index 000000000..d67dd14cc --- /dev/null +++ b/ReactCommon/fabric/graphics/debugStringConvertibleUtils.h @@ -0,0 +1,22 @@ +/** + * 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(Point, stringFromPoint) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(Size, stringFromSize) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(Rect, stringFromRect) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(SharedColor, colorNameFromColor) + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/text/basetext/BaseTextProps.cpp b/ReactCommon/fabric/text/basetext/BaseTextProps.cpp index 4b3e1a80e..5b03c924d 100644 --- a/ReactCommon/fabric/text/basetext/BaseTextProps.cpp +++ b/ReactCommon/fabric/text/basetext/BaseTextProps.cpp @@ -61,12 +61,7 @@ TextAttributes BaseTextProps::getTextAttributes() const { #pragma mark - DebugStringConvertible SharedDebugStringConvertibleList BaseTextProps::getDebugProps() const { - SharedDebugStringConvertibleList list = {}; - - auto textAttributesPropsList = textAttributes_.getDebugProps(); - std::move(textAttributesPropsList.begin(), textAttributesPropsList.end(), std::back_inserter(list)); - - return list; + return textAttributes_.getDebugProps(); } } // namespace react diff --git a/ReactCommon/fabric/text/paragraph/ParagraphLocalData.cpp b/ReactCommon/fabric/text/paragraph/ParagraphLocalData.cpp index 0390313b6..0064ee862 100644 --- a/ReactCommon/fabric/text/paragraph/ParagraphLocalData.cpp +++ b/ReactCommon/fabric/text/paragraph/ParagraphLocalData.cpp @@ -7,7 +7,7 @@ #include "ParagraphLocalData.h" -#include +#include namespace facebook { namespace react { @@ -37,9 +37,9 @@ std::string ParagraphLocalData::getDebugName() const { } SharedDebugStringConvertibleList ParagraphLocalData::getDebugProps() const { - SharedDebugStringConvertibleList list = {}; - list.push_back(std::make_shared("attributedString", attributedString_.getDebugDescription())); - return list; + return { + debugStringConvertibleItem("attributedString", attributedString_) + }; } } // namespace react diff --git a/ReactCommon/fabric/text/paragraph/ParagraphProps.cpp b/ReactCommon/fabric/text/paragraph/ParagraphProps.cpp index 95be162bb..a4481e138 100644 --- a/ReactCommon/fabric/text/paragraph/ParagraphProps.cpp +++ b/ReactCommon/fabric/text/paragraph/ParagraphProps.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include namespace facebook { @@ -43,21 +43,10 @@ bool ParagraphProps::getIsSelectable() const { #pragma mark - DebugStringConvertible SharedDebugStringConvertibleList ParagraphProps::getDebugProps() const { - SharedDebugStringConvertibleList list = {}; - - // View Props - auto &&viewPropsList = ViewProps::getDebugProps(); - std::move(viewPropsList.begin(), viewPropsList.end(), std::back_inserter(list)); - - // Paragraph Props - auto &¶graphAttributePropsList = paragraphAttributes_.getDebugProps(); - std::move(paragraphAttributePropsList.begin(), paragraphAttributePropsList.end(), std::back_inserter(list)); - - // Base Text Props - auto &&baseTextPropsList = BaseTextProps::getDebugProps(); - std::move(baseTextPropsList.begin(), baseTextPropsList.end(), std::back_inserter(list)); - - return list; + return + ViewProps::getDebugProps() + + paragraphAttributes_.getDebugProps() + + BaseTextProps::getDebugProps(); } } // namespace react