diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index f3f68fd075c..727723665ad 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -13,6 +13,7 @@ #include "YGNode.h" #include "YGNodePrint.h" #include "Yoga-internal.h" +#include "events.h" #include "instrumentation.h" #ifdef _MSC_VER #include @@ -213,6 +214,9 @@ WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) { YGAssertWithConfig( config, node != nullptr, "Could not allocate memory for node"); gNodeInstanceCount++; +#ifdef YG_ENABLE_EVENTS + Event::publish(node, {config}); +#endif if (config->useWebDefaults) { node->getStyle().flexDirection() = YGFlexDirectionRow; @@ -238,6 +242,9 @@ YGNodeRef YGNodeClone(YGNodeRef oldNode) { node != nullptr, "Could not allocate memory for node"); gNodeInstanceCount++; +#ifdef YG_ENABLE_EVENTS + Event::publish(node, {node->getConfig()}); +#endif node->setOwner(nullptr); return node; } @@ -284,6 +291,9 @@ void YGNodeFree(const YGNodeRef node) { } node->clearChildren(); +#ifdef YG_ENABLE_EVENTS + Event::publish(node, {node->getConfig()}); +#endif delete node; gNodeInstanceCount--; } diff --git a/ReactCommon/yoga/yoga/events.cpp b/ReactCommon/yoga/yoga/events.cpp index 19092fc5e9a..2548204a7d5 100644 --- a/ReactCommon/yoga/yoga/events.cpp +++ b/ReactCommon/yoga/yoga/events.cpp @@ -8,6 +8,8 @@ #include #include +#include + namespace facebook { namespace yoga { diff --git a/ReactCommon/yoga/yoga/events.h b/ReactCommon/yoga/yoga/events.h index c48fab7bef1..bd8cdd4b72e 100644 --- a/ReactCommon/yoga/yoga/events.h +++ b/ReactCommon/yoga/yoga/events.h @@ -15,7 +15,7 @@ namespace facebook { namespace yoga { struct Event { - enum Type {}; + enum Type { NodeAllocation, NodeDeallocation }; class Data; using Subscriber = void(const YGNode&, Type, Data); @@ -51,5 +51,15 @@ private: static void publish(const YGNode&, Type, const Data&); }; +template <> +struct Event::TypedData { + YGConfig* config; +}; + +template <> +struct Event::TypedData { + YGConfig* config; +}; + } // namespace yoga } // namespace facebook