diff --git a/ReactCommon/fabric/view/debugStringConvertibleUtils.h b/ReactCommon/fabric/view/debugStringConvertibleUtils.h new file mode 100644 index 000000000..a1a2f9422 --- /dev/null +++ b/ReactCommon/fabric/view/debugStringConvertibleUtils.h @@ -0,0 +1,48 @@ +/** + * 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 + +// Yoga does not have this as part of the library, so we have to implement it +// here ouside of `facebook::react::` namespace. +inline bool operator==(const YGValue &lhs, const YGValue &rhs) { + if ( + (lhs.unit == YGUnitUndefined && rhs.unit == YGUnitUndefined) || + (lhs.unit == YGUnitAuto && rhs.unit == YGUnitAuto) + ) { + return true; + } + + return + lhs.unit == rhs.unit && + ((isnan(lhs.value) && isnan(rhs.value)) || (lhs.value == rhs.value)); +} + +namespace facebook { +namespace react { + +using YogaDimentionsType = std::array; +using YogaEdgesType = std::array; + +DEBUG_STRING_CONVERTIBLE_TEMPLATE(YogaDimentionsType, stringFromYogaStyleDimensions) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(YogaEdgesType, stringFromYogaStyleEdges) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(YGDirection, stringFromYogaStyleDirection) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(YGFlexDirection, stringFromYogaStyleFlexDirection) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(YGJustify, stringFromYogaStyleJustify) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(YGAlign, stringFromYogaStyleAlign) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(YGPositionType, stringFromYogaStylePositionType) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(YGWrap, stringFromYogaStyleWrap) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(YGOverflow, stringFromYogaStyleOverflow) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(YGDisplay, stringFromYogaStyleDisplay) +DEBUG_STRING_CONVERTIBLE_TEMPLATE(YGValue, stringFromYogaStyleValue) +DEBUG_STRING_CONVERTIBLE_TEMPLATE_EX(YGFloatOptional, stringFromYogaStyleOptionalFloat, YGFloatOptional(), IS_EQUAL) + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/view/yoga/YogaStylableProps.cpp b/ReactCommon/fabric/view/yoga/YogaStylableProps.cpp index 88471868b..4a3553c1f 100644 --- a/ReactCommon/fabric/view/yoga/YogaStylableProps.cpp +++ b/ReactCommon/fabric/view/yoga/YogaStylableProps.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -27,46 +28,31 @@ YogaStylableProps::YogaStylableProps(const YogaStylableProps &sourceProps, const #pragma mark - DebugStringConvertible SharedDebugStringConvertibleList YogaStylableProps::getDebugProps() const { - SharedDebugStringConvertibleList list = {}; - - YGStyle defaultYogaStyle = YGStyle(); - YGStyle currentYogaStyle = yogaStyle; - -#define YOGA_STYLE_PROPS_ADD_TO_SET(stringName, propertyName, accessor, convertor) \ - { \ - auto currentValueString = convertor(currentYogaStyle.propertyName accessor); \ - auto defaultValueString = convertor(defaultYogaStyle.propertyName accessor); \ - if (currentValueString != defaultValueString) { \ - list.push_back(std::make_shared(#stringName, currentValueString)); \ - } \ - } - - YOGA_STYLE_PROPS_ADD_TO_SET(direction, direction, , stringFromYogaStyleDirection) - - YOGA_STYLE_PROPS_ADD_TO_SET(flexDirection, flexDirection, , stringFromYogaStyleFlexDirection) - YOGA_STYLE_PROPS_ADD_TO_SET(justifyContent, justifyContent, , stringFromYogaStyleJustify) - YOGA_STYLE_PROPS_ADD_TO_SET(alignItems, alignItems, , stringFromYogaStyleAlign) - YOGA_STYLE_PROPS_ADD_TO_SET(alignSelf, alignSelf, , stringFromYogaStyleAlign) - YOGA_STYLE_PROPS_ADD_TO_SET(positionType, positionType, , stringFromYogaStylePositionType) - YOGA_STYLE_PROPS_ADD_TO_SET(flexWrap, flexWrap, , stringFromYogaStyleWrap) - YOGA_STYLE_PROPS_ADD_TO_SET(overflow, overflow, , stringFromYogaStyleOverflow) - - YOGA_STYLE_PROPS_ADD_TO_SET(flex, flex, , stringFromYogaStyleOptionalFloat) - YOGA_STYLE_PROPS_ADD_TO_SET(flexGrow, flexGrow, , stringFromYogaStyleOptionalFloat) - YOGA_STYLE_PROPS_ADD_TO_SET(flexShrink, flexShrink, , stringFromYogaStyleOptionalFloat) - YOGA_STYLE_PROPS_ADD_TO_SET(flexBasis, flexBasis, , stringFromYogaStyleValue) - YOGA_STYLE_PROPS_ADD_TO_SET(margin, margin, , stringFromYogaStyleEdge) - YOGA_STYLE_PROPS_ADD_TO_SET(position, position, , stringFromYogaStyleEdge) - YOGA_STYLE_PROPS_ADD_TO_SET(padding, padding, , stringFromYogaStyleEdge) - YOGA_STYLE_PROPS_ADD_TO_SET(border, border, , stringFromYogaStyleEdge) - - YOGA_STYLE_PROPS_ADD_TO_SET(size, dimensions, , stringFromYogaStyleDimensions) - YOGA_STYLE_PROPS_ADD_TO_SET(minSize, minDimensions, , stringFromYogaStyleDimensions) - YOGA_STYLE_PROPS_ADD_TO_SET(maxSize, maxDimensions, , stringFromYogaStyleDimensions) - - YOGA_STYLE_PROPS_ADD_TO_SET(aspectRatio, aspectRatio, , stringFromYogaStyleOptionalFloat) - - return list; + YGStyle defaultYogaStyle; + return { + debugStringConvertibleItem("direction", yogaStyle.direction, defaultYogaStyle.direction), + debugStringConvertibleItem("flexDirection", yogaStyle.flexDirection, defaultYogaStyle.flexDirection), + debugStringConvertibleItem("justifyContent", yogaStyle.justifyContent, defaultYogaStyle.justifyContent), + debugStringConvertibleItem("alignContent", yogaStyle.alignContent, defaultYogaStyle.alignContent), + debugStringConvertibleItem("alignItems", yogaStyle.alignItems, defaultYogaStyle.alignItems), + debugStringConvertibleItem("alignSelf", yogaStyle.alignSelf, defaultYogaStyle.alignSelf), + debugStringConvertibleItem("positionType", yogaStyle.positionType, defaultYogaStyle.positionType), + debugStringConvertibleItem("flexWrap", yogaStyle.flexWrap, defaultYogaStyle.flexWrap), + debugStringConvertibleItem("overflow", yogaStyle.overflow, defaultYogaStyle.overflow), + debugStringConvertibleItem("display", yogaStyle.display, defaultYogaStyle.display), + debugStringConvertibleItem("flex", yogaStyle.flex, defaultYogaStyle.flex), + debugStringConvertibleItem("flexGrow", yogaStyle.flexGrow, defaultYogaStyle.flexGrow), + debugStringConvertibleItem("flexShrink", yogaStyle.flexShrink, defaultYogaStyle.flexShrink), + debugStringConvertibleItem("flexBasis", yogaStyle.flexBasis, defaultYogaStyle.flexBasis), + debugStringConvertibleItem("margin", yogaStyle.margin, defaultYogaStyle.margin), + debugStringConvertibleItem("position", yogaStyle.position, defaultYogaStyle.position), + debugStringConvertibleItem("padding", yogaStyle.padding, defaultYogaStyle.padding), + debugStringConvertibleItem("border", yogaStyle.border, defaultYogaStyle.border), + debugStringConvertibleItem("dimensions", yogaStyle.dimensions, defaultYogaStyle.dimensions), + debugStringConvertibleItem("minDimensions", yogaStyle.minDimensions, defaultYogaStyle.minDimensions), + debugStringConvertibleItem("maxDimensions", yogaStyle.maxDimensions, defaultYogaStyle.maxDimensions), + debugStringConvertibleItem("aspectRatio", yogaStyle.aspectRatio, defaultYogaStyle.aspectRatio), + }; } } // namespace react diff --git a/ReactCommon/fabric/view/yoga/YogaStylableProps.h b/ReactCommon/fabric/view/yoga/YogaStylableProps.h index 3dd023584..c62bb03e7 100644 --- a/ReactCommon/fabric/view/yoga/YogaStylableProps.h +++ b/ReactCommon/fabric/view/yoga/YogaStylableProps.h @@ -19,8 +19,7 @@ class YogaStylableProps; typedef std::shared_ptr SharedYogaStylableProps; -class YogaStylableProps: - public virtual DebugStringConvertible { +class YogaStylableProps { public: @@ -32,9 +31,9 @@ public: const YGStyle yogaStyle {}; -#pragma mark - DebugStringConvertible +#pragma mark - DebugStringConvertible (Partial) - SharedDebugStringConvertibleList getDebugProps() const override; + SharedDebugStringConvertibleList getDebugProps() const; }; } // namespace react diff --git a/ReactCommon/fabric/view/yoga/yogaValuesConversions.cpp b/ReactCommon/fabric/view/yoga/yogaValuesConversions.cpp index 328ea9f18..d53f78b2a 100644 --- a/ReactCommon/fabric/view/yoga/yogaValuesConversions.cpp +++ b/ReactCommon/fabric/view/yoga/yogaValuesConversions.cpp @@ -220,7 +220,7 @@ YGFloatOptional yogaStyleOptionalFloatFromDynamic(const folly::dynamic &value) { abort(); } -std::string stringFromYogaDimensions(std::array dimensions) { +std::string stringFromYogaDimensions(std::array dimensions) { return "{" + folly::to(dimensions[0]) + ", " + folly::to(dimensions[1]) + "}"; } @@ -228,7 +228,7 @@ std::string stringFromYogaPosition(std::array position) { return "{" + folly::to(position[0]) + ", " + folly::to(position[1]) + "}"; } -std::string stringFromYogaEdges(std::array edges) { +std::string stringFromYogaEdges(std::array edges) { return "{" + folly::to(edges[0]) + ", " + folly::to(edges[1]) + ", " + @@ -324,18 +324,23 @@ std::string stringFromYogaStyleOptionalFloat(YGFloatOptional value) { return folly::to(fabricFloatFromYogaFloat(value.getValue())); } -std::string stringFromYogaStyleDimensions(std::array value) { +std::string stringFromYogaStyleDimensions(std::array value) { return "{" + stringFromYogaStyleValue(value[0]) + ", " + stringFromYogaStyleValue(value[1]) + "}"; } -std::string stringFromYogaStyleEdge(std::array value) { +std::string stringFromYogaStyleEdges(std::array value) { return "{" + stringFromYogaStyleValue(value[0]) + ", " + stringFromYogaStyleValue(value[1]) + ", " + stringFromYogaStyleValue(value[2]) + ", " + - stringFromYogaStyleValue(value[3]) + "}"; + stringFromYogaStyleValue(value[3]) + ", " + + stringFromYogaStyleValue(value[4]) + ", " + + stringFromYogaStyleValue(value[5]) + ", " + + stringFromYogaStyleValue(value[6]) + ", " + + stringFromYogaStyleValue(value[7]) + ", " + + stringFromYogaStyleValue(value[8]) + "}"; } } // namespace react diff --git a/ReactCommon/fabric/view/yoga/yogaValuesConversions.h b/ReactCommon/fabric/view/yoga/yogaValuesConversions.h index 6837f9e10..376182933 100644 --- a/ReactCommon/fabric/view/yoga/yogaValuesConversions.h +++ b/ReactCommon/fabric/view/yoga/yogaValuesConversions.h @@ -39,9 +39,9 @@ YGDisplay yogaStyleDisplayFromDynamic(const folly::dynamic &value); YGValue yogaStyleValueFromDynamic(const folly::dynamic &value); YGFloatOptional yogaStyleOptionalFloatFromDynamic(const folly::dynamic &value); -std::string stringFromYogaDimensions(std::array dimensions); +std::string stringFromYogaDimensions(std::array dimensions); std::string stringFromYogaPosition(std::array position); -std::string stringFromYogaEdges(std::array edges); +std::string stringFromYogaEdges(std::array edges); std::string stringFromYogaStyleDirection(YGDirection direction); std::string stringFromYogaStyleFlexDirection(YGFlexDirection value); std::string stringFromYogaStyleJustify(YGJustify value); @@ -52,8 +52,8 @@ std::string stringFromYogaStyleOverflow(YGOverflow value); std::string stringFromYogaStyleDisplay(YGDisplay value); std::string stringFromYogaStyleValue(YGValue value); std::string stringFromYogaStyleOptionalFloat(YGFloatOptional value); -std::string stringFromYogaStyleDimensions(std::array value); -std::string stringFromYogaStyleEdge(std::array value); +std::string stringFromYogaStyleDimensions(std::array value); +std::string stringFromYogaStyleEdges(std::array value); } // namespace react } // namespace facebook