Skip to content

Commit

Permalink
Reorder members in Node.h (facebook#41994)
Browse files Browse the repository at this point in the history
Summary:

X-link: facebook/yoga#1529

Reorganizes the header according to common C++ convnetions. Public first, then private. Constructors, then functions, then member variables.

Reviewed By: joevilches

Differential Revision: D52106056
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Dec 19, 2023
1 parent 1cb29f9 commit 30d513e
Showing 1 changed file with 51 additions and 61 deletions.
112 changes: 51 additions & 61 deletions packages/react-native/ReactCommon/yoga/yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,65 +29,9 @@ struct YGNode {};
namespace facebook::yoga {

class YG_EXPORT Node : public ::YGNode {
private:
bool hasNewLayout_ : 1 = true;
bool isReferenceBaseline_ : 1 = false;
bool isDirty_ : 1 = false;
NodeType nodeType_ : bitCount<NodeType>() = NodeType::Default;
void* context_ = nullptr;
YGMeasureFunc measureFunc_ = {nullptr};
YGBaselineFunc baselineFunc_ = {nullptr};
YGPrintFunc printFunc_ = {nullptr};
YGDirtiedFunc dirtiedFunc_ = nullptr;
Style style_ = {};
LayoutResults layout_ = {};
size_t lineIndex_ = 0;
Node* owner_ = nullptr;
std::vector<Node*> children_ = {};
const Config* config_;
std::array<Style::Length, 2> resolvedDimensions_ = {
{value::undefined(), value::undefined()}};

float relativePosition(
FlexDirection axis,
Direction direction,
const float axisSize) const;

Edge getInlineStartEdgeUsingErrata(
FlexDirection flexDirection,
Direction direction) const;
Edge getInlineEndEdgeUsingErrata(
FlexDirection flexDirection,
Direction direction) const;
Edge getFlexStartRelativeEdgeUsingErrata(
FlexDirection flexDirection,
Direction direction) const;
Edge getFlexEndRelativeEdgeUsingErrata(
FlexDirection flexDirection,
Direction direction) const;

void useWebDefaults() {
style_.setFlexDirection(FlexDirection::Row);
style_.setAlignContent(Align::Stretch);
}

template <auto Field>
Style::Length computeEdgeValueForColumn(Edge edge) const;

template <auto Field>
Style::Length computeEdgeValueForRow(Edge rowEdge, Edge edge) const;

// DANGER DANGER DANGER!
// If the node assigned to has children, we'd either have to deallocate
// them (potentially incorrect) or ignore them (danger of leaks). Only ever
// use this after checking that there are no children.
// DO NOT CHANGE THE VISIBILITY OF THIS METHOD!
Node& operator=(Node&&) = default;

public:
Node();
explicit Node(const Config* config);
~Node() = default; // cleanup of owner/children relationships in YGNodeFree

Node(Node&&);

Expand Down Expand Up @@ -181,11 +125,6 @@ class YG_EXPORT Node : public ::YGNode {
return owner_;
}

// Deprecated, use getOwner() instead.
Node* getParent() const {
return getOwner();
}

const std::vector<Node*>& getChildren() const {
return children_;
}
Expand Down Expand Up @@ -393,6 +332,57 @@ class YG_EXPORT Node : public ::YGNode {
float resolveFlexShrink() const;
bool isNodeFlexible();
void reset();

private:
// Used to allow resetting the node
Node& operator=(Node&&) = default;

float relativePosition(
FlexDirection axis,
Direction direction,
const float axisSize) const;

Edge getInlineStartEdgeUsingErrata(
FlexDirection flexDirection,
Direction direction) const;
Edge getInlineEndEdgeUsingErrata(
FlexDirection flexDirection,
Direction direction) const;
Edge getFlexStartRelativeEdgeUsingErrata(
FlexDirection flexDirection,
Direction direction) const;
Edge getFlexEndRelativeEdgeUsingErrata(
FlexDirection flexDirection,
Direction direction) const;

void useWebDefaults() {
style_.setFlexDirection(FlexDirection::Row);
style_.setAlignContent(Align::Stretch);
}

template <auto Field>
Style::Length computeEdgeValueForColumn(Edge edge) const;

template <auto Field>
Style::Length computeEdgeValueForRow(Edge rowEdge, Edge edge) const;

bool hasNewLayout_ : 1 = true;
bool isReferenceBaseline_ : 1 = false;
bool isDirty_ : 1 = false;
NodeType nodeType_ : bitCount<NodeType>() = NodeType::Default;
void* context_ = nullptr;
YGMeasureFunc measureFunc_ = {nullptr};
YGBaselineFunc baselineFunc_ = {nullptr};
YGPrintFunc printFunc_ = {nullptr};
YGDirtiedFunc dirtiedFunc_ = nullptr;
Style style_ = {};
LayoutResults layout_ = {};
size_t lineIndex_ = 0;
Node* owner_ = nullptr;
std::vector<Node*> children_ = {};
const Config* config_;
std::array<Style::Length, 2> resolvedDimensions_ = {
{value::undefined(), value::undefined()}};
};

inline Node* resolveRef(const YGNodeRef ref) {
Expand Down

0 comments on commit 30d513e

Please sign in to comment.