Rename YogaNode.parent -> YogaNode.owner

Reviewed By: priteshrnandgaonkar

Differential Revision: D7352778

fbshipit-source-id: dcf1af5e72bfc3063b5c4bda197d7952a9194768
This commit is contained in:
David Vacca
2018-04-01 18:27:06 -07:00
committed by Facebook Github Bot
parent aff5a75d8e
commit 29ff30c539
11 changed files with 297 additions and 284 deletions

View File

@@ -301,7 +301,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
+ "')");
}
// TODO: T26729293 This is a temporary code that will be replaced as part of T26729293.
YogaNode parent = childYogaNode.getParent();
YogaNode parent = childYogaNode.getOwner();
if (parent != null) {
for (int k = 0; k < parent.getChildCount(); k++) {
if (parent.getChildAt(k) == childYogaNode) {

View File

@@ -29,7 +29,7 @@ public class YogaNode implements Cloneable {
*/
static native int jni_YGNodeGetInstanceCount();
private YogaNode mParent;
private YogaNode mOwner;
private List<YogaNode> mChildren;
private YogaMeasureFunction mMeasureFunction;
private YogaBaselineFunction mBaselineFunction;
@@ -152,7 +152,7 @@ public class YogaNode implements Cloneable {
private native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
public void addChildAt(YogaNode child, int i) {
if (child.mParent != null) {
if (child.mOwner != null) {
throw new IllegalStateException("Child already has a parent, it must be removed first.");
}
@@ -160,7 +160,7 @@ public class YogaNode implements Cloneable {
mChildren = new ArrayList<>(4);
}
mChildren.add(i, child);
child.mParent = this;
child.mOwner = this;
jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i);
}
@@ -180,15 +180,23 @@ public class YogaNode implements Cloneable {
public YogaNode removeChildAt(int i) {
final YogaNode child = mChildren.remove(i);
child.mParent = null;
child.mOwner = null;
jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
return child;
}
/**
* @returns the {@link YogaNode} that owns this {@link YogaNode}.
* The owner is used to identify the YogaTree that a {@link YogaNode} belongs
* to.
* This method will return the parent of the {@link YogaNode} when the
* {@link YogaNode} only belongs to one YogaTree or null when the
* {@link YogaNode} is shared between two or more YogaTrees.
*/
@Nullable
public
YogaNode getParent() {
return mParent;
YogaNode getOwner() {
return mOwner;
}
public int indexOf(YogaNode child) {

View File

@@ -152,7 +152,7 @@ static inline YGConfigRef _jlong2YGConfigRef(jlong addr) {
static YGNodeRef YGJNIOnNodeClonedFunc(
YGNodeRef oldNode,
YGNodeRef parent,
YGNodeRef owner,
int childIndex) {
auto config = oldNode->getConfig();
if (!config) {
@@ -171,7 +171,7 @@ static YGNodeRef YGJNIOnNodeClonedFunc(
auto newNode = onNodeClonedFunc(
javaConfig->get(),
YGNodeJobject(oldNode)->lockLocal(),
YGNodeJobject(parent)->lockLocal(),
YGNodeJobject(owner)->lockLocal(),
childIndex);
static auto replaceChild = findClassStatic("com/facebook/yoga/YogaNode")
@@ -180,7 +180,7 @@ static YGNodeRef YGJNIOnNodeClonedFunc(
jint)>("replaceChild");
jlong newNodeNativePointer = replaceChild(
YGNodeJobject(parent)->lockLocal(),
YGNodeJobject(owner)->lockLocal(),
newNode,
childIndex);

View File

@@ -54,7 +54,7 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
) {
auto yogaNode = std::make_shared<YGNode>(*shadowNode->yogaNode_);
yogaNode->setContext(this);
yogaNode->setParent(nullptr);
yogaNode->setOwner(nullptr);
if (props) {
yogaNode->setStyle(props->getYogaStyle());

View File

@@ -45,7 +45,7 @@ struct YGCollectFlexItemsRowValues {
float remainingFreeSpace;
// The size of the mainDim for the row after considering size, padding, margin
// and border of flex items. This is used to calculate maxLineDim after going
// through all the rows to decide on the main axis size of parent.
// through all the rows to decide on the main axis size of owner.
float mainDim;
// The size of the crossDim for the row after considering size, padding,
// margin and border of flex items. Used for calculating containers crossSize.
@@ -109,7 +109,7 @@ inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) {
flexDirection == YGFlexDirectionRowReverse;
}
inline YGFloatOptional YGResolveValue(const YGValue value, const float parentSize) {
inline YGFloatOptional YGResolveValue(const YGValue value, const float ownerSize) {
switch (value.unit) {
case YGUnitUndefined:
case YGUnitAuto:
@@ -118,7 +118,7 @@ inline YGFloatOptional YGResolveValue(const YGValue value, const float parentSiz
return YGFloatOptional(value.value);
case YGUnitPercent:
return YGFloatOptional(
static_cast<float>(value.value * parentSize * 0.01));
static_cast<float>(value.value * ownerSize * 0.01));
}
return YGFloatOptional();
}
@@ -144,6 +144,6 @@ inline YGFlexDirection YGResolveFlexDirection(
static inline float YGResolveValueMargin(
const YGValue value,
const float parentSize) {
return value.unit == YGUnitAuto ? 0 : YGUnwrapFloatOptional(YGResolveValue(value, parentSize));
const float ownerSize) {
return value.unit == YGUnitAuto ? 0 : YGUnwrapFloatOptional(YGResolveValue(value, ownerSize));
}

View File

@@ -22,7 +22,7 @@ YGLayout::YGLayout()
computedFlexBasis(YGUndefined),
hadOverflow(false),
generationCount(0),
lastParentDirection((YGDirection)-1),
lastOwnerDirection((YGDirection)-1),
nextCachedMeasurementsIndex(0),
cachedMeasurements(),
measuredDimensions(kYGDefaultDimensionValues),
@@ -37,7 +37,7 @@ bool YGLayout::operator==(YGLayout layout) const {
YGFloatArrayEqual(border, layout.border) &&
YGFloatArrayEqual(padding, layout.padding) &&
direction == layout.direction && hadOverflow == layout.hadOverflow &&
lastParentDirection == layout.lastParentDirection &&
lastOwnerDirection == layout.lastOwnerDirection &&
nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex &&
cachedLayout == layout.cachedLayout;

View File

@@ -23,7 +23,7 @@ struct YGLayout {
// Instead of recomputing the entire layout every single time, we
// cache some information to break early when nothing changed
uint32_t generationCount;
YGDirection lastParentDirection;
YGDirection lastOwnerDirection;
uint32_t nextCachedMeasurementsIndex;
std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT>

View File

@@ -49,8 +49,8 @@ uint32_t YGNode::getLineIndex() const {
return lineIndex_;
}
YGNodeRef YGNode::getParent() const {
return parent_;
YGNodeRef YGNode::getOwner() const {
return owner_;
}
YGVector YGNode::getChildren() const {
@@ -237,8 +237,8 @@ void YGNode::setLineIndex(uint32_t lineIndex) {
lineIndex_ = lineIndex;
}
void YGNode::setParent(YGNodeRef parent) {
parent_ = parent;
void YGNode::setOwner(YGNodeRef owner) {
owner_ = owner;
}
void YGNode::setChildren(const YGVector& children) {
@@ -305,8 +305,8 @@ void YGNode::setLayoutPadding(float padding, int index) {
layout_.padding[index] = padding;
}
void YGNode::setLayoutLastParentDirection(YGDirection direction) {
layout_.lastParentDirection = direction;
void YGNode::setLayoutLastOwnerDirection(YGDirection direction) {
layout_.lastOwnerDirection = direction;
}
void YGNode::setLayoutComputedFlexBasis(float computedFlexBasis) {
@@ -347,11 +347,11 @@ void YGNode::setPosition(
const YGDirection direction,
const float mainSize,
const float crossSize,
const float parentWidth) {
const float ownerWidth) {
/* Root nodes should be always layouted as LTR, so we don't return negative
* values. */
const YGDirection directionRespectingRoot =
parent_ != nullptr ? direction : YGDirectionLTR;
owner_ != nullptr ? direction : YGDirectionLTR;
const YGFlexDirection mainAxis =
YGResolveFlexDirection(style_.flexDirection, directionRespectingRoot);
const YGFlexDirection crossAxis =
@@ -361,16 +361,16 @@ void YGNode::setPosition(
const float relativePositionCross = relativePosition(crossAxis, crossSize);
setLayoutPosition(
getLeadingMargin(mainAxis, parentWidth) + relativePositionMain,
getLeadingMargin(mainAxis, ownerWidth) + relativePositionMain,
leading[mainAxis]);
setLayoutPosition(
getTrailingMargin(mainAxis, parentWidth) + relativePositionMain,
getTrailingMargin(mainAxis, ownerWidth) + relativePositionMain,
trailing[mainAxis]);
setLayoutPosition(
getLeadingMargin(crossAxis, parentWidth) + relativePositionCross,
getLeadingMargin(crossAxis, ownerWidth) + relativePositionCross,
leading[crossAxis]);
setLayoutPosition(
getTrailingMargin(crossAxis, parentWidth) + relativePositionCross,
getTrailingMargin(crossAxis, ownerWidth) + relativePositionCross,
trailing[crossAxis]);
}
@@ -385,7 +385,7 @@ YGNode::YGNode()
style_(YGStyle()),
layout_(YGLayout()),
lineIndex_(0),
parent_(nullptr),
owner_(nullptr),
children_(YGVector()),
nextChild_(nullptr),
config_(nullptr),
@@ -403,7 +403,7 @@ YGNode::YGNode(const YGNode& node)
style_(node.style_),
layout_(node.layout_),
lineIndex_(node.lineIndex_),
parent_(node.parent_),
owner_(node.owner_),
children_(node.children_),
nextChild_(node.nextChild_),
config_(node.config_),
@@ -425,7 +425,7 @@ YGNode::YGNode(
YGStyle style,
const YGLayout& layout,
uint32_t lineIndex,
YGNodeRef parent,
YGNodeRef owner,
const YGVector& children,
YGNodeRef nextChild,
YGConfigRef config,
@@ -441,7 +441,7 @@ YGNode::YGNode(
style_(style),
layout_(layout),
lineIndex_(lineIndex),
parent_(parent),
owner_(owner),
children_(children),
nextChild_(nextChild),
config_(config),
@@ -467,7 +467,7 @@ YGNode& YGNode::operator=(const YGNode& node) {
style_ = node.style_;
layout_ = node.layout_;
lineIndex_ = node.getLineIndex();
parent_ = node.getParent();
owner_ = node.getOwner();
children_ = node.getChildren();
nextChild_ = node.getNextChild();
config_ = node.getConfig();
@@ -518,9 +518,9 @@ void YGNode::resolveDimension() {
}
}
YGDirection YGNode::resolveDirection(const YGDirection parentDirection) {
YGDirection YGNode::resolveDirection(const YGDirection ownerDirection) {
if (style_.direction == YGDirectionInherit) {
return parentDirection > YGDirectionInherit ? parentDirection
return ownerDirection > YGDirectionInherit ? ownerDirection
: YGDirectionLTR;
} else {
return style_.direction;
@@ -550,10 +550,10 @@ void YGNode::cloneChildrenIfNeeded() {
}
const YGNodeRef firstChild = children_.front();
if (firstChild->getParent() == this) {
// If the first child has this node as its parent, we assume that it is
if (firstChild->getOwner() == this) {
// If the first child has this node as its owner, we assume that it is
// already unique. We can do this because if we have it has a child, that
// means that its parent was at some point cloned which made that subtree
// means that its owner was at some point cloned which made that subtree
// immutable. We also assume that all its sibling are cloned as well.
return;
}
@@ -569,7 +569,7 @@ void YGNode::cloneChildrenIfNeeded() {
newChild = YGNodeClone(oldChild);
}
replaceChild(newChild, i);
newChild->setParent(this);
newChild->setOwner(this);
}
}
@@ -577,8 +577,8 @@ void YGNode::markDirtyAndPropogate() {
if (!isDirty_) {
setDirty(true);
setLayoutComputedFlexBasis(YGUndefined);
if (parent_) {
parent_->markDirtyAndPropogate();
if (owner_) {
owner_->markDirtyAndPropogate();
}
}
}
@@ -592,7 +592,7 @@ void YGNode::markDirtyAndPropogateDownwards() {
float YGNode::resolveFlexGrow() {
// Root nodes flexGrow should always be 0
if (parent_ == nullptr) {
if (owner_ == nullptr) {
return 0.0;
}
if (!style_.flexGrow.isUndefined()) {
@@ -605,7 +605,7 @@ float YGNode::resolveFlexGrow() {
}
float YGNode::resolveFlexShrink() {
if (parent_ == nullptr) {
if (owner_ == nullptr) {
return 0.0;
}
if (!style_.flexShrink.isUndefined()) {

View File

@@ -23,7 +23,7 @@ struct YGNode {
YGStyle style_;
YGLayout layout_;
uint32_t lineIndex_;
YGNodeRef parent_;
YGNodeRef owner_;
YGVector children_;
YGNodeRef nextChild_;
YGConfigRef config_;
@@ -49,7 +49,7 @@ struct YGNode {
YGStyle style,
const YGLayout& layout,
uint32_t lineIndex,
YGNodeRef parent,
YGNodeRef owner,
const YGVector& children,
YGNodeRef nextChild,
YGConfigRef config,
@@ -69,7 +69,12 @@ struct YGNode {
// For Performance reasons passing as reference.
YGLayout& getLayout();
uint32_t getLineIndex() const;
YGNodeRef getParent() const;
// returns the YGNodeRef that owns this YGNode. An owner is used to identify
// the YogaTree that a YGNode belongs to.
// This method will return the parent of the YGNode when a YGNode only belongs
// to one YogaTree or nullptr when the YGNode is shared between two or more
// YogaTrees.
YGNodeRef getOwner() const;
YGVector getChildren() const;
uint32_t getChildrenCount() const;
YGNodeRef getChild(uint32_t index) const;
@@ -111,12 +116,12 @@ struct YGNode {
void setStyleAlignContent(YGAlign alignContent);
void setLayout(const YGLayout& layout);
void setLineIndex(uint32_t lineIndex);
void setParent(YGNodeRef parent);
void setOwner(YGNodeRef owner);
void setChildren(const YGVector& children);
void setNextChild(YGNodeRef nextChild);
void setConfig(YGConfigRef config);
void setDirty(bool isDirty);
void setLayoutLastParentDirection(YGDirection direction);
void setLayoutLastOwnerDirection(YGDirection direction);
void setLayoutComputedFlexBasis(float computedFlexBasis);
void setLayoutComputedFlexBasisGeneration(
uint32_t computedFlexBasisGeneration);
@@ -132,7 +137,7 @@ struct YGNode {
const YGDirection direction,
const float mainSize,
const float crossSize,
const float parentWidth);
const float ownerWidth);
void setAndPropogateUseLegacyFlag(bool useLegacyFlag);
void setLayoutDoesLegacyFlagAffectsLayout(bool doesLegacyFlagAffectsLayout);
void setLayoutDidUseLegacyFlag(bool didUseLegacyFlag);
@@ -143,7 +148,7 @@ struct YGNode {
YGValue marginTrailingValue(const YGFlexDirection axis) const;
YGValue resolveFlexBasisPtr() const;
void resolveDimension();
YGDirection resolveDirection(const YGDirection parentDirection);
YGDirection resolveDirection(const YGDirection ownerDirection);
void clearChildren();
/// Replaces the occurrences of oldChild with newChild
void replaceChild(YGNodeRef oldChild, YGNodeRef newChild);

File diff suppressed because it is too large Load Diff

View File

@@ -81,14 +81,14 @@ WIN_EXPORT void YGNodeInsertChild(const YGNodeRef node,
WIN_EXPORT void YGNodeRemoveChild(const YGNodeRef node, const YGNodeRef child);
WIN_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef node);
WIN_EXPORT YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index);
WIN_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node);
WIN_EXPORT YGNodeRef YGNodeGetOwner(const YGNodeRef node);
WIN_EXPORT uint32_t YGNodeGetChildCount(const YGNodeRef node);
WIN_EXPORT void YGNodeSetChildren(YGNodeRef const parent, const YGNodeRef children[], const uint32_t count);
WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node,
const float availableWidth,
const float availableHeight,
const YGDirection parentDirection);
const YGDirection ownerDirection);
// Mark a node as dirty. Only valid for nodes with a custom measure function
// set.