Skip to content

Commit

Permalink
Moved out logic to calculate size consumed on a line into seperate fu…
Browse files Browse the repository at this point in the history
…nction

Reviewed By: emilsjolander

Differential Revision: D6797640

fbshipit-source-id: ad9757e7d603c0ce57f452b1e5c404037605bed9
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Feb 5, 2018
1 parent 8235a49 commit 34b7ec8
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 109 deletions.
35 changes: 35 additions & 0 deletions ReactCommon/yoga/yoga/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,41 @@
#include "YGNode.h"
#include "Yoga-internal.h"

// This struct is an helper model to hold the data for step 4 of flexbox
// algo, which is collecting the flex items in a line.
//
// - itemsOnLine: Number of items which can fit in a line considering the
// available Inner dimension, the flex items computed flexbasis and their
// margin. It may be different than the difference between start and end
// indicates because we skip over absolute-positioned items.
//
// - sizeConsumedOnCurrentLine: It is accumulation of the dimensions and margin
// of all the children on the current line. This will be used in order to either
// set the dimensions of the node if none already exist or to compute the
// remaining space left for the flexible children.
//
// - totalFlexGrowFactors: total flex grow factors of flex items which are to be
// layed in the current line
//
// - totalFlexShrinkFactors: total flex shrink factors of flex items which are
// to be layed in the current line
//
// - endOfLineIndex: Its the end index of the last flex item which was examined
// and it may or may not be part of the current line(as it may be absolutely
// positioned or inculding it may have caused to overshoot availableInnerDim)
//
// - relativeChildren: Maintain a vector of the child nodes that can shrink
// and/or grow.

struct YGCollectFlexItemsRowValues {
uint32_t itemsOnLine;
float sizeConsumedOnCurrentLine;
float totalFlexGrowFactors;
float totalFlexShrinkScaledFactors;
float endOfLineIndex;
std::vector<YGNodeRef> relativeChildren;
};

bool YGValueEqual(const YGValue a, const YGValue b);

YGFlexDirection YGFlexDirectionCross(
Expand Down
4 changes: 4 additions & 0 deletions ReactCommon/yoga/yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ YGVector YGNode::getChildren() const {
return children_;
}

uint32_t YGNode::getChildrenCount() const {
return static_cast<uint32_t>(children_.size());
}

YGNodeRef YGNode::getChild(uint32_t index) const {
return children_.at(index);
}
Expand Down
1 change: 1 addition & 0 deletions ReactCommon/yoga/yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct YGNode {
uint32_t getLineIndex() const;
YGNodeRef getParent() const;
YGVector getChildren() const;
uint32_t getChildrenCount() const;
YGNodeRef getChild(uint32_t index) const;
YGNodeRef getNextChild() const;
YGConfigRef getConfig() const;
Expand Down
Loading

0 comments on commit 34b7ec8

Please sign in to comment.