From 755fa07b39eb32f6c46906ec8aa1dad7007e9a9a Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Thu, 6 Jun 2019 20:59:24 -0700 Subject: [PATCH] add node measure event and passing the callback to java layer Summary: Adds measure event and its listener initial code structure Reviewed By: davidaurelio Differential Revision: D15600738 fbshipit-source-id: d15764e0b64edb170fcb15e0912ecce5f7e53595 --- java/com/facebook/yoga/YogaEventListener.java | 4 +++- tests/EventsTest.cpp | 2 ++ yoga/Yoga.cpp | 4 ++++ yoga/event/event.h | 8 +++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/java/com/facebook/yoga/YogaEventListener.java b/java/com/facebook/yoga/YogaEventListener.java index 6d1d486b..97791224 100644 --- a/java/com/facebook/yoga/YogaEventListener.java +++ b/java/com/facebook/yoga/YogaEventListener.java @@ -10,4 +10,6 @@ public interface YogaEventListener { void onLayoutPassEnd(YogaNode node); -} \ No newline at end of file + void onNodeMeasure(YogaNode node); + +} diff --git a/tests/EventsTest.cpp b/tests/EventsTest.cpp index 44ade6fd..5cb5db02 100644 --- a/tests/EventsTest.cpp +++ b/tests/EventsTest.cpp @@ -131,6 +131,8 @@ void EventTest::listen(const YGNode& node, Event::Type type, Event::Data data) { break; case Event::LayoutPassEnd: break; + case Event::NodeMeasure: + break; } } diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 763d9bfc..c46104be 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -1635,6 +1635,10 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( heightMeasureMode, layoutContext); +#ifdef YG_ENABLE_EVENTS + Event::publish(node, {layoutContext}); +#endif + node->setLayoutMeasuredDimension( YGNodeBoundAxis( node, diff --git a/yoga/event/event.h b/yoga/event/event.h index f0f42797..bff8dbfd 100644 --- a/yoga/event/event.h +++ b/yoga/event/event.h @@ -21,7 +21,8 @@ struct Event { NodeDeallocation, NodeLayout, LayoutPassStart, - LayoutPassEnd + LayoutPassEnd, + NodeMeasure, }; class Data; using Subscriber = void(const YGNode&, Type, Data); @@ -76,5 +77,10 @@ struct Event::TypedData { void* layoutContext; }; +template <> +struct Event::TypedData { + void* layoutContext; +}; + } // namespace yoga } // namespace facebook