Move style properties which accept one parameter to vanilla JNI (YogaStyleProperties Part 1)

Summary: Move Yoga style properties to vanilla JNI under a flag.

Reviewed By: amir-shalem

Differential Revision: D17666048

fbshipit-source-id: 6565acd35ab04ef0c3a2544447a25dc6edc3e7a5
This commit is contained in:
Sidharth Guglani
2019-10-08 14:23:57 -07:00
committed by Facebook Github Bot
parent c37f5956e4
commit 32a973ebd1
3 changed files with 199 additions and 27 deletions

View File

@@ -114,5 +114,31 @@ public class YogaNative {
// JNI methods that use Vanilla JNI
static native int jni_YGNodeStyleGetDirectionJNI(long nativePointer);
static native void jni_YGNodeStyleSetDirectionJNI(long nativePointer, int direction);
static native int jni_YGNodeStyleGetFlexDirectionJNI(long nativePointer);
static native void jni_YGNodeStyleSetFlexDirectionJNI(long nativePointer, int flexDirection);
static native int jni_YGNodeStyleGetJustifyContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetJustifyContentJNI(long nativePointer, int justifyContent);
static native int jni_YGNodeStyleGetAlignItemsJNI(long nativePointer);
static native void jni_YGNodeStyleSetAlignItemsJNI(long nativePointer, int alignItems);
static native int jni_YGNodeStyleGetAlignSelfJNI(long nativePointer);
static native void jni_YGNodeStyleSetAlignSelfJNI(long nativePointer, int alignSelf);
static native int jni_YGNodeStyleGetAlignContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetAlignContentJNI(long nativePointer, int alignContent);
static native int jni_YGNodeStyleGetPositionTypeJNI(long nativePointer);
static native void jni_YGNodeStyleSetPositionTypeJNI(long nativePointer, int positionType);
static native int jni_YGNodeStyleGetFlexWrapJNI(long nativePointer);
static native void jni_YGNodeStyleSetFlexWrapJNI(long nativePointer, int wrapType);
static native int jni_YGNodeStyleGetOverflowJNI(long nativePointer);
static native void jni_YGNodeStyleSetOverflowJNI(long nativePointer, int overflow);
static native int jni_YGNodeStyleGetDisplayJNI(long nativePointer);
static native void jni_YGNodeStyleSetDisplayJNI(long nativePointer, int display);
public static native void jni_YGNodeStyleSetFlexJNI(long nativePointer, float flex);
static native float jni_YGNodeStyleGetFlexGrowJNI(long nativePointer);
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 float jni_YGNodeStyleGetAspectRatioJNI(long nativePointer);
static native void jni_YGNodeStyleSetAspectRatioJNI(long nativePointer, float aspectRatio);
}

View File

@@ -203,83 +203,113 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
}
public YogaDirection getStyleDirection() {
return YogaDirection.fromInt(YogaNative.jni_YGNodeStyleGetDirection(mNativePointer));
return YogaDirection.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetDirectionJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetDirection(mNativePointer));
}
public void setDirection(YogaDirection direction) {
YogaNative.jni_YGNodeStyleSetDirection(mNativePointer, direction.intValue());
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetDirectionJNI(mNativePointer, direction.intValue());
else
YogaNative.jni_YGNodeStyleSetDirection(mNativePointer, direction.intValue());
}
public YogaFlexDirection getFlexDirection() {
return YogaFlexDirection.fromInt(YogaNative.jni_YGNodeStyleGetFlexDirection(mNativePointer));
return YogaFlexDirection.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetFlexDirectionJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetFlexDirection(mNativePointer));
}
public void setFlexDirection(YogaFlexDirection flexDirection) {
YogaNative.jni_YGNodeStyleSetFlexDirection(mNativePointer, flexDirection.intValue());
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetFlexDirectionJNI(mNativePointer, flexDirection.intValue());
else
YogaNative.jni_YGNodeStyleSetFlexDirection(mNativePointer, flexDirection.intValue());
}
public YogaJustify getJustifyContent() {
return YogaJustify.fromInt(YogaNative.jni_YGNodeStyleGetJustifyContent(mNativePointer));
return YogaJustify.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetJustifyContentJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetJustifyContent(mNativePointer));
}
public void setJustifyContent(YogaJustify justifyContent) {
YogaNative.jni_YGNodeStyleSetJustifyContent(mNativePointer, justifyContent.intValue());
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetJustifyContentJNI(mNativePointer, justifyContent.intValue());
else
YogaNative.jni_YGNodeStyleSetJustifyContent(mNativePointer, justifyContent.intValue());
}
public YogaAlign getAlignItems() {
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignItems(mNativePointer));
return YogaAlign.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetAlignItemsJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetAlignItems(mNativePointer));
}
public void setAlignItems(YogaAlign alignItems) {
YogaNative.jni_YGNodeStyleSetAlignItems(mNativePointer, alignItems.intValue());
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetAlignItemsJNI(mNativePointer, alignItems.intValue());
else
YogaNative.jni_YGNodeStyleSetAlignItems(mNativePointer, alignItems.intValue());
}
public YogaAlign getAlignSelf() {
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignSelf(mNativePointer));
return YogaAlign.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetAlignSelfJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetAlignSelf(mNativePointer));
}
public void setAlignSelf(YogaAlign alignSelf) {
YogaNative.jni_YGNodeStyleSetAlignSelf(mNativePointer, alignSelf.intValue());
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetAlignSelfJNI(mNativePointer, alignSelf.intValue());
else
YogaNative.jni_YGNodeStyleSetAlignSelf(mNativePointer, alignSelf.intValue());
}
public YogaAlign getAlignContent() {
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignContent(mNativePointer));
return YogaAlign.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetAlignContentJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetAlignContent(mNativePointer));
}
public void setAlignContent(YogaAlign alignContent) {
YogaNative.jni_YGNodeStyleSetAlignContent(mNativePointer, alignContent.intValue());
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetAlignContentJNI(mNativePointer, alignContent.intValue());
else
YogaNative.jni_YGNodeStyleSetAlignContent(mNativePointer, alignContent.intValue());
}
public YogaPositionType getPositionType() {
return YogaPositionType.fromInt(YogaNative.jni_YGNodeStyleGetPositionType(mNativePointer));
return YogaPositionType.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetPositionTypeJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetPositionType(mNativePointer));
}
public void setPositionType(YogaPositionType positionType) {
YogaNative.jni_YGNodeStyleSetPositionType(mNativePointer, positionType.intValue());
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetPositionTypeJNI(mNativePointer, positionType.intValue());
else
YogaNative.jni_YGNodeStyleSetPositionType(mNativePointer, positionType.intValue());
}
public YogaWrap getWrap() {
return YogaWrap.fromInt(YogaNative.jni_YGNodeStyleGetFlexWrap(mNativePointer));
return YogaWrap.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetFlexWrapJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetFlexWrap(mNativePointer));
}
public void setWrap(YogaWrap flexWrap) {
YogaNative.jni_YGNodeStyleSetFlexWrap(mNativePointer, flexWrap.intValue());
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetFlexWrapJNI(mNativePointer, flexWrap.intValue());
else
YogaNative.jni_YGNodeStyleSetFlexWrap(mNativePointer, flexWrap.intValue());
}
public YogaOverflow getOverflow() {
return YogaOverflow.fromInt(YogaNative.jni_YGNodeStyleGetOverflow(mNativePointer));
return YogaOverflow.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetOverflowJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetOverflow(mNativePointer));
}
public void setOverflow(YogaOverflow overflow) {
YogaNative.jni_YGNodeStyleSetOverflow(mNativePointer, overflow.intValue());
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetOverflowJNI(mNativePointer, overflow.intValue());
else
YogaNative.jni_YGNodeStyleSetOverflow(mNativePointer, overflow.intValue());
}
public YogaDisplay getDisplay() {
return YogaDisplay.fromInt(YogaNative.jni_YGNodeStyleGetDisplay(mNativePointer));
return YogaDisplay.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetDisplayJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetDisplay(mNativePointer));
}
public void setDisplay(YogaDisplay display) {
YogaNative.jni_YGNodeStyleSetDisplay(mNativePointer, display.intValue());
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetDisplayJNI(mNativePointer, display.intValue());
else
YogaNative.jni_YGNodeStyleSetDisplay(mNativePointer, display.intValue());
}
public float getFlex() {
@@ -295,19 +325,25 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
}
public float getFlexGrow() {
return YogaNative.jni_YGNodeStyleGetFlexGrow(mNativePointer);
return useVanillaJNI ? YogaNative.jni_YGNodeStyleGetFlexGrowJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetFlexGrow(mNativePointer);
}
public void setFlexGrow(float flexGrow) {
YogaNative.jni_YGNodeStyleSetFlexGrow(mNativePointer, flexGrow);
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetFlexGrowJNI(mNativePointer, flexGrow);
else
YogaNative.jni_YGNodeStyleSetFlexGrow(mNativePointer, flexGrow);
}
public float getFlexShrink() {
return YogaNative.jni_YGNodeStyleGetFlexShrink(mNativePointer);
return useVanillaJNI ? YogaNative.jni_YGNodeStyleGetFlexShrinkJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetFlexShrink(mNativePointer);
}
public void setFlexShrink(float flexShrink) {
YogaNative.jni_YGNodeStyleSetFlexShrink(mNativePointer, flexShrink);
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetFlexShrinkJNI(mNativePointer, flexShrink);
else
YogaNative.jni_YGNodeStyleSetFlexShrink(mNativePointer, flexShrink);
}
public YogaValue getFlexBasis() {
@@ -455,11 +491,14 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
}
public float getAspectRatio() {
return YogaNative.jni_YGNodeStyleGetAspectRatio(mNativePointer);
return useVanillaJNI ? YogaNative.jni_YGNodeStyleGetAspectRatioJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetAspectRatio(mNativePointer);
}
public void setAspectRatio(float aspectRatio) {
YogaNative.jni_YGNodeStyleSetAspectRatio(mNativePointer, aspectRatio);
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetAspectRatioJNI(mNativePointer, aspectRatio);
else
YogaNative.jni_YGNodeStyleSetAspectRatio(mNativePointer, aspectRatio);
}
public void setMeasureFunction(YogaMeasureFunction measureFunction) {

View File

@@ -12,6 +12,31 @@ static inline YGNodeRef _jlong2YGNodeRef(jlong addr) {
return reinterpret_cast<YGNodeRef>(static_cast<intptr_t>(addr));
}
#define YG_NODE_JNI_STYLE_PROP(javatype, type, name) \
static javatype jni_YGNodeStyleGet##name##JNI( \
JNIEnv* env, jobject obj, jlong nativePointer) { \
return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer)); \
} \
\
static void jni_YGNodeStyleSet##name##JNI( \
JNIEnv* env, jobject obj, jlong nativePointer, javatype value) { \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), static_cast<type>(value)); \
}
YG_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction);
YG_NODE_JNI_STYLE_PROP(jint, YGFlexDirection, FlexDirection);
YG_NODE_JNI_STYLE_PROP(jint, YGJustify, JustifyContent);
YG_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignItems);
YG_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignSelf);
YG_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignContent);
YG_NODE_JNI_STYLE_PROP(jint, YGPositionType, PositionType);
YG_NODE_JNI_STYLE_PROP(jint, YGWrap, FlexWrap);
YG_NODE_JNI_STYLE_PROP(jint, YGOverflow, Overflow);
YG_NODE_JNI_STYLE_PROP(jint, YGDisplay, Display);
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexGrow);
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink);
void jni_YGNodeStyleSetFlexJNI(
JNIEnv* env,
jobject obj,
@@ -21,6 +46,9 @@ void jni_YGNodeStyleSetFlexJNI(
_jlong2YGNodeRef(nativePointer), static_cast<float>(value));
}
// Yoga specific properties, not compatible with flexbox specification
YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio);
void assertNoPendingJniException(JNIEnv* env) {
// This method cannot call any other method of the library, since other
// methods of the library use it to check for exceptions too
@@ -44,7 +72,86 @@ void registerNativeMethods(
}
static JNINativeMethod methods[] = {
{"jni_YGNodeStyleSetFlexJNI", "(JF)V", (void*) jni_YGNodeStyleSetFlexJNI}};
{"jni_YGNodeStyleSetFlexJNI", "(JF)V", (void*) jni_YGNodeStyleSetFlexJNI},
{"jni_YGNodeStyleGetDirectionJNI",
"(J)I",
(void*) jni_YGNodeStyleGetDirectionJNI},
{"jni_YGNodeStyleSetDirectionJNI",
"(JI)V",
(void*) jni_YGNodeStyleSetDirectionJNI},
{"jni_YGNodeStyleGetFlexDirectionJNI",
"(J)I",
(void*) jni_YGNodeStyleGetFlexDirectionJNI},
{"jni_YGNodeStyleSetFlexDirectionJNI",
"(JI)V",
(void*) jni_YGNodeStyleSetFlexDirectionJNI},
{"jni_YGNodeStyleGetJustifyContentJNI",
"(J)I",
(void*) jni_YGNodeStyleGetJustifyContentJNI},
{"jni_YGNodeStyleSetJustifyContentJNI",
"(JI)V",
(void*) jni_YGNodeStyleSetJustifyContentJNI},
{"jni_YGNodeStyleGetAlignItemsJNI",
"(J)I",
(void*) jni_YGNodeStyleGetAlignItemsJNI},
{"jni_YGNodeStyleSetAlignItemsJNI",
"(JI)V",
(void*) jni_YGNodeStyleSetAlignItemsJNI},
{"jni_YGNodeStyleGetAlignSelfJNI",
"(J)I",
(void*) jni_YGNodeStyleGetAlignSelfJNI},
{"jni_YGNodeStyleSetAlignSelfJNI",
"(JI)V",
(void*) jni_YGNodeStyleSetAlignSelfJNI},
{"jni_YGNodeStyleGetAlignContentJNI",
"(J)I",
(void*) jni_YGNodeStyleGetAlignContentJNI},
{"jni_YGNodeStyleSetAlignContentJNI",
"(JI)V",
(void*) jni_YGNodeStyleSetAlignContentJNI},
{"jni_YGNodeStyleGetPositionTypeJNI",
"(J)I",
(void*) jni_YGNodeStyleGetPositionTypeJNI},
{"jni_YGNodeStyleSetPositionTypeJNI",
"(JI)V",
(void*) jni_YGNodeStyleSetPositionTypeJNI},
{"jni_YGNodeStyleGetFlexWrapJNI",
"(J)I",
(void*) jni_YGNodeStyleGetFlexWrapJNI},
{"jni_YGNodeStyleSetFlexWrapJNI",
"(JI)V",
(void*) jni_YGNodeStyleSetFlexWrapJNI},
{"jni_YGNodeStyleGetOverflowJNI",
"(J)I",
(void*) jni_YGNodeStyleGetOverflowJNI},
{"jni_YGNodeStyleSetOverflowJNI",
"(JI)V",
(void*) jni_YGNodeStyleSetOverflowJNI},
{"jni_YGNodeStyleGetDisplayJNI",
"(J)I",
(void*) jni_YGNodeStyleGetDisplayJNI},
{"jni_YGNodeStyleSetDisplayJNI",
"(JI)V",
(void*) jni_YGNodeStyleSetDisplayJNI},
{"jni_YGNodeStyleGetFlexGrowJNI",
"(J)F",
(void*) jni_YGNodeStyleGetFlexGrowJNI},
{"jni_YGNodeStyleSetFlexGrowJNI",
"(JF)V",
(void*) jni_YGNodeStyleSetFlexGrowJNI},
{"jni_YGNodeStyleGetFlexShrinkJNI",
"(J)F",
(void*) jni_YGNodeStyleGetFlexShrinkJNI},
{"jni_YGNodeStyleSetFlexShrinkJNI",
"(JF)V",
(void*) jni_YGNodeStyleSetFlexShrinkJNI},
{"jni_YGNodeStyleGetAspectRatioJNI",
"(J)F",
(void*) jni_YGNodeStyleGetAspectRatioJNI},
{"jni_YGNodeStyleSetAspectRatioJNI",
"(JF)V",
(void*) jni_YGNodeStyleSetAspectRatioJNI},
};
void YGJNIVanilla::registerNatives(JNIEnv* env) {
registerNativeMethods(