From a15bf6e701313e6a2b6202dbacdce92060a46f02 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Fri, 10 May 2019 18:55:53 -0700 Subject: [PATCH] Publish events for layout pass Summary: Adds `LayoutPassStart` and `LayoutPassEnd` events. The existing `NodeLayout` event in isolation is not as useful as it could be. Having events that mark start and end of a layout pass are a useful addition. Differential Revision: D15305467 fbshipit-source-id: 14af6f65e698fb1e3112eb2ffd87a74d31df4840 --- tests/EventsTest.cpp | 4 ++++ yoga/Yoga.cpp | 18 ++++++++++++++++-- yoga/event/event.h | 8 +++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tests/EventsTest.cpp b/tests/EventsTest.cpp index d4645a3b..99c19d94 100644 --- a/tests/EventsTest.cpp +++ b/tests/EventsTest.cpp @@ -127,6 +127,10 @@ void EventTest::listen(const YGNode& node, Event::Type type, Event::Data data) { case Event::NodeLayout: events.push_back(createArgs(node, data)); break; + case Event::LayoutPassStart: + break; + case Event::LayoutPassEnd: + break; } } diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index a34c791e..f7322980 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "Utils.h" #include "YGNode.h" #include "YGNodePrint.h" @@ -4002,7 +4003,13 @@ void YGNodeCalculateLayoutWithContext( const float ownerHeight, const YGDirection ownerDirection, void* layoutContext) { - marker::MarkerSection marker{node}; + +#ifdef YG_ENABLE_EVENTS + Event::publish(node); +#endif + // unique pointer to allow ending the marker early + std::unique_ptr> marker{ + new marker::MarkerSection{node}}; // Increment the generation count. This will force the recursive routine to // visit all dirty nodes at least once. Subsequent visits will be skipped if @@ -4061,7 +4068,7 @@ void YGNodeCalculateLayoutWithContext( true, "initial", node->getConfig(), - marker.data, + marker->data, layoutContext)) { node->setPosition( node->getLayout().direction, ownerWidth, ownerHeight, ownerWidth); @@ -4078,6 +4085,13 @@ void YGNodeCalculateLayoutWithContext( #endif } + // end marker here + marker = nullptr; + +#ifdef YG_ENABLE_EVENTS + Event::publish(node); +#endif + // We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we // aren't sure whether client's of yoga have gotten rid off this flag or not. // So logging this in YGLayout would help to find out the call sites depending diff --git a/yoga/event/event.h b/yoga/event/event.h index e667d2d2..c86d5bde 100644 --- a/yoga/event/event.h +++ b/yoga/event/event.h @@ -15,7 +15,13 @@ namespace facebook { namespace yoga { struct Event { - enum Type { NodeAllocation, NodeDeallocation, NodeLayout }; + enum Type { + NodeAllocation, + NodeDeallocation, + NodeLayout, + LayoutPassStart, + LayoutPassEnd + }; class Data; using Subscriber = void(const YGNode&, Type, Data);