diff --git a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp index 5cd3b412e2c..f625e146786 100644 --- a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp +++ b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp @@ -6,11 +6,6 @@ */ #include "YogaLayoutableShadowNode.h" - -#include -#include -#include - #include #include #include @@ -18,6 +13,9 @@ #include #include #include +#include +#include +#include namespace facebook { namespace react { @@ -396,10 +394,29 @@ YGSize YogaLayoutableShadowNode::yogaNodeMeasureCallbackConnector( yogaFloatFromFloat(size.height)}; } +#ifdef RN_DEBUG_YOGA_LOGGER +static int YogaLog( + const YGConfigRef config, + const YGNodeRef node, + YGLogLevel level, + const char *format, + va_list args) { + int result = vsnprintf(NULL, 0, format, args); + std::vector buffer(1 + result); + vsnprintf(buffer.data(), buffer.size(), format, args); + LOG(INFO) << "RNYogaLogger " << buffer.data(); + return result; +} +#endif + YGConfig &YogaLayoutableShadowNode::initializeYogaConfig(YGConfig &config) { config.setCloneNodeCallback( YogaLayoutableShadowNode::yogaNodeCloneCallbackConnector); config.useLegacyStretchBehaviour = true; +#ifdef RN_DEBUG_YOGA_LOGGER + config.printTree = true; + config.setLogger(&YogaLog); +#endif return config; } diff --git a/ReactCommon/fabric/debug/DebugStringConvertible.h b/ReactCommon/fabric/debug/DebugStringConvertible.h index f50d9be071e..a71077193cb 100644 --- a/ReactCommon/fabric/debug/DebugStringConvertible.h +++ b/ReactCommon/fabric/debug/DebugStringConvertible.h @@ -20,6 +20,12 @@ namespace react { #define RN_DEBUG_STRING_CONVERTIBLE 1 #endif +// To Debug Yoga layout, uncomment the following line. +// #define RN_DEBUG_YOGA_LOGGER 1 +// +// Additional logging can be enabled editing yoga.cpp (e.g. gPrintChanges, +// gPrintSkips) + #if RN_DEBUG_STRING_CONVERTIBLE class DebugStringConvertible;