Skip to content

Commit

Permalink
Expose logging capablities in Yoga header
Browse files Browse the repository at this point in the history
Summary: Exposes a bool in the config which will help log the yoga hierarchy. Also added a test case

Reviewed By: IanChilds

Differential Revision: D9560577

fbshipit-source-id: ef4998107ed51ea374853bab7cbe09e3232caa0c
  • Loading branch information
priteshrnandgaonkar authored and KusStar committed Oct 27, 2020
1 parent 177168f commit 6bb9cce
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
17 changes: 10 additions & 7 deletions ReactCommon/yoga/yoga/YGConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
/*
* Copyright (c) 2014-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.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "YGConfig.h"

const std::array<bool, YGExperimentalFeatureCount>
Expand All @@ -15,5 +15,8 @@ YGConfig::YGConfig(YGLogger logger)
useWebDefaults(false),
useLegacyStretchBehaviour(false),
shouldDiffLayoutWithoutLegacyStretchBehaviour(false),
pointScaleFactor(1.0f), logger(logger), cloneNodeCallback(nullptr),
context(nullptr) {}
pointScaleFactor(1.0f),
logger(logger),
cloneNodeCallback(nullptr),
context(nullptr),
printTree(false) {}
11 changes: 6 additions & 5 deletions ReactCommon/yoga/yoga/YGConfig.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
/*
* Copyright (c) 2014-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.
*
* 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 "Yoga-internal.h"
#include "Yoga.h"
Expand All @@ -18,6 +18,7 @@ struct YGConfig {
YGLogger logger;
YGCloneNodeFunc cloneNodeCallback;
void* context;
bool printTree;

YGConfig(YGLogger logger);
};
9 changes: 6 additions & 3 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ bool YGNodeGetHasNewLayout(YGNodeRef node) {
return node->getHasNewLayout();
}

void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled) {
config->printTree = enabled;
}

void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) {
node->setHasNewLayout(hasNewLayout);
}
Expand Down Expand Up @@ -3480,7 +3484,6 @@ static void YGNodelayoutImpl(
}

uint32_t gDepth = 0;
bool gPrintTree = false;
bool gPrintChanges = false;
bool gPrintSkips = false;

Expand Down Expand Up @@ -4056,7 +4059,7 @@ void YGNodeCalculateLayout(
node->getLayout().direction, ownerWidth, ownerHeight, ownerWidth);
YGRoundToPixelGrid(node, node->getConfig()->pointScaleFactor, 0.0f, 0.0f);

if (gPrintTree) {
if (node->getConfig()->printTree) {
YGNodePrint(
node,
(YGPrintOptions)(
Expand Down Expand Up @@ -4108,7 +4111,7 @@ void YGNodeCalculateLayout(
node->setLayoutDoesLegacyFlagAffectsLayout(
!originalNode->isLayoutTreeEqualToNode(*node));

if (gPrintTree) {
if (originalNode->getConfig()->printTree) {
YGNodePrint(
originalNode,
(YGPrintOptions)(
Expand Down
1 change: 1 addition & 0 deletions ReactCommon/yoga/yoga/Yoga.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ WIN_EXPORT void YGNodeCopyStyle(

void* YGNodeGetContext(YGNodeRef node);
void YGNodeSetContext(YGNodeRef node, void* context);
void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled);
YGMeasureFunc YGNodeGetMeasureFunc(YGNodeRef node);
void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc);
YGBaselineFunc YGNodeGetBaselineFunc(YGNodeRef node);
Expand Down

0 comments on commit 6bb9cce

Please sign in to comment.