From 4692e97ba078d224f6606577ffa029617f642bd8 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 27 Apr 2023 06:48:04 -0700 Subject: [PATCH] Add Java bindings for Errata API (#37096) Summary: X-link: https://github.com/facebook/react-native/pull/37096 Pull Request resolved: https://github.com/facebook/yoga/pull/1263 JNI glue to expose `YogaConfig.setErrata()` and `YogaConfig.getErrata()`. Reviewed By: yungsters Differential Revision: D45296538 fbshipit-source-id: 8d743d278b7df43f7843a79d8f4542bfb03fc08d --- java/com/facebook/yoga/YogaConfig.java | 4 ++++ java/com/facebook/yoga/YogaConfigJNIBase.java | 8 ++++++++ java/com/facebook/yoga/YogaNative.java | 2 ++ java/jni/YGJNIVanilla.cpp | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/java/com/facebook/yoga/YogaConfig.java b/java/com/facebook/yoga/YogaConfig.java index ec96a963..87928f02 100644 --- a/java/com/facebook/yoga/YogaConfig.java +++ b/java/com/facebook/yoga/YogaConfig.java @@ -25,6 +25,10 @@ public abstract class YogaConfig { */ public abstract void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour); + public abstract void setErrata(YogaErrata errata); + + public abstract YogaErrata getErrata(); + public abstract void setLogger(YogaLogger logger); public abstract YogaLogger getLogger(); diff --git a/java/com/facebook/yoga/YogaConfigJNIBase.java b/java/com/facebook/yoga/YogaConfigJNIBase.java index 62a740ef..bbe526d7 100644 --- a/java/com/facebook/yoga/YogaConfigJNIBase.java +++ b/java/com/facebook/yoga/YogaConfigJNIBase.java @@ -52,6 +52,14 @@ public abstract class YogaConfigJNIBase extends YogaConfig { YogaNative.jni_YGConfigSetUseLegacyStretchBehaviourJNI(mNativePointer, useLegacyStretchBehaviour); } + public void setErrata(YogaErrata errata) { + YogaNative.jni_YGConfigSetErrataJNI(mNativePointer, errata.intValue()); + } + + public YogaErrata getErrata() { + return YogaErrata.fromInt(YogaNative.jni_YGConfigGetErrataJNI(mNativePointer)); + } + public void setLogger(YogaLogger logger) { mLogger = logger; YogaNative.jni_YGConfigSetLoggerJNI(mNativePointer, logger); diff --git a/java/com/facebook/yoga/YogaNative.java b/java/com/facebook/yoga/YogaNative.java index 934602d8..524a93b3 100644 --- a/java/com/facebook/yoga/YogaNative.java +++ b/java/com/facebook/yoga/YogaNative.java @@ -25,6 +25,8 @@ public class YogaNative { static native void jni_YGConfigSetPrintTreeFlagJNI(long nativePointer, boolean enable); static native void jni_YGConfigSetPointScaleFactorJNI(long nativePointer, float pixelsInPoint); static native void jni_YGConfigSetUseLegacyStretchBehaviourJNI(long nativePointer, boolean useLegacyStretchBehaviour); + static native void jni_YGConfigSetErrataJNI(long nativePointer, int errata); + static native int jni_YGConfigGetErrataJNI(long nativePointer); static native void jni_YGConfigSetLoggerJNI(long nativePointer, YogaLogger logger); // YGNode related diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index b6ef83be..3a30cdf0 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -105,6 +105,23 @@ static void jni_YGConfigSetUseLegacyStretchBehaviourJNI( YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour); } +static void jni_YGConfigSetErrataJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer, + jint errata) { + const YGConfigRef config = _jlong2YGConfigRef(nativePointer); + YGConfigSetErrata(config, static_cast(errata)); +} + +static jint jni_YGConfigGetErrataJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer) { + const YGConfigRef config = _jlong2YGConfigRef(nativePointer); + return static_cast(YGConfigGetErrata(config)); +} + static jlong jni_YGNodeNewJNI(JNIEnv* env, jobject obj) { const YGNodeRef node = YGNodeNew(); node->setContext(YGNodeContext{}.asVoidPtr); @@ -764,6 +781,8 @@ static JNINativeMethod methods[] = { {"jni_YGConfigSetUseLegacyStretchBehaviourJNI", "(JZ)V", (void*) jni_YGConfigSetUseLegacyStretchBehaviourJNI}, + {"jni_YGConfigSetErrataJNI", "(JI)V", (void*) jni_YGConfigSetErrataJNI}, + {"jni_YGConfigGetErrataJNI", "(J)I", (void*) jni_YGConfigGetErrataJNI}, {"jni_YGConfigSetLoggerJNI", "(JLcom/facebook/yoga/YogaLogger;)V", (void*) jni_YGConfigSetLoggerJNI},