diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/YogaConfig.java b/ReactAndroid/src/main/java/com/facebook/yoga/YogaConfig.java index e68c512140f015..2d90eec9de9dca 100644 --- a/ReactAndroid/src/main/java/com/facebook/yoga/YogaConfig.java +++ b/ReactAndroid/src/main/java/com/facebook/yoga/YogaConfig.java @@ -74,6 +74,19 @@ public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) { jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour); } + private native void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( + long nativePointer, boolean shouldDiffLayoutWithoutLegacyStretchBehaviour); + /** + * If this flag is set then yoga would diff the layout without legacy flag and would set a bool in + * YogaNode(mDoesLegacyStretchFlagAffectsLayout) with true if the layouts were different and false + * if not + */ + public void setShouldDiffLayoutWithoutLegacyStretchBehaviour( + boolean shouldDiffLayoutWithoutLegacyStretchBehaviour) { + jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( + mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour); + } + private native void jni_YGConfigSetLogger(long nativePointer, Object logger); public void setLogger(YogaLogger logger) { mLogger = logger; diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java index df5fae91712879..1c6e67a55eb9e5 100644 --- a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java +++ b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java @@ -82,6 +82,7 @@ public class YogaNode implements Cloneable { private int mLayoutDirection = 0; @DoNotStrip private boolean mHasNewLayout = true; + @DoNotStrip private boolean mDoesLegacyStretchFlagAffectsLayout = false; private native long jni_YGNodeNew(); public YogaNode() { @@ -136,6 +137,7 @@ public void reset() { mMeasureFunction = null; mBaselineFunction = null; mData = null; + mDoesLegacyStretchFlagAffectsLayout = false; jni_YGNodeReset(mNativePointer); } @@ -573,6 +575,10 @@ public float getLayoutHeight() { return mHeight; } + public boolean getDoesLegacyStretchFlagAffectsLayout() { + return mDoesLegacyStretchFlagAffectsLayout; + } + public float getLayoutMargin(YogaEdge edge) { switch (edge) { case LEFT: 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 46d73b44b4d7ff..cc75df96a15131 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp @@ -67,6 +67,9 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) { static auto edgeSetFlagField = obj->getClass()->getField("mEdgeSetFlag"); static auto hasNewLayoutField = obj->getClass()->getField("mHasNewLayout"); + static auto doesLegacyStretchBehaviour = + obj->getClass()->getField( + "mDoesLegacyStretchFlagAffectsLayout"); /* Those flags needs be in sync with YogaNode.java */ const int MARGIN = 1; @@ -79,12 +82,19 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) { obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root)); obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root)); obj->setFieldValue(topField, YGNodeLayoutGetTop(root)); + obj->setFieldValue( + doesLegacyStretchBehaviour, + YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root)); if ((hasEdgeSetFlag & MARGIN) == MARGIN) { - obj->setFieldValue(marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft)); - obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop)); - obj->setFieldValue(marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight)); - obj->setFieldValue(marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom)); + obj->setFieldValue( + marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft)); + obj->setFieldValue( + marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop)); + obj->setFieldValue( + marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight)); + obj->setFieldValue( + marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom)); } if ((hasEdgeSetFlag & PADDING) == PADDING) { @@ -467,6 +477,14 @@ void jni_YGConfigSetExperimentalFeatureEnabled(alias_ref, enabled); } +void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( + alias_ref, + jlong nativePointer, + jboolean enabled) { + const YGConfigRef config = _jlong2YGConfigRef(nativePointer); + YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(config, enabled); +} + void jni_YGConfigSetUseWebDefaults(alias_ref, jlong nativePointer, jboolean useWebDefaults) { @@ -624,16 +642,19 @@ jint JNI_OnLoad(JavaVM *vm, void *) { YGMakeNativeMethod(jni_YGNodePrint), YGMakeNativeMethod(jni_YGNodeClone), }); - registerNatives("com/facebook/yoga/YogaConfig", - { - YGMakeNativeMethod(jni_YGConfigNew), - YGMakeNativeMethod(jni_YGConfigFree), - YGMakeNativeMethod(jni_YGConfigSetExperimentalFeatureEnabled), - YGMakeNativeMethod(jni_YGConfigSetUseWebDefaults), - YGMakeNativeMethod(jni_YGConfigSetPointScaleFactor), - YGMakeNativeMethod(jni_YGConfigSetUseLegacyStretchBehaviour), - YGMakeNativeMethod(jni_YGConfigSetLogger), - YGMakeNativeMethod(jni_YGConfigSetHasNodeClonedFunc), - }); + registerNatives( + "com/facebook/yoga/YogaConfig", + { + YGMakeNativeMethod(jni_YGConfigNew), + YGMakeNativeMethod(jni_YGConfigFree), + YGMakeNativeMethod(jni_YGConfigSetExperimentalFeatureEnabled), + YGMakeNativeMethod(jni_YGConfigSetUseWebDefaults), + YGMakeNativeMethod(jni_YGConfigSetPointScaleFactor), + YGMakeNativeMethod(jni_YGConfigSetUseLegacyStretchBehaviour), + YGMakeNativeMethod(jni_YGConfigSetLogger), + YGMakeNativeMethod(jni_YGConfigSetHasNodeClonedFunc), + YGMakeNativeMethod( + jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour), + }); }); } diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index b3f3e2206a1395..b5e1e4c044f54c 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -905,6 +905,10 @@ YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Margin, margin); YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border); YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding); +bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(const YGNodeRef node) { + return node->getLayout().doesLegacyStretchFlagAffectsLayout; +} + uint32_t gCurrentGenerationCount = 0; bool YGLayoutNodeInternal(const YGNodeRef node, @@ -3842,6 +3846,12 @@ void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) { } } +void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( + const YGConfigRef config, + const bool shouldDiffLayout) { + config->shouldDiffLayoutWithoutLegacyStretchBehaviour = shouldDiffLayout; +} + static void YGVLog(const YGConfigRef config, const YGNodeRef node, YGLogLevel level, diff --git a/ReactCommon/yoga/yoga/Yoga.h b/ReactCommon/yoga/yoga/Yoga.h index baeb28e2219c36..83eefa02689347 100644 --- a/ReactCommon/yoga/yoga/Yoga.h +++ b/ReactCommon/yoga/yoga/Yoga.h @@ -236,6 +236,7 @@ YG_NODE_LAYOUT_PROPERTY(float, Width); YG_NODE_LAYOUT_PROPERTY(float, Height); YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction); YG_NODE_LAYOUT_PROPERTY(bool, HadOverflow); +bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(const YGNodeRef node); // Get the computed values for these nodes after performing layout. If they were set using // point values then the returned value will be the same as YGNodeStyleGetXXX. However if @@ -253,10 +254,12 @@ WIN_EXPORT void YGAssertWithNode(const YGNodeRef node, const bool condition, con WIN_EXPORT void YGAssertWithConfig(const YGConfigRef config, const bool condition, const char *message); - // Set this to number of pixels in 1 point to round calculation results // If you want to avoid rounding - set PointScaleFactor to 0 WIN_EXPORT void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInPoint); +void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( + const YGConfigRef config, + const bool shouldDiffLayout); // Yoga previously had an error where containers would take the maximum space possible instead of // the minimum