Skip to content

Commit

Permalink
Fabric/View: Debug printing logic in YogaLayoutableShadowNode was mov…
Browse files Browse the repository at this point in the history
…ed to superclass

Summary:
It's more useful and consistent now because:
 - We print compound layout metrics from the correct storage (not from Yoga nodes);
 - It works fro any kind of layout now (but we still have just one);
 - It's much clear and straight-forward.

Reviewed By: fkgozali

Differential Revision: D7607422

fbshipit-source-id: 4c3cd2848e785a7f77c7f591e376d00c7c09ade9
  • Loading branch information
shergin authored and facebook-github-bot committed Apr 27, 2018
1 parent 88c368b commit 98b4747
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 41 deletions.
37 changes: 37 additions & 0 deletions ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <fabric/core/LayoutConstraints.h>
#include <fabric/core/LayoutContext.h>
#include <fabric/core/LayoutMetrics.h>
#include <fabric/debug/DebugStringConvertibleItem.h>
#include <fabric/graphics/graphicValuesConversions.h>

namespace facebook {
namespace react {
Expand Down Expand Up @@ -94,5 +96,40 @@ void LayoutableShadowNode::layoutChildren(LayoutContext layoutContext) {
// Default implementation does nothing.
}

SharedDebugStringConvertibleList LayoutableShadowNode::getDebugProps() const {
SharedDebugStringConvertibleList list = {};

if (getHasNewLayout()) {
list.push_back(std::make_shared<DebugStringConvertibleItem>("hasNewLayout"));
}

if (!getIsLayoutClean()) {
list.push_back(std::make_shared<DebugStringConvertibleItem>("dirty"));
}

LayoutMetrics layoutMetrics = getLayoutMetrics();
LayoutMetrics defaultLayoutMetrics = LayoutMetrics();

list.push_back(std::make_shared<DebugStringConvertibleItem>("frame", stringFromRect(layoutMetrics.frame)));

if (layoutMetrics.borderWidth != defaultLayoutMetrics.borderWidth) {
list.push_back(std::make_shared<DebugStringConvertibleItem>("borderWidth", stringFromEdgeInsets(layoutMetrics.borderWidth)));
}

if (layoutMetrics.contentInsets != defaultLayoutMetrics.contentInsets) {
list.push_back(std::make_shared<DebugStringConvertibleItem>("contentInsets", stringFromEdgeInsets(layoutMetrics.contentInsets)));
}

if (layoutMetrics.displayType == DisplayType::None) {
list.push_back(std::make_shared<DebugStringConvertibleItem>("hidden"));
}

if (layoutMetrics.layoutDirection == LayoutDirection::RightToLeft) {
list.push_back(std::make_shared<DebugStringConvertibleItem>("rtl"));
}

return list;
}

} // namespace react
} // namespace facebook
5 changes: 5 additions & 0 deletions ReactCommon/fabric/core/layout/LayoutableShadowNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <fabric/core/LayoutMetrics.h>
#include <fabric/core/Sealable.h>
#include <fabric/debug/DebugStringConvertible.h>

namespace facebook {
namespace react {
Expand Down Expand Up @@ -102,6 +103,10 @@ class LayoutableShadowNode:
*/
virtual bool setLayoutMetrics(LayoutMetrics layoutMetrics);

#pragma mark - DebugStringConvertible

SharedDebugStringConvertibleList getDebugProps() const;

private:
LayoutMetrics layoutMetrics_ {};
bool hasNewLayout_ {false};
Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/fabric/view/ConcreteViewShadowNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ConcreteViewShadowNode:
auto basePropsList = ShadowNode::getDebugProps();
std::move(basePropsList.begin(), basePropsList.end(), std::back_inserter(list));

list.push_back(std::make_shared<DebugStringConvertibleItem>("layout", "", YogaLayoutableShadowNode::getDebugProps()));
list.push_back(std::make_shared<DebugStringConvertibleItem>("layout", "", LayoutableShadowNode::getDebugProps()));

return list;
}
Expand Down
36 changes: 0 additions & 36 deletions ReactCommon/fabric/view/yoga/YogaLayoutableShadowNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,42 +130,6 @@ void YogaLayoutableShadowNode::layoutChildren(LayoutContext layoutContext) {
}
}

#pragma mark - DebugStringConvertible

SharedDebugStringConvertibleList YogaLayoutableShadowNode::getDebugProps() const {
// TODO: Move to the base class and return `layoutMetrics` instead.

SharedDebugStringConvertibleList list = {};

if (getHasNewLayout()) {
list.push_back(std::make_shared<DebugStringConvertibleItem>("hasNewLayout"));
}

YGLayout defaultYogaLayout = YGLayout();
defaultYogaLayout.direction = YGDirectionLTR;
YGLayout currentYogaLayout = std::const_pointer_cast<YGNode>(yogaNode_)->getLayout();

#define YOGA_LAYOUT_PROPS_ADD_TO_SET(stringName, propertyName, accessor, convertor) \
{ \
auto currentValueString = convertor(currentYogaLayout.propertyName accessor); \
auto defaultValueString = convertor(defaultYogaLayout.propertyName accessor); \
if (currentValueString != defaultValueString) { \
list.push_back(std::make_shared<DebugStringConvertibleItem>(#stringName, currentValueString)); \
} \
}

YOGA_LAYOUT_PROPS_ADD_TO_SET(position, position, , stringFromYogaPosition)
YOGA_LAYOUT_PROPS_ADD_TO_SET(dimensions, dimensions, , stringFromYogaDimensions)
YOGA_LAYOUT_PROPS_ADD_TO_SET(margin, margin, , stringFromYogaEdges)
YOGA_LAYOUT_PROPS_ADD_TO_SET(border, border, , stringFromYogaEdges)
YOGA_LAYOUT_PROPS_ADD_TO_SET(padding, padding, , stringFromYogaEdges)
YOGA_LAYOUT_PROPS_ADD_TO_SET(direction, direction, , stringFromYogaStyleDirection)

return list;
}

#pragma mark - Helpers

#pragma mark - Yoga Connectors

YGNode *YogaLayoutableShadowNode::yogaNodeCloneCallbackConnector(YGNode *oldYogaNode, YGNode *parentYogaNode, int childIndex) {
Expand Down
4 changes: 0 additions & 4 deletions ReactCommon/fabric/view/yoga/YogaLayoutableShadowNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ class YogaLayoutableShadowNode:

void layoutChildren(LayoutContext layoutContext) override;

#pragma mark - DebugStringConvertible

SharedDebugStringConvertibleList getDebugProps() const override;

private:
mutable SharedYogaNode yogaNode_;

Expand Down

0 comments on commit 98b4747

Please sign in to comment.