Fabric: New nice way to deal with DebugStringConvertible items

Summary:
No macros in product code.
(Not all callsites are converted yet.)

Reviewed By: mdvacca

Differential Revision: D7797561

fbshipit-source-id: da899421bf99669a0e0a2b83df6004daf14355c2
This commit is contained in:
Valentin Shergin
2018-05-08 22:56:02 -07:00
committed by Facebook Github Bot
parent d9ff1769aa
commit 6e537b000b
11 changed files with 198 additions and 60 deletions

View File

@@ -7,8 +7,9 @@
#include "TextAttributes.h"
#include <fabric/debug/DebugStringConvertibleItem.h>
#include <fabric/graphics/debugStringConvertibleUtils.h>
#include <fabric/graphics/graphicValuesConversions.h>
#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<DebugStringConvertibleItem>(#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