From 055b28b4f42bf28946138a34ccd649795a56d794 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Mon, 24 Jun 2019 08:29:59 -0700 Subject: [PATCH] pass cachedLayout and cachedMeasure measures to plugin Summary: Passing whether layout cache or measure cache was used or not Reviewed By: davidaurelio Differential Revision: D15920937 fbshipit-source-id: a6728e7af07ea228a285f824fbdfddc8130c5990 --- .../com/facebook/yoga/YogaLayoutType.java | 34 +++++++++++++++++++ ReactCommon/yoga/yoga/Yoga.cpp | 11 +++++- ReactCommon/yoga/yoga/event/event.h | 9 ++++- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 ReactAndroid/src/main/java/com/facebook/yoga/YogaLayoutType.java diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/YogaLayoutType.java b/ReactAndroid/src/main/java/com/facebook/yoga/YogaLayoutType.java new file mode 100644 index 00000000000..b747439f697 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/yoga/YogaLayoutType.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ +package com.facebook.yoga; + +public enum YogaLayoutType { + LAYOUT(0), + MEASURE(1), + CACHED_LAYOUT(2), + CACHED_MEASURE(3); + + private final int mIntValue; + + YogaLayoutType(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaLayoutType fromInt(int value) { + switch (value) { + case 0: return LAYOUT; + case 1: return MEASURE; + case 2: return CACHED_LAYOUT; + case 3: return CACHED_MEASURE; + default: throw new IllegalArgumentException("Unknown enum value: " + value); + } + } +} diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index cfcadf5753f..375668b7af7 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -3928,7 +3928,16 @@ bool YGLayoutNodeInternal( layout->generationCount = gCurrentGenerationCount; #ifdef YG_ENABLE_EVENTS - Event::publish(node, {performLayout, layoutContext}); + LayoutType layoutType; + if (performLayout) { + layoutType = !needToVisitNode && cachedResults == &layout->cachedLayout + ? LayoutType::kCachedLayout + : LayoutType::kLayout; + } else { + layoutType = cachedResults != nullptr ? LayoutType::kCachedMeasure + : LayoutType::kMeasure; + } + Event::publish(node, {layoutType, layoutContext}); #endif return (needToVisitNode || cachedResults == nullptr); diff --git a/ReactCommon/yoga/yoga/event/event.h b/ReactCommon/yoga/yoga/event/event.h index 58e5e541ed5..4179e9be367 100644 --- a/ReactCommon/yoga/yoga/event/event.h +++ b/ReactCommon/yoga/yoga/event/event.h @@ -17,6 +17,13 @@ struct YGNode; namespace facebook { namespace yoga { +enum LayoutType : int { + kLayout = 0, + kMeasure = 1, + kCachedLayout = 2, + kCachedMeasure = 3 +}; + struct Event { enum Type { NodeAllocation, @@ -99,7 +106,7 @@ struct Event::TypedData { template <> struct Event::TypedData { - bool performLayout; + LayoutType layoutType; void* layoutContext; };