Fabric: Modernizing debug printing in View module

Summary: This is continue of the work started in D7797561.

Reviewed By: fkgozali

Differential Revision: D7901244

fbshipit-source-id: 2f7a5cd9fa8c0079787e26e19c7c6c4255e54b42
This commit is contained in:
Valentin Shergin 2018-05-14 15:43:34 -07:00 committed by Facebook Github Bot
parent f3f378ad3d
commit 2b827c9f13
5 changed files with 91 additions and 53 deletions

View File

@ -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 <fabric/debug/debugStringConvertibleUtils.h>
#include <fabric/view/yogaValuesConversions.h>
// 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<YGValue, YGDimensionCount>;
using YogaEdgesType = std::array<YGValue, YGEdgeCount>;
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

View File

@ -9,6 +9,7 @@
#include <fabric/core/propsConversions.h>
#include <fabric/debug/DebugStringConvertibleItem.h>
#include <fabric/view/debugStringConvertibleUtils.h>
#include <fabric/view/propsConversions.h>
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
@ -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<DebugStringConvertibleItem>(#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

View File

@ -19,8 +19,7 @@ class YogaStylableProps;
typedef std::shared_ptr<const YogaStylableProps> 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

View File

@ -220,7 +220,7 @@ YGFloatOptional yogaStyleOptionalFloatFromDynamic(const folly::dynamic &value) {
abort();
}
std::string stringFromYogaDimensions(std::array<float, 2> dimensions) {
std::string stringFromYogaDimensions(std::array<float, YGDimensionCount> dimensions) {
return "{" + folly::to<std::string>(dimensions[0]) + ", " + folly::to<std::string>(dimensions[1]) + "}";
}
@ -228,7 +228,7 @@ std::string stringFromYogaPosition(std::array<float, 4> position) {
return "{" + folly::to<std::string>(position[0]) + ", " + folly::to<std::string>(position[1]) + "}";
}
std::string stringFromYogaEdges(std::array<float, 6> edges) {
std::string stringFromYogaEdges(std::array<float, YGEdgeCount> edges) {
return "{" +
folly::to<std::string>(edges[0]) + ", " +
folly::to<std::string>(edges[1]) + ", " +
@ -324,18 +324,23 @@ std::string stringFromYogaStyleOptionalFloat(YGFloatOptional value) {
return folly::to<std::string>(fabricFloatFromYogaFloat(value.getValue()));
}
std::string stringFromYogaStyleDimensions(std::array<YGValue, 2> value) {
std::string stringFromYogaStyleDimensions(std::array<YGValue, YGDimensionCount> value) {
return "{" +
stringFromYogaStyleValue(value[0]) + ", " +
stringFromYogaStyleValue(value[1]) + "}";
}
std::string stringFromYogaStyleEdge(std::array<YGValue, YGEdgeCount> value) {
std::string stringFromYogaStyleEdges(std::array<YGValue, YGEdgeCount> 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

View File

@ -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<float, 2> dimensions);
std::string stringFromYogaDimensions(std::array<float, YGDimensionCount> dimensions);
std::string stringFromYogaPosition(std::array<float, 4> position);
std::string stringFromYogaEdges(std::array<float, 6> edges);
std::string stringFromYogaEdges(std::array<float, YGEdgeCount> 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<YGValue, 2> value);
std::string stringFromYogaStyleEdge(std::array<YGValue, YGEdgeCount> value);
std::string stringFromYogaStyleDimensions(std::array<YGValue, YGDimensionCount> value);
std::string stringFromYogaStyleEdges(std::array<YGValue, YGEdgeCount> value);
} // namespace react
} // namespace facebook