diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java index 9836f9cac..093d209d3 100644 --- a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java +++ b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java @@ -9,13 +9,11 @@ package com.facebook.yoga; -import javax.annotation.Nullable; - -import java.util.List; -import java.util.ArrayList; - import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.soloader.SoLoader; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nullable; @DoNotStrip public class YogaNode { @@ -195,6 +193,12 @@ public class YogaNode { jni_YGNodeMarkDirty(mNativePointer); } + private native void jni_YGNodeMarkDirtyAndPropogateToDescendants(long nativePointer); + + public void dirtyAllDescendants() { + jni_YGNodeMarkDirtyAndPropogateToDescendants(mNativePointer); + } + private native boolean jni_YGNodeIsDirty(long nativePointer); public boolean isDirty() { return jni_YGNodeIsDirty(mNativePointer); 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 fd2ed9c38..a54c062fd 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp @@ -251,6 +251,12 @@ void jni_YGNodeMarkDirty(alias_ref, jlong nativePointer) { YGNodeMarkDirty(_jlong2YGNodeRef(nativePointer)); } +void jni_YGNodeMarkDirtyAndPropogateToDescendants( + alias_ref, + jlong nativePointer) { + YGNodeMarkDirtyAndPropogateToDescendants(_jlong2YGNodeRef(nativePointer)); +} + jboolean jni_YGNodeIsDirty(alias_ref, jlong nativePointer) { return (jboolean)_jlong2YGNodeRef(nativePointer)->isDirty(); } @@ -449,85 +455,87 @@ jint jni_YGNodeGetInstanceCount(alias_ref clazz) { jint JNI_OnLoad(JavaVM *vm, void *) { return initialize(vm, [] { - registerNatives("com/facebook/yoga/YogaNode", - { - YGMakeNativeMethod(jni_YGNodeNew), - YGMakeNativeMethod(jni_YGNodeNewWithConfig), - YGMakeNativeMethod(jni_YGNodeFree), - YGMakeNativeMethod(jni_YGNodeReset), - YGMakeNativeMethod(jni_YGNodeInsertChild), - YGMakeNativeMethod(jni_YGNodeRemoveChild), - YGMakeNativeMethod(jni_YGNodeCalculateLayout), - YGMakeNativeMethod(jni_YGNodeMarkDirty), - YGMakeNativeMethod(jni_YGNodeIsDirty), - YGMakeNativeMethod(jni_YGNodeSetHasMeasureFunc), - YGMakeNativeMethod(jni_YGNodeSetHasBaselineFunc), - YGMakeNativeMethod(jni_YGNodeCopyStyle), - YGMakeNativeMethod(jni_YGNodeStyleGetDirection), - YGMakeNativeMethod(jni_YGNodeStyleSetDirection), - YGMakeNativeMethod(jni_YGNodeStyleGetFlexDirection), - YGMakeNativeMethod(jni_YGNodeStyleSetFlexDirection), - YGMakeNativeMethod(jni_YGNodeStyleGetJustifyContent), - YGMakeNativeMethod(jni_YGNodeStyleSetJustifyContent), - YGMakeNativeMethod(jni_YGNodeStyleGetAlignItems), - YGMakeNativeMethod(jni_YGNodeStyleSetAlignItems), - YGMakeNativeMethod(jni_YGNodeStyleGetAlignSelf), - YGMakeNativeMethod(jni_YGNodeStyleSetAlignSelf), - YGMakeNativeMethod(jni_YGNodeStyleGetAlignContent), - YGMakeNativeMethod(jni_YGNodeStyleSetAlignContent), - YGMakeNativeMethod(jni_YGNodeStyleGetPositionType), - YGMakeNativeMethod(jni_YGNodeStyleSetPositionType), - YGMakeNativeMethod(jni_YGNodeStyleSetFlexWrap), - YGMakeNativeMethod(jni_YGNodeStyleGetOverflow), - YGMakeNativeMethod(jni_YGNodeStyleSetOverflow), - YGMakeNativeMethod(jni_YGNodeStyleGetDisplay), - YGMakeNativeMethod(jni_YGNodeStyleSetDisplay), - YGMakeNativeMethod(jni_YGNodeStyleSetFlex), - YGMakeNativeMethod(jni_YGNodeStyleGetFlexGrow), - YGMakeNativeMethod(jni_YGNodeStyleSetFlexGrow), - YGMakeNativeMethod(jni_YGNodeStyleGetFlexShrink), - YGMakeNativeMethod(jni_YGNodeStyleSetFlexShrink), - YGMakeNativeMethod(jni_YGNodeStyleGetFlexBasis), - YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasis), - YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasisPercent), - YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasisAuto), - YGMakeNativeMethod(jni_YGNodeStyleGetMargin), - YGMakeNativeMethod(jni_YGNodeStyleSetMargin), - YGMakeNativeMethod(jni_YGNodeStyleSetMarginPercent), - YGMakeNativeMethod(jni_YGNodeStyleSetMarginAuto), - YGMakeNativeMethod(jni_YGNodeStyleGetPadding), - YGMakeNativeMethod(jni_YGNodeStyleSetPadding), - YGMakeNativeMethod(jni_YGNodeStyleSetPaddingPercent), - YGMakeNativeMethod(jni_YGNodeStyleGetBorder), - YGMakeNativeMethod(jni_YGNodeStyleSetBorder), - YGMakeNativeMethod(jni_YGNodeStyleGetPosition), - YGMakeNativeMethod(jni_YGNodeStyleSetPosition), - YGMakeNativeMethod(jni_YGNodeStyleSetPositionPercent), - YGMakeNativeMethod(jni_YGNodeStyleGetWidth), - YGMakeNativeMethod(jni_YGNodeStyleSetWidth), - YGMakeNativeMethod(jni_YGNodeStyleSetWidthPercent), - YGMakeNativeMethod(jni_YGNodeStyleSetWidthAuto), - YGMakeNativeMethod(jni_YGNodeStyleGetHeight), - YGMakeNativeMethod(jni_YGNodeStyleSetHeight), - YGMakeNativeMethod(jni_YGNodeStyleSetHeightPercent), - YGMakeNativeMethod(jni_YGNodeStyleSetHeightAuto), - YGMakeNativeMethod(jni_YGNodeStyleGetMinWidth), - YGMakeNativeMethod(jni_YGNodeStyleSetMinWidth), - YGMakeNativeMethod(jni_YGNodeStyleSetMinWidthPercent), - YGMakeNativeMethod(jni_YGNodeStyleGetMinHeight), - YGMakeNativeMethod(jni_YGNodeStyleSetMinHeight), - YGMakeNativeMethod(jni_YGNodeStyleSetMinHeightPercent), - YGMakeNativeMethod(jni_YGNodeStyleGetMaxWidth), - YGMakeNativeMethod(jni_YGNodeStyleSetMaxWidth), - YGMakeNativeMethod(jni_YGNodeStyleSetMaxWidthPercent), - YGMakeNativeMethod(jni_YGNodeStyleGetMaxHeight), - YGMakeNativeMethod(jni_YGNodeStyleSetMaxHeight), - YGMakeNativeMethod(jni_YGNodeStyleSetMaxHeightPercent), - YGMakeNativeMethod(jni_YGNodeStyleGetAspectRatio), - YGMakeNativeMethod(jni_YGNodeStyleSetAspectRatio), - YGMakeNativeMethod(jni_YGNodeGetInstanceCount), - YGMakeNativeMethod(jni_YGNodePrint), - }); + registerNatives( + "com/facebook/yoga/YogaNode", + { + YGMakeNativeMethod(jni_YGNodeNew), + YGMakeNativeMethod(jni_YGNodeNewWithConfig), + YGMakeNativeMethod(jni_YGNodeFree), + YGMakeNativeMethod(jni_YGNodeReset), + YGMakeNativeMethod(jni_YGNodeInsertChild), + YGMakeNativeMethod(jni_YGNodeRemoveChild), + YGMakeNativeMethod(jni_YGNodeCalculateLayout), + YGMakeNativeMethod(jni_YGNodeMarkDirty), + YGMakeNativeMethod(jni_YGNodeMarkDirtyAndPropogateToDescendants), + YGMakeNativeMethod(jni_YGNodeIsDirty), + YGMakeNativeMethod(jni_YGNodeSetHasMeasureFunc), + YGMakeNativeMethod(jni_YGNodeSetHasBaselineFunc), + YGMakeNativeMethod(jni_YGNodeCopyStyle), + YGMakeNativeMethod(jni_YGNodeStyleGetDirection), + YGMakeNativeMethod(jni_YGNodeStyleSetDirection), + YGMakeNativeMethod(jni_YGNodeStyleGetFlexDirection), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexDirection), + YGMakeNativeMethod(jni_YGNodeStyleGetJustifyContent), + YGMakeNativeMethod(jni_YGNodeStyleSetJustifyContent), + YGMakeNativeMethod(jni_YGNodeStyleGetAlignItems), + YGMakeNativeMethod(jni_YGNodeStyleSetAlignItems), + YGMakeNativeMethod(jni_YGNodeStyleGetAlignSelf), + YGMakeNativeMethod(jni_YGNodeStyleSetAlignSelf), + YGMakeNativeMethod(jni_YGNodeStyleGetAlignContent), + YGMakeNativeMethod(jni_YGNodeStyleSetAlignContent), + YGMakeNativeMethod(jni_YGNodeStyleGetPositionType), + YGMakeNativeMethod(jni_YGNodeStyleSetPositionType), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexWrap), + YGMakeNativeMethod(jni_YGNodeStyleGetOverflow), + YGMakeNativeMethod(jni_YGNodeStyleSetOverflow), + YGMakeNativeMethod(jni_YGNodeStyleGetDisplay), + YGMakeNativeMethod(jni_YGNodeStyleSetDisplay), + YGMakeNativeMethod(jni_YGNodeStyleSetFlex), + YGMakeNativeMethod(jni_YGNodeStyleGetFlexGrow), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexGrow), + YGMakeNativeMethod(jni_YGNodeStyleGetFlexShrink), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexShrink), + YGMakeNativeMethod(jni_YGNodeStyleGetFlexBasis), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasis), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasisPercent), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasisAuto), + YGMakeNativeMethod(jni_YGNodeStyleGetMargin), + YGMakeNativeMethod(jni_YGNodeStyleSetMargin), + YGMakeNativeMethod(jni_YGNodeStyleSetMarginPercent), + YGMakeNativeMethod(jni_YGNodeStyleSetMarginAuto), + YGMakeNativeMethod(jni_YGNodeStyleGetPadding), + YGMakeNativeMethod(jni_YGNodeStyleSetPadding), + YGMakeNativeMethod(jni_YGNodeStyleSetPaddingPercent), + YGMakeNativeMethod(jni_YGNodeStyleGetBorder), + YGMakeNativeMethod(jni_YGNodeStyleSetBorder), + YGMakeNativeMethod(jni_YGNodeStyleGetPosition), + YGMakeNativeMethod(jni_YGNodeStyleSetPosition), + YGMakeNativeMethod(jni_YGNodeStyleSetPositionPercent), + YGMakeNativeMethod(jni_YGNodeStyleGetWidth), + YGMakeNativeMethod(jni_YGNodeStyleSetWidth), + YGMakeNativeMethod(jni_YGNodeStyleSetWidthPercent), + YGMakeNativeMethod(jni_YGNodeStyleSetWidthAuto), + YGMakeNativeMethod(jni_YGNodeStyleGetHeight), + YGMakeNativeMethod(jni_YGNodeStyleSetHeight), + YGMakeNativeMethod(jni_YGNodeStyleSetHeightPercent), + YGMakeNativeMethod(jni_YGNodeStyleSetHeightAuto), + YGMakeNativeMethod(jni_YGNodeStyleGetMinWidth), + YGMakeNativeMethod(jni_YGNodeStyleSetMinWidth), + YGMakeNativeMethod(jni_YGNodeStyleSetMinWidthPercent), + YGMakeNativeMethod(jni_YGNodeStyleGetMinHeight), + YGMakeNativeMethod(jni_YGNodeStyleSetMinHeight), + YGMakeNativeMethod(jni_YGNodeStyleSetMinHeightPercent), + YGMakeNativeMethod(jni_YGNodeStyleGetMaxWidth), + YGMakeNativeMethod(jni_YGNodeStyleSetMaxWidth), + YGMakeNativeMethod(jni_YGNodeStyleSetMaxWidthPercent), + YGMakeNativeMethod(jni_YGNodeStyleGetMaxHeight), + YGMakeNativeMethod(jni_YGNodeStyleSetMaxHeight), + YGMakeNativeMethod(jni_YGNodeStyleSetMaxHeightPercent), + YGMakeNativeMethod(jni_YGNodeStyleGetAspectRatio), + YGMakeNativeMethod(jni_YGNodeStyleSetAspectRatio), + YGMakeNativeMethod(jni_YGNodeGetInstanceCount), + YGMakeNativeMethod(jni_YGNodePrint), + }); registerNatives("com/facebook/yoga/YogaConfig", { YGMakeNativeMethod(jni_YGConfigNew), diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index 93767f3ed..6e6806f27 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -215,6 +215,10 @@ bool YGNodeLayoutGetDidUseLegacyFlag(const YGNodeRef node) { return node->didUseLegacyFlag(); } +void YGNodeMarkDirtyAndPropogateToDescendants(const YGNodeRef node) { + return node->markDirtyAndPropogateDownwards(); +} + int32_t gNodeInstanceCount = 0; int32_t gConfigInstanceCount = 0; diff --git a/ReactCommon/yoga/yoga/Yoga.h b/ReactCommon/yoga/yoga/Yoga.h index ab5e1f046..bca51da28 100644 --- a/ReactCommon/yoga/yoga/Yoga.h +++ b/ReactCommon/yoga/yoga/Yoga.h @@ -99,6 +99,10 @@ WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node, // marking manually. WIN_EXPORT void YGNodeMarkDirty(const YGNodeRef node); +// This function marks the current node and all its descendants as dirty. This function is added to test yoga benchmarks. +// This function is not expected to be used in production as calling `YGCalculateLayout` will cause the recalculation of each and every node. +WIN_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants(const YGNodeRef node); + WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options); WIN_EXPORT bool YGFloatIsUndefined(const float value);