Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete traitCast and identifier traits #42748

Closed
wants to merge 2 commits into from
Closed
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 @@ -154,7 +154,6 @@ add_executable(reactnative_unittest
${REACT_COMMON_DIR}/react/renderer/core/tests/PrimitivesTest.cpp
${REACT_COMMON_DIR}/react/renderer/core/tests/RawPropsTest.cpp
${REACT_COMMON_DIR}/react/renderer/core/tests/ShadowNodeFamilyTest.cpp
${REACT_COMMON_DIR}/react/renderer/core/tests/traitCastTest.cpp
${REACT_COMMON_DIR}/react/renderer/debug/tests/DebugStringConvertibleTest.cpp
${REACT_COMMON_DIR}/react/renderer/element/tests/ElementTest.cpp
${REACT_COMMON_DIR}/react/renderer/graphics/tests/GraphicsTest.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <react/renderer/components/text/RawTextShadowNode.h>
#include <react/renderer/components/text/TextProps.h>
#include <react/renderer/components/text/TextShadowNode.h>
#include <react/renderer/core/TraitCast.h>
#include <react/renderer/mounting/ShadowView.h>

namespace facebook::react {
Expand All @@ -33,7 +32,7 @@ void BaseTextShadowNode::buildAttributedString(
for (const auto& childNode : parentNode.getChildren()) {
// RawShadowNode
auto rawTextShadowNode =
traitCast<const RawTextShadowNode*>(childNode.get());
dynamic_cast<const RawTextShadowNode*>(childNode.get());
if (rawTextShadowNode != nullptr) {
auto fragment = AttributedString::Fragment{};
fragment.string = rawTextShadowNode->getConcreteProps().text;
Expand All @@ -49,7 +48,7 @@ void BaseTextShadowNode::buildAttributedString(
}

// TextShadowNode
auto textShadowNode = traitCast<const TextShadowNode*>(childNode.get());
auto textShadowNode = dynamic_cast<const TextShadowNode*>(childNode.get());
if (textShadowNode != nullptr) {
auto localTextAttributes = baseTextAttributes;
localTextAttributes.apply(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <react/renderer/attributedstring/AttributedStringBox.h>
#include <react/renderer/components/view/ViewShadowNode.h>
#include <react/renderer/components/view/conversions.h>
#include <react/renderer/core/TraitCast.h>
#include <react/renderer/graphics/rounding.h>
#include <react/renderer/telemetry/TransactionTelemetry.h>
#include <react/renderer/textlayoutmanager/TextLayoutContext.h>
Expand All @@ -31,7 +30,7 @@ ParagraphShadowNode::ParagraphShadowNode(
const ShadowNodeFragment& fragment)
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
auto& sourceParagraphShadowNode =
traitCast<ParagraphShadowNode const&>(sourceShadowNode);
dynamic_cast<const ParagraphShadowNode&>(sourceShadowNode);
if (!fragment.children && !fragment.props &&
sourceParagraphShadowNode.getIsLayoutClean()) {
// This ParagraphShadowNode was cloned but did not change
Expand Down Expand Up @@ -84,7 +83,7 @@ Content ParagraphShadowNode::getContentWithMeasuredAttachments(

for (const auto& attachment : content.attachments) {
auto laytableShadowNode =
traitCast<const LayoutableShadowNode*>(attachment.shadowNode);
dynamic_cast<const LayoutableShadowNode*>(attachment.shadowNode);

if (laytableShadowNode == nullptr) {
continue;
Expand Down Expand Up @@ -213,7 +212,7 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
for (size_t i = 0; i < content.attachments.size(); i++) {
auto& attachment = content.attachments.at(i);

if (traitCast<const LayoutableShadowNode*>(attachment.shadowNode) ==
if (dynamic_cast<const LayoutableShadowNode*>(attachment.shadowNode) ==
nullptr) {
// Not a layoutable `ShadowNode`, no need to lay it out.
continue;
Expand All @@ -231,7 +230,7 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
static_cast<ParagraphShadowNode*>(paragraphOwningShadowNode.get());

auto& layoutableShadowNode =
traitCast<LayoutableShadowNode&>(*clonedShadowNode);
dynamic_cast<LayoutableShadowNode&>(*clonedShadowNode);

auto attachmentFrame = measurement.attachments[i].frame;
auto attachmentSize = roundToPixel<&ceil>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class ParagraphShadowNode final : public ConcreteViewShadowNode<
static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
traits.set(ShadowNodeTraits::Trait::TextKind);
traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);

#ifdef ANDROID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ class RawTextShadowNode : public ConcreteShadowNode<
public:
using ConcreteShadowNode::ConcreteShadowNode;
static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteShadowNode::BaseTraits();
traits.set(IdentifierTrait());
return traits;
}
static ShadowNodeTraits::Trait IdentifierTrait() {
return ShadowNodeTraits::Trait::RawText;
return ConcreteShadowNode::BaseTraits();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,12 @@ class TextShadowNode : public ConcreteShadowNode<
public:
static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteShadowNode::BaseTraits();

#ifdef ANDROID
traits.set(ShadowNodeTraits::Trait::FormsView);
#endif
traits.set(IdentifierTrait());

return traits;
}

static ShadowNodeTraits::Trait IdentifierTrait() {
return ShadowNodeTraits::Trait::Text;
}

using ConcreteShadowNode::ConcreteShadowNode;

#ifdef ANDROID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class AndroidTextInputShadowNode final : public ConcreteViewShadowNode<
public:
static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::TextKind);
traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
return traits;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class TextInputShadowNode final : public ConcreteViewShadowNode<

static ShadowNodeTraits BaseTraits() {
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 @@ -35,9 +35,7 @@ class ViewShadowNode final : public ConcreteViewShadowNode<
ViewEventEmitter> {
public:
static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::View);
return traits;
return ConcreteViewShadowNode::BaseTraits();
}

ViewShadowNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <react/renderer/components/view/conversions.h>
#include <react/renderer/core/LayoutConstraints.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/core/TraitCast.h>
#include <react/renderer/debug/DebugStringConvertibleItem.h>
#include <react/renderer/debug/SystraceSection.h>
#include <react/utils/CoreFeatures.h>
Expand Down Expand Up @@ -63,13 +62,7 @@ static int FabricDefaultYogaLog(
thread_local LayoutContext threadLocalLayoutContext;

ShadowNodeTraits YogaLayoutableShadowNode::BaseTraits() {
auto traits = LayoutableShadowNode::BaseTraits();
traits.set(IdentifierTrait());
return traits;
}

ShadowNodeTraits::Trait YogaLayoutableShadowNode::IdentifierTrait() {
return ShadowNodeTraits::Trait::YogaLayoutableKind;
return LayoutableShadowNode::BaseTraits();
}

YogaLayoutableShadowNode::YogaLayoutableShadowNode(
Expand Down Expand Up @@ -123,8 +116,10 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(

if (!getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) {
for (auto& child : getChildren()) {
if (auto layoutableChild = traitCast<YogaLayoutableShadowNode>(child)) {
yogaLayoutableChildren_.push_back(layoutableChild);
if (auto layoutableChild =
std::dynamic_pointer_cast<const YogaLayoutableShadowNode>(
child)) {
yogaLayoutableChildren_.push_back(std::move(layoutableChild));
}
}
}
Expand Down Expand Up @@ -210,7 +205,7 @@ void YogaLayoutableShadowNode::adoptYogaChild(size_t index) {
!getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode));

auto& childNode =
traitCast<const YogaLayoutableShadowNode&>(*getChildren().at(index));
dynamic_cast<const YogaLayoutableShadowNode&>(*getChildren().at(index));

if (childNode.yogaNode_.getOwner() == nullptr) {
// The child node is not owned.
Expand Down Expand Up @@ -243,7 +238,8 @@ void YogaLayoutableShadowNode::appendChild(
}

if (auto yogaLayoutableChild =
traitCast<YogaLayoutableShadowNode>(childNode)) {
std::dynamic_pointer_cast<const YogaLayoutableShadowNode>(
childNode)) {
// Here we don't have information about the previous structure of the node
// (if it that existed before), so we don't have anything to compare the
// Yoga node with (like a previous version of this node). Therefore we must
Expand Down Expand Up @@ -273,8 +269,9 @@ void YogaLayoutableShadowNode::replaceChild(
ensureYogaChildrenLookFine();

auto layoutableOldChild =
traitCast<const YogaLayoutableShadowNode*>(&oldChild);
auto layoutableNewChild = traitCast<YogaLayoutableShadowNode>(newChild);
dynamic_cast<const YogaLayoutableShadowNode*>(&oldChild);
auto layoutableNewChild =
std::dynamic_pointer_cast<const YogaLayoutableShadowNode>(newChild);

if (layoutableOldChild == nullptr && layoutableNewChild == nullptr) {
// No need to mutate yogaLayoutableChildren_
Expand Down Expand Up @@ -349,7 +346,8 @@ void YogaLayoutableShadowNode::updateYogaChildren() {

for (size_t i = 0; i < getChildren().size(); i++) {
if (auto yogaLayoutableChild =
traitCast<YogaLayoutableShadowNode>(getChildren()[i])) {
std::dynamic_pointer_cast<const YogaLayoutableShadowNode>(
getChildren()[i])) {
appendYogaChild(yogaLayoutableChild);
adoptYogaChild(i);

Expand Down Expand Up @@ -496,7 +494,7 @@ void YogaLayoutableShadowNode::configureYogaTree(
}

YGErrata YogaLayoutableShadowNode::resolveErrata(YGErrata defaultErrata) const {
if (auto viewShadowNode = traitCast<const ViewShadowNode*>(this)) {
if (auto viewShadowNode = dynamic_cast<const ViewShadowNode*>(this)) {
const auto& props = viewShadowNode->getConcreteProps();
switch (props.experimental_layoutConformance) {
case LayoutConformance::Classic:
Expand Down Expand Up @@ -745,7 +743,7 @@ Rect YogaLayoutableShadowNode::getContentBounds() const {

auto layoutMetricsWithOverflowInset = childNode.getLayoutMetrics();
if (layoutMetricsWithOverflowInset.displayType != DisplayType::None) {
auto viewChildNode = traitCast<const ViewShadowNode*>(&childNode);
auto viewChildNode = dynamic_cast<const ViewShadowNode*>(&childNode);
auto hitSlop = viewChildNode != nullptr
? viewChildNode->getConcreteProps().hitSlop
: EdgeInsets{};
Expand Down Expand Up @@ -837,7 +835,7 @@ YGSize YogaLayoutableShadowNode::yogaNodeMeasureCallbackConnector(

YogaLayoutableShadowNode& YogaLayoutableShadowNode::shadowNodeFromContext(
YGNodeConstRef yogaNode) {
return traitCast<YogaLayoutableShadowNode&>(
return dynamic_cast<YogaLayoutableShadowNode&>(
*static_cast<ShadowNode*>(YGNodeGetContext(yogaNode)));
}

Expand All @@ -863,13 +861,12 @@ yoga::Config& YogaLayoutableShadowNode::initializeYogaConfig(
void YogaLayoutableShadowNode::swapStyleLeftAndRight() {
ensureUnsealed();

swapLeftAndRightInYogaStyleProps(*this);
swapLeftAndRightInViewProps(*this);
swapLeftAndRightInYogaStyleProps();
swapLeftAndRightInViewProps();
}

void YogaLayoutableShadowNode::swapLeftAndRightInYogaStyleProps(
const YogaLayoutableShadowNode& shadowNode) {
auto yogaStyle = shadowNode.yogaNode_.style();
void YogaLayoutableShadowNode::swapLeftAndRightInYogaStyleProps() {
auto yogaStyle = yogaNode_.style();

// Swap Yoga node values, position, padding and margin.

Expand Down Expand Up @@ -906,66 +903,65 @@ void YogaLayoutableShadowNode::swapLeftAndRightInYogaStyleProps(
yogaStyle.setMargin(yoga::Edge::Right, yoga::value::undefined());
}

shadowNode.yogaNode_.setStyle(yogaStyle);
}

void YogaLayoutableShadowNode::swapLeftAndRightInViewProps(
const YogaLayoutableShadowNode& shadowNode) {
auto& typedCasting = static_cast<const ViewProps&>(*shadowNode.props_);
auto& props = const_cast<ViewProps&>(typedCasting);

// Swap border node values, borderRadii, borderColors and borderStyles.

if (props.borderRadii.topLeft.has_value()) {
props.borderRadii.topStart = props.borderRadii.topLeft;
props.borderRadii.topLeft.reset();
if (yogaStyle.border(yoga::Edge::Left).isDefined()) {
yogaStyle.setBorder(yoga::Edge::Start, yogaStyle.border(yoga::Edge::Left));
yogaStyle.setBorder(yoga::Edge::Left, yoga::value::undefined());
}

if (props.borderRadii.bottomLeft.has_value()) {
props.borderRadii.bottomStart = props.borderRadii.bottomLeft;
props.borderRadii.bottomLeft.reset();
if (yogaStyle.border(yoga::Edge::Right).isDefined()) {
yogaStyle.setBorder(yoga::Edge::End, yogaStyle.border(yoga::Edge::Right));
yogaStyle.setBorder(yoga::Edge::Right, yoga::value::undefined());
}

if (props.borderRadii.topRight.has_value()) {
props.borderRadii.topEnd = props.borderRadii.topRight;
props.borderRadii.topRight.reset();
}
yogaNode_.setStyle(yogaStyle);
}

if (props.borderRadii.bottomRight.has_value()) {
props.borderRadii.bottomEnd = props.borderRadii.bottomRight;
props.borderRadii.bottomRight.reset();
}
void YogaLayoutableShadowNode::swapLeftAndRightInViewProps() {
if (auto viewShadowNode = dynamic_cast<ViewShadowNode*>(this)) {
// TODO: Do not mutate props directly.
auto& props =
const_cast<ViewShadowNodeProps&>(viewShadowNode->getConcreteProps());

if (props.borderColors.left.has_value()) {
props.borderColors.start = props.borderColors.left;
props.borderColors.left.reset();
}
// Swap border node values, borderRadii, borderColors and borderStyles.
if (props.borderRadii.topLeft.has_value()) {
props.borderRadii.topStart = props.borderRadii.topLeft;
props.borderRadii.topLeft.reset();
}

if (props.borderColors.right.has_value()) {
props.borderColors.end = props.borderColors.right;
props.borderColors.right.reset();
}
if (props.borderRadii.bottomLeft.has_value()) {
props.borderRadii.bottomStart = props.borderRadii.bottomLeft;
props.borderRadii.bottomLeft.reset();
}

if (props.borderStyles.left.has_value()) {
props.borderStyles.start = props.borderStyles.left;
props.borderStyles.left.reset();
}
if (props.borderRadii.topRight.has_value()) {
props.borderRadii.topEnd = props.borderRadii.topRight;
props.borderRadii.topRight.reset();
}

if (props.borderStyles.right.has_value()) {
props.borderStyles.end = props.borderStyles.right;
props.borderStyles.right.reset();
}
if (props.borderRadii.bottomRight.has_value()) {
props.borderRadii.bottomEnd = props.borderRadii.bottomRight;
props.borderRadii.bottomRight.reset();
}

if (props.yogaStyle.border(yoga::Edge::Left).isDefined()) {
props.yogaStyle.setBorder(
yoga::Edge::Start, props.yogaStyle.border(yoga::Edge::Left));
props.yogaStyle.setBorder(yoga::Edge::Left, yoga::value::undefined());
}
if (props.borderColors.left.has_value()) {
props.borderColors.start = props.borderColors.left;
props.borderColors.left.reset();
}

if (props.borderColors.right.has_value()) {
props.borderColors.end = props.borderColors.right;
props.borderColors.right.reset();
}

if (props.yogaStyle.border(yoga::Edge::Right).isDefined()) {
props.yogaStyle.setBorder(
yoga::Edge::End, props.yogaStyle.border(yoga::Edge::Right));
props.yogaStyle.setBorder(yoga::Edge::Right, yoga::value::undefined());
if (props.borderStyles.left.has_value()) {
props.borderStyles.start = props.borderStyles.left;
props.borderStyles.left.reset();
}

if (props.borderStyles.right.has_value()) {
props.borderStyles.end = props.borderStyles.right;
props.borderStyles.right.reset();
}
}
}

Expand Down Expand Up @@ -1016,7 +1012,7 @@ void YogaLayoutableShadowNode::ensureYogaChildrenAlignment() const {
auto& child = children.at(i);
react_native_assert(
yogaChild->getContext() ==
traitCast<const YogaLayoutableShadowNode*>(child.get()));
dynamic_cast<const YogaLayoutableShadowNode*>(child.get()));
}
#endif
}
Expand Down
Loading
Loading