Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class SafeAreaViewShadowNode final : public ConcreteViewShadowNode<
public:
static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(
ShadowNodeTraits::Trait::YogaLayoutableKindMutatesStylesAfterCloning);
traits.set(ShadowNodeTraits::Trait::DirtyYogaNode);
return traits;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class TextInputComponentDescriptor final
std::static_pointer_cast<TextInputShadowNode>(shadowNode);

concreteShadowNode->setTextLayoutManager(textLayoutManager_);
concreteShadowNode->dirtyLayout();
concreteShadowNode->enableMeasurement();
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TextInputShadowNode : public ConcreteViewShadowNode<
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::TextKind);
traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
return traits;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
// This is not a default for `YGNode`.
yogaNode_.setDirty(true);

if (getTraits().check(ShadowNodeTraits::Trait::MeasurableYogaNode)) {
assert(getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode));

yogaNode_.setMeasureFunc(
YogaLayoutableShadowNode::yogaNodeMeasureCallbackConnector);
}

updateYogaProps();
updateYogaChildren();

Expand All @@ -73,17 +80,24 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
static_cast<YogaLayoutableShadowNode const &>(sourceShadowNode)
.yogaNode_,
&initializeYogaConfig(yogaConfig_)) {
yogaNode_.setContext(this);
yogaNode_.setOwner(nullptr);
updateYogaChildrenOwnersIfNeeded();
// Note, cloned `YGNode` instance (copied using copy-constructor) inherits
// dirty flag, measure function, and other properties being set originally in
// the `YogaLayoutableShadowNode` constructor above.

// Yoga node must inherit dirty flag.
assert(
static_cast<YogaLayoutableShadowNode const &>(sourceShadowNode)
.yogaNode_.isDirty() == yogaNode_.isDirty());
.yogaNode_.isDirty() == yogaNode_.isDirty() &&
"Yoga node must inherit dirty flag.");

yogaNode_.setContext(this);
yogaNode_.setOwner(nullptr);
updateYogaChildrenOwnersIfNeeded();

if (getTraits().check(ShadowNodeTraits::Trait::
YogaLayoutableKindMutatesStylesAfterCloning)) {
// This is the only legit place where we can dirty cloned Yoga node.
// If we do it later, ancestor nodes will not be able to observe this and
// dirty (and clone) themselves as a result.
if (getTraits().check(ShadowNodeTraits::Trait::DirtyYogaNode) ||
getTraits().check(ShadowNodeTraits::Trait::MeasurableYogaNode)) {
yogaNode_.setDirty(true);
}

Expand Down
15 changes: 9 additions & 6 deletions ReactCommon/react/renderer/core/ShadowNodeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,21 @@ class ShadowNodeTraits {
// Yoga node when a `ShadowNode` is being cloned. `ShadowNode`s that modify
// Yoga styles in the constructor (or later) *after* the `ShadowNode`
// is cloned must set this trait.
YogaLayoutableKindMutatesStylesAfterCloning = 1 << 7,
// Any Yoga node (not only Leaf ones) can have this trait.
DirtyYogaNode = 1 << 9,

// Inherits `YogaLayoutableShadowNode` and enforces that the `YGNode` is a
// leaf.
LeafYogaNode = 1 << 10,

// Inherits `LayoutableShadowNode` and calls `measure()`.
HasMeasure = 1 << 11,
// Inherits `YogaLayoutableShadowNode` and has a custom measure function.
// Only Leaf nodes can have this trait.
MeasurableYogaNode = 1 << 11,

// Indicates that the `ShadowNode` must form a stacking context (a level
// of the hierarchy; `ShadowView`s formed by descendants the node will be
// descendants of a `ShadowView` formed by the node).
// Indicates that the `ShadowNode` must form a stacking context.
// A Stacking Context forms a level of a `ShadowView` hierarchy (in contrast
// with a level of a `ShadowNode` hierarchy).
// See W3C standard for more details: https://www.w3.org/TR/CSS2/zindex.html
FormsStackingContext = 1 << 13,

// Indicates that the node must form a `ShadowView`.
Expand Down