From cea3865c74634359b5bf9504353a2e90e304855a Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Wed, 29 May 2019 07:38:12 -0700 Subject: [PATCH] Deprecate `YGNode::setConfig` Summary: We want to phase out usage of config pointers on nodes. Setting configs is no longer needed, as a config is unly used during construction. Here we deprecate the setter, as it is no longer working as it used to (e.g. changing `useWebDefaults` after a node is constructed). Reviewed By: SidharthGuglani Differential Revision: D15416474 fbshipit-source-id: a2cc06cad0c5148cecce056ece5f141b3defe9a9 --- yoga/YGMacros.h | 12 ++++++++++++ yoga/YGNode.h | 3 ++- yoga/Yoga.cpp | 12 +++++++----- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/yoga/YGMacros.h b/yoga/YGMacros.h index 9c2989ac..badea8c3 100644 --- a/yoga/YGMacros.h +++ b/yoga/YGMacros.h @@ -30,3 +30,15 @@ #define YG_ENUM_BEGIN(name) enum name #define YG_ENUM_END(name) name #endif + +#ifdef __GNUC__ +#define YG_DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) +#define YG_DEPRECATED __declspec(deprecated) +#elif __cplusplus >= 201402L +#if defined(__has_cpp_attribute) +#if __has_cpp_attribute(deprecated) +#define YG_DEPRECATED [[deprecated]] +#endif +#endif +#endif diff --git a/yoga/YGNode.h b/yoga/YGNode.h index e5f1da3c..1ef80142 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -11,6 +11,7 @@ #include "YGConfig.h" #include "YGLayout.h" #include "YGStyle.h" +#include "YGMacros.h" #include "Yoga-internal.h" YGConfigRef YGConfigGetDefault(); @@ -272,7 +273,7 @@ public: // TODO: rvalue override for setChildren - void setConfig(YGConfigRef config) { config_ = config; } + YG_DEPRECATED void setConfig(YGConfigRef config) { config_ = config; } void setDirty(bool isDirty); void setLayoutLastOwnerDirection(YGDirection direction); diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 93ad4148..da24a549 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -253,7 +253,13 @@ static YGConfigRef YGConfigClone(const YGConfig& oldConfig) { } static YGNodeRef YGNodeDeepClone(YGNodeRef oldNode) { - YGNodeRef node = YGNodeClone(oldNode); + auto config = YGConfigClone(*oldNode->getConfig()); + auto node = new YGNode{*oldNode, config}; + node->setOwner(nullptr); +#ifdef YG_ENABLE_EVENTS + Event::publish(node, {node->getConfig()}); +#endif + YGVector vec = YGVector(); vec.reserve(oldNode->getChildren().size()); YGNodeRef childNode = nullptr; @@ -264,10 +270,6 @@ static YGNodeRef YGNodeDeepClone(YGNodeRef oldNode) { } node->setChildren(vec); - if (oldNode->getConfig() != nullptr) { - node->setConfig(YGConfigClone(*(oldNode->getConfig()))); - } - return node; }