Skip to content

Commit

Permalink
Expose a function which marks all descendants dirty
Browse files Browse the repository at this point in the history
Reviewed By: emilsjolander

Differential Revision: D6911869

fbshipit-source-id: e0a3abcf5653f921297edfdca473d83b947cc627
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Feb 8, 2018
1 parent af0c863 commit 528bbac
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 84 deletions.
14 changes: 9 additions & 5 deletions ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -195,6 +193,12 @@ public void dirty() {
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);
Expand Down
166 changes: 87 additions & 79 deletions ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ void jni_YGNodeMarkDirty(alias_ref<jobject>, jlong nativePointer) {
YGNodeMarkDirty(_jlong2YGNodeRef(nativePointer));
}

void jni_YGNodeMarkDirtyAndPropogateToDescendants(
alias_ref<jobject>,
jlong nativePointer) {
YGNodeMarkDirtyAndPropogateToDescendants(_jlong2YGNodeRef(nativePointer));
}

jboolean jni_YGNodeIsDirty(alias_ref<jobject>, jlong nativePointer) {
return (jboolean)_jlong2YGNodeRef(nativePointer)->isDirty();
}
Expand Down Expand Up @@ -449,85 +455,87 @@ jint jni_YGNodeGetInstanceCount(alias_ref<jclass> 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),
Expand Down
4 changes: 4 additions & 0 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions ReactCommon/yoga/yoga/Yoga.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 528bbac

Please sign in to comment.