From f0240e004a021c2bb5889f507726949d849e8ea6 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Fri, 17 Mar 2017 09:07:24 -0700 Subject: [PATCH] Avoid transfering cached layout information to java Reviewed By: astreet Differential Revision: D4716024 fbshipit-source-id: c30763a6fc7426d653c7a6ca129615cddb4140e9 --- .../src/main/jni/first-party/yogajni/jni/YGJNI.cpp | 6 ++++++ ReactCommon/yoga/yoga/Yoga.c | 13 +++++++++++++ ReactCommon/yoga/yoga/Yoga.h | 2 ++ 3 files changed, 21 insertions(+) diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp index 72e704c8c..c0b0dd495 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp @@ -24,6 +24,12 @@ static void YGTransferLayoutDirection(YGNodeRef node, alias_ref javaNod } static void YGTransferLayoutOutputsRecursive(YGNodeRef root) { + // If the node is using a cached layout it means we have already + // transfered it to java. + if (YGNodeIsUsingCachedLayout(root)) { + return; + } + if (auto obj = YGNodeJobject(root)->lockLocal()) { static auto widthField = obj->getClass()->getField("mWidth"); static auto heightField = obj->getClass()->getField("mHeight"); diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index 65a3ba46f..1b3961c9c 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -459,6 +459,18 @@ void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) { } } +static int YGNodeRootGenerationCount(const YGNodeRef node) { + if (node->parent) { + return YGNodeRootGenerationCount(node->parent); + } else { + return node->layout.generationCount; + } +} + +bool YGNodeIsUsingCachedLayout(const YGNodeRef node) { + return node->layout.generationCount != YGNodeRootGenerationCount(node); +} + static inline float YGResolveFlexGrow(const YGNodeRef node) { if (!YGFloatIsUndefined(node->style.flexGrow)) { return node->style.flexGrow; @@ -1811,6 +1823,7 @@ static void YGZeroOutLayoutRecursivly(const YGNodeRef node) { node->layout.cachedLayout.widthMeasureMode = YGMeasureModeExactly; node->layout.cachedLayout.computedWidth = 0; node->layout.cachedLayout.computedHeight = 0; + node->layout.generationCount = gCurrentGenerationCount; const uint32_t childCount = YGNodeGetChildCount(node); for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = YGNodeListGet(node->children, i); diff --git a/ReactCommon/yoga/yoga/Yoga.h b/ReactCommon/yoga/yoga/Yoga.h index d5c5258a7..054b5dc50 100644 --- a/ReactCommon/yoga/yoga/Yoga.h +++ b/ReactCommon/yoga/yoga/Yoga.h @@ -218,6 +218,8 @@ YG_NODE_LAYOUT_EDGE_PROPERTY(float, Margin); YG_NODE_LAYOUT_EDGE_PROPERTY(float, Border); YG_NODE_LAYOUT_EDGE_PROPERTY(float, Padding); +bool YGNodeIsUsingCachedLayout(const YGNodeRef node); + WIN_EXPORT void YGSetLogger(YGLogger logger); WIN_EXPORT void YGLog(YGLogLevel level, const char *message, ...);