Fabric/View: Debug printing logic in YogaLayoutableShadowNode was moved 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
This commit is contained in:
parent
88c368b488
commit
98b4747041
|
@ -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 {
|
||||
|
@ -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
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <fabric/core/LayoutMetrics.h>
|
||||
#include <fabric/core/Sealable.h>
|
||||
#include <fabric/debug/DebugStringConvertible.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
@ -102,6 +103,10 @@ protected:
|
|||
*/
|
||||
virtual bool setLayoutMetrics(LayoutMetrics layoutMetrics);
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
||||
SharedDebugStringConvertibleList getDebugProps() const;
|
||||
|
||||
private:
|
||||
LayoutMetrics layoutMetrics_ {};
|
||||
bool hasNewLayout_ {false};
|
||||
|
|
|
@ -138,7 +138,7 @@ public:
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -76,10 +76,6 @@ public:
|
|||
|
||||
void layoutChildren(LayoutContext layoutContext) override;
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
||||
SharedDebugStringConvertibleList getDebugProps() const override;
|
||||
|
||||
private:
|
||||
mutable SharedYogaNode yogaNode_;
|
||||
|
||||
|
|
Loading…
Reference in New Issue