From abb77b34cc4d45aa75fb91e00fa90b2469810756 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Tue, 8 Oct 2019 14:23:57 -0700 Subject: [PATCH] move percent auto style properties to vanilla jni (YogaStyleProperties Part 3) Summary: Move Yoga style properties to vanilla JNI under a flag. Reviewed By: amir-shalem Differential Revision: D17666674 fbshipit-source-id: 08490bf7c214c856a93214088a27dd4e6df9e0fd --- .../java/com/facebook/yoga/YogaNative.java | 24 ++++ .../com/facebook/yoga/YogaNodeJNIBase.java | 99 +++++++++++++---- .../jni/first-party/yogajni/jni/YGJNI.cpp | 1 - .../main/jni/first-party/yogajni/jni/YGJNI.h | 2 + .../first-party/yogajni/jni/YGJNIVanilla.cpp | 103 ++++++++++++++++++ 5 files changed, 204 insertions(+), 25 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNative.java b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNative.java index bc79d20ff4..a257eb8ccd 100644 --- a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNative.java +++ b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNative.java @@ -140,6 +140,30 @@ public class YogaNative { static native void jni_YGNodeStyleSetFlexGrowJNI(long nativePointer, float flexGrow); static native float jni_YGNodeStyleGetFlexShrinkJNI(long nativePointer); static native void jni_YGNodeStyleSetFlexShrinkJNI(long nativePointer, float flexShrink); + static native long jni_YGNodeStyleGetFlexBasisJNI(long nativePointer); + static native void jni_YGNodeStyleSetFlexBasisJNI(long nativePointer, float flexBasis); + static native void jni_YGNodeStyleSetFlexBasisPercentJNI(long nativePointer, float percent); + static native void jni_YGNodeStyleSetFlexBasisAutoJNI(long nativePointer); + static native long jni_YGNodeStyleGetWidthJNI(long nativePointer); + static native void jni_YGNodeStyleSetWidthJNI(long nativePointer, float width); + static native void jni_YGNodeStyleSetWidthPercentJNI(long nativePointer, float percent); + static native void jni_YGNodeStyleSetWidthAutoJNI(long nativePointer); + static native long jni_YGNodeStyleGetHeightJNI(long nativePointer); + static native void jni_YGNodeStyleSetHeightJNI(long nativePointer, float height); + static native void jni_YGNodeStyleSetHeightPercentJNI(long nativePointer, float percent); + static native void jni_YGNodeStyleSetHeightAutoJNI(long nativePointer); + static native long jni_YGNodeStyleGetMinWidthJNI(long nativePointer); + static native void jni_YGNodeStyleSetMinWidthJNI(long nativePointer, float minWidth); + static native void jni_YGNodeStyleSetMinWidthPercentJNI(long nativePointer, float percent); + static native long jni_YGNodeStyleGetMinHeightJNI(long nativePointer); + static native void jni_YGNodeStyleSetMinHeightJNI(long nativePointer, float minHeight); + static native void jni_YGNodeStyleSetMinHeightPercentJNI(long nativePointer, float percent); + static native long jni_YGNodeStyleGetMaxWidthJNI(long nativePointer); + static native void jni_YGNodeStyleSetMaxWidthJNI(long nativePointer, float maxWidth); + static native void jni_YGNodeStyleSetMaxWidthPercentJNI(long nativePointer, float percent); + static native long jni_YGNodeStyleGetMaxHeightJNI(long nativePointer); + static native void jni_YGNodeStyleSetMaxHeightJNI(long nativePointer, float maxheight); + static native void jni_YGNodeStyleSetMaxHeightPercentJNI(long nativePointer, float percent); static native float jni_YGNodeStyleGetAspectRatioJNI(long nativePointer); static native void jni_YGNodeStyleSetAspectRatioJNI(long nativePointer, float aspectRatio); } diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java index 5fbb87282a..3b7f5b6394 100644 --- a/ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -347,19 +347,28 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { } public YogaValue getFlexBasis() { - return valueFromLong(YogaNative.jni_YGNodeStyleGetFlexBasis(mNativePointer)); + return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetFlexBasisJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetFlexBasis(mNativePointer)); } public void setFlexBasis(float flexBasis) { - YogaNative.jni_YGNodeStyleSetFlexBasis(mNativePointer, flexBasis); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetFlexBasisJNI(mNativePointer, flexBasis); + else + YogaNative.jni_YGNodeStyleSetFlexBasis(mNativePointer, flexBasis); } public void setFlexBasisPercent(float percent) { - YogaNative.jni_YGNodeStyleSetFlexBasisPercent(mNativePointer, percent); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetFlexBasisPercentJNI(mNativePointer, percent); + else + YogaNative.jni_YGNodeStyleSetFlexBasisPercent(mNativePointer, percent); } public void setFlexBasisAuto() { - YogaNative.jni_YGNodeStyleSetFlexBasisAuto(mNativePointer); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetFlexBasisAutoJNI(mNativePointer); + else + YogaNative.jni_YGNodeStyleSetFlexBasisAuto(mNativePointer); } public YogaValue getMargin(YogaEdge edge) { @@ -411,83 +420,125 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { } public YogaValue getWidth() { - return valueFromLong(YogaNative.jni_YGNodeStyleGetWidth(mNativePointer)); + return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetWidthJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetWidth(mNativePointer)); } public void setWidth(float width) { - YogaNative.jni_YGNodeStyleSetWidth(mNativePointer, width); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetWidthJNI(mNativePointer, width); + else + YogaNative.jni_YGNodeStyleSetWidth(mNativePointer, width); } public void setWidthPercent(float percent) { - YogaNative.jni_YGNodeStyleSetWidthPercent(mNativePointer, percent); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetWidthPercentJNI(mNativePointer, percent); + else + YogaNative.jni_YGNodeStyleSetWidthPercent(mNativePointer, percent); } public void setWidthAuto() { - YogaNative.jni_YGNodeStyleSetWidthAuto(mNativePointer); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetWidthAutoJNI(mNativePointer); + else + YogaNative.jni_YGNodeStyleSetWidthAuto(mNativePointer); } public YogaValue getHeight() { - return valueFromLong(YogaNative.jni_YGNodeStyleGetHeight(mNativePointer)); + return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetHeightJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetHeight(mNativePointer)); } public void setHeight(float height) { - YogaNative.jni_YGNodeStyleSetHeight(mNativePointer, height); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetHeightJNI(mNativePointer, height); + else + YogaNative.jni_YGNodeStyleSetHeight(mNativePointer, height); } public void setHeightPercent(float percent) { - YogaNative.jni_YGNodeStyleSetHeightPercent(mNativePointer, percent); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetHeightPercentJNI(mNativePointer, percent); + else + YogaNative.jni_YGNodeStyleSetHeightPercent(mNativePointer, percent); } public void setHeightAuto() { - YogaNative.jni_YGNodeStyleSetHeightAuto(mNativePointer); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetHeightAutoJNI(mNativePointer); + else + YogaNative.jni_YGNodeStyleSetHeightAuto(mNativePointer); } public YogaValue getMinWidth() { - return valueFromLong(YogaNative.jni_YGNodeStyleGetMinWidth(mNativePointer)); + return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetMinWidthJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetMinWidth(mNativePointer)); } public void setMinWidth(float minWidth) { - YogaNative.jni_YGNodeStyleSetMinWidth(mNativePointer, minWidth); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetMinWidthJNI(mNativePointer, minWidth); + else + YogaNative.jni_YGNodeStyleSetMinWidth(mNativePointer, minWidth); } public void setMinWidthPercent(float percent) { - YogaNative.jni_YGNodeStyleSetMinWidthPercent(mNativePointer, percent); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetMinWidthPercentJNI(mNativePointer, percent); + else + YogaNative.jni_YGNodeStyleSetMinWidthPercent(mNativePointer, percent); } public YogaValue getMinHeight() { - return valueFromLong(YogaNative.jni_YGNodeStyleGetMinHeight(mNativePointer)); + return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetMinHeightJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetMinHeight(mNativePointer)); } public void setMinHeight(float minHeight) { - YogaNative.jni_YGNodeStyleSetMinHeight(mNativePointer, minHeight); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetMinHeightJNI(mNativePointer, minHeight); + else + YogaNative.jni_YGNodeStyleSetMinHeight(mNativePointer, minHeight); } public void setMinHeightPercent(float percent) { - YogaNative.jni_YGNodeStyleSetMinHeightPercent(mNativePointer, percent); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetMinHeightPercentJNI(mNativePointer, percent); + else + YogaNative.jni_YGNodeStyleSetMinHeightPercent(mNativePointer, percent); } public YogaValue getMaxWidth() { - return valueFromLong(YogaNative.jni_YGNodeStyleGetMaxWidth(mNativePointer)); + return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetMaxWidthJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetMaxWidth(mNativePointer)); } public void setMaxWidth(float maxWidth) { - YogaNative.jni_YGNodeStyleSetMaxWidth(mNativePointer, maxWidth); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetMaxWidthJNI(mNativePointer, maxWidth); + else + YogaNative.jni_YGNodeStyleSetMaxWidth(mNativePointer, maxWidth); } public void setMaxWidthPercent(float percent) { - YogaNative.jni_YGNodeStyleSetMaxWidthPercent(mNativePointer, percent); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetMaxWidthPercentJNI(mNativePointer, percent); + else + YogaNative.jni_YGNodeStyleSetMaxWidthPercent(mNativePointer, percent); } public YogaValue getMaxHeight() { - return valueFromLong(YogaNative.jni_YGNodeStyleGetMaxHeight(mNativePointer)); + return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetMaxHeightJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetMaxHeight(mNativePointer)); } public void setMaxHeight(float maxheight) { - YogaNative.jni_YGNodeStyleSetMaxHeight(mNativePointer, maxheight); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetMaxHeightJNI(mNativePointer, maxheight); + else + YogaNative.jni_YGNodeStyleSetMaxHeight(mNativePointer, maxheight); } public void setMaxHeightPercent(float percent) { - YogaNative.jni_YGNodeStyleSetMaxHeightPercent(mNativePointer, percent); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetMaxHeightPercentJNI(mNativePointer, percent); + else + YogaNative.jni_YGNodeStyleSetMaxHeightPercent(mNativePointer, percent); } public float getAspectRatio() { 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 595fe20430..c042320872 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h index f0c489c1ae..d69fba4726 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h @@ -4,6 +4,8 @@ * This source code is licensed under the MIT license found in the LICENSE * file in the root directory of this source tree. */ +#include + namespace { union YGNodeContext { diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.cpp b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.cpp index c3f60160bc..86899508a0 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.cpp +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.cpp @@ -7,6 +7,7 @@ #include "jni.h" #include "YGJNIVanilla.h" #include +#include "YGJNI.h" static inline YGNodeRef _jlong2YGNodeRef(jlong addr) { return reinterpret_cast(static_cast(addr)); @@ -24,6 +25,32 @@ static inline YGNodeRef _jlong2YGNodeRef(jlong addr) { _jlong2YGNodeRef(nativePointer), static_cast(value)); \ } +#define YG_NODE_JNI_STYLE_UNIT_PROP(name) \ + static jlong jni_YGNodeStyleGet##name##JNI( \ + JNIEnv* env, jobject obj, jlong nativePointer) { \ + return YogaValue::asJavaLong( \ + YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \ + } \ + \ + static void jni_YGNodeStyleSet##name##JNI( \ + JNIEnv* env, jobject obj, jlong nativePointer, jfloat value) { \ + YGNodeStyleSet##name( \ + _jlong2YGNodeRef(nativePointer), static_cast(value)); \ + } \ + \ + static void jni_YGNodeStyleSet##name##PercentJNI( \ + JNIEnv* env, jobject obj, jlong nativePointer, jfloat value) { \ + YGNodeStyleSet##name##Percent( \ + _jlong2YGNodeRef(nativePointer), static_cast(value)); \ + } + +#define YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(name) \ + YG_NODE_JNI_STYLE_UNIT_PROP(name) \ + static void jni_YGNodeStyleSet##name##AutoJNI( \ + JNIEnv* env, jobject obj, jlong nativePointer) { \ + YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer)); \ + } + YG_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction); YG_NODE_JNI_STYLE_PROP(jint, YGFlexDirection, FlexDirection); YG_NODE_JNI_STYLE_PROP(jint, YGJustify, JustifyContent); @@ -38,6 +65,14 @@ YG_NODE_JNI_STYLE_PROP(jfloat, float, Flex); YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexGrow); YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink); +YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(FlexBasis); +YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(Width); +YG_NODE_JNI_STYLE_UNIT_PROP(MinWidth); +YG_NODE_JNI_STYLE_UNIT_PROP(MaxWidth); +YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(Height); +YG_NODE_JNI_STYLE_UNIT_PROP(MinHeight); +YG_NODE_JNI_STYLE_UNIT_PROP(MaxHeight); + // Yoga specific properties, not compatible with flexbox specification YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio); @@ -138,6 +173,74 @@ static JNINativeMethod methods[] = { {"jni_YGNodeStyleSetFlexShrinkJNI", "(JF)V", (void*) jni_YGNodeStyleSetFlexShrinkJNI}, + {"jni_YGNodeStyleGetFlexBasisJNI", + "(J)J", + (void*) jni_YGNodeStyleGetFlexBasisJNI}, + {"jni_YGNodeStyleSetFlexBasisJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetFlexBasisJNI}, + {"jni_YGNodeStyleSetFlexBasisPercentJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetFlexBasisPercentJNI}, + {"jni_YGNodeStyleSetFlexBasisAutoJNI", + "(J)V", + (void*) jni_YGNodeStyleSetFlexBasisAutoJNI}, + {"jni_YGNodeStyleGetWidthJNI", "(J)J", (void*) jni_YGNodeStyleGetWidthJNI}, + {"jni_YGNodeStyleSetWidthJNI", "(JF)V", (void*) jni_YGNodeStyleSetWidthJNI}, + {"jni_YGNodeStyleSetWidthPercentJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetWidthPercentJNI}, + {"jni_YGNodeStyleSetWidthAutoJNI", + "(J)V", + (void*) jni_YGNodeStyleSetWidthAutoJNI}, + {"jni_YGNodeStyleGetHeightJNI", + "(J)J", + (void*) jni_YGNodeStyleGetHeightJNI}, + {"jni_YGNodeStyleSetHeightJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetHeightJNI}, + {"jni_YGNodeStyleSetHeightPercentJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetHeightPercentJNI}, + {"jni_YGNodeStyleSetHeightAutoJNI", + "(J)V", + (void*) jni_YGNodeStyleSetHeightAutoJNI}, + {"jni_YGNodeStyleGetMinWidthJNI", + "(J)J", + (void*) jni_YGNodeStyleGetMinWidthJNI}, + {"jni_YGNodeStyleSetMinWidthJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetMinWidthJNI}, + {"jni_YGNodeStyleSetMinWidthPercentJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetMinWidthPercentJNI}, + {"jni_YGNodeStyleGetMinHeightJNI", + "(J)J", + (void*) jni_YGNodeStyleGetMinHeightJNI}, + {"jni_YGNodeStyleSetMinHeightJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetMinHeightJNI}, + {"jni_YGNodeStyleSetMinHeightPercentJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetMinHeightPercentJNI}, + {"jni_YGNodeStyleGetMaxWidthJNI", + "(J)J", + (void*) jni_YGNodeStyleGetMaxWidthJNI}, + {"jni_YGNodeStyleSetMaxWidthJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetMaxWidthJNI}, + {"jni_YGNodeStyleSetMaxWidthPercentJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetMaxWidthPercentJNI}, + {"jni_YGNodeStyleGetMaxHeightJNI", + "(J)J", + (void*) jni_YGNodeStyleGetMaxHeightJNI}, + {"jni_YGNodeStyleSetMaxHeightJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetMaxHeightJNI}, + {"jni_YGNodeStyleSetMaxHeightPercentJNI", + "(JF)V", + (void*) jni_YGNodeStyleSetMaxHeightPercentJNI}, {"jni_YGNodeStyleGetAspectRatioJNI", "(J)F", (void*) jni_YGNodeStyleGetAspectRatioJNI},