From ae2d06d0f5056c5f28ef9732b00b9ca34a6e6c6c Mon Sep 17 00:00:00 2001 From: heoblitz Date: Mon, 9 Dec 2024 13:38:05 -0800 Subject: [PATCH] Update YGNodeStyleGetGap to return YGValue (#1753) Summary: X-link: https://github.com/facebook/react-native/pull/47973 Gap can be styled using both `points` and `percentages`, but YGNodeStyleGetGap currently returns a float value. To maintain alignment with the `padding` and `margin` functionalities and allow it to be handled in bridging code, this function has been updated to return YGValue. Pull Request resolved: https://github.com/facebook/yoga/pull/1753 Reviewed By: joevilches Differential Revision: D66513236 Pulled By: NickGerleman fbshipit-source-id: b7110855c037f20780f031f22a945bde4446687d --- capture/NodeToString.cpp | 6 +++--- java/com/facebook/yoga/YogaNative.java | 2 +- java/com/facebook/yoga/YogaNode.java | 2 +- java/com/facebook/yoga/YogaNodeJNIBase.java | 4 ++-- java/jni/YGJNIVanilla.cpp | 8 ++++---- javascript/src/Node.cpp | 5 +++-- javascript/src/Node.h | 2 +- yoga/YGNodeStyle.cpp | 9 ++------- yoga/YGNodeStyle.h | 2 +- 9 files changed, 18 insertions(+), 22 deletions(-) diff --git a/capture/NodeToString.cpp b/capture/NodeToString.cpp index 87065277f5..2f4cd32762 100644 --- a/capture/NodeToString.cpp +++ b/capture/NodeToString.cpp @@ -225,17 +225,17 @@ static void serializeTreeImpl( appendEdges<&YGNodeStyleGetPosition>( j, "position", node, defaultNode.get()); - appendFloatIfNotDefault( + appendYGValueIfNotDefault( j["style"], "gap", YGNodeStyleGetGap(node, YGGutterAll), YGNodeStyleGetGap(defaultNode.get(), YGGutterAll)); - appendFloatIfNotDefault( + appendYGValueIfNotDefault( j["style"], "column-gap", YGNodeStyleGetGap(node, YGGutterColumn), YGNodeStyleGetGap(defaultNode.get(), YGGutterColumn)); - appendFloatIfNotDefault( + appendYGValueIfNotDefault( j["style"], "row-gap", YGNodeStyleGetGap(node, YGGutterRow), diff --git a/java/com/facebook/yoga/YogaNative.java b/java/com/facebook/yoga/YogaNative.java index 582bd1eb19..8d23257a69 100644 --- a/java/com/facebook/yoga/YogaNative.java +++ b/java/com/facebook/yoga/YogaNative.java @@ -130,7 +130,7 @@ public class YogaNative { static native void jni_YGNodeStyleSetMaxHeightStretchJNI(long nativePointer); static native float jni_YGNodeStyleGetAspectRatioJNI(long nativePointer); static native void jni_YGNodeStyleSetAspectRatioJNI(long nativePointer, float aspectRatio); - static native float jni_YGNodeStyleGetGapJNI(long nativePointer, int gutter); + static native long jni_YGNodeStyleGetGapJNI(long nativePointer, int gutter); static native void jni_YGNodeStyleSetGapJNI(long nativePointer, int gutter, float gapLength); static native void jni_YGNodeStyleSetGapPercentJNI(long nativePointer, int gutter, float gapLength); static native void jni_YGNodeSetHasMeasureFuncJNI(long nativePointer, boolean hasMeasureFunc); diff --git a/java/com/facebook/yoga/YogaNode.java b/java/com/facebook/yoga/YogaNode.java index b683b553ca..18f2914aeb 100644 --- a/java/com/facebook/yoga/YogaNode.java +++ b/java/com/facebook/yoga/YogaNode.java @@ -236,7 +236,7 @@ public interface Inputs { public abstract void setAspectRatio(float aspectRatio); - public abstract float getGap(YogaGutter gutter); + public abstract YogaValue getGap(YogaGutter gutter); public abstract void setGap(YogaGutter gutter, float gapLength); diff --git a/java/com/facebook/yoga/YogaNodeJNIBase.java b/java/com/facebook/yoga/YogaNodeJNIBase.java index e25872545e..38c2f93a31 100644 --- a/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -811,8 +811,8 @@ public void markLayoutSeen() { } @Override - public float getGap(YogaGutter gutter) { - return YogaNative.jni_YGNodeStyleGetGapJNI(mNativePointer, gutter.intValue()); + public YogaValue getGap(YogaGutter gutter) { + return valueFromLong(YogaNative.jni_YGNodeStyleGetGapJNI(mNativePointer, gutter.intValue())); } @Override diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index 95273836c2..e164c96c38 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -725,13 +725,13 @@ jni_YGNodeCloneJNI(JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer) { return reinterpret_cast(clonedYogaNode); } -static jfloat jni_YGNodeStyleGetGapJNI( +static jlong jni_YGNodeStyleGetGapJNI( JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer, jint gutter) { - return (jfloat)YGNodeStyleGetGap( - _jlong2YGNodeRef(nativePointer), static_cast(gutter)); + return YogaValue::asJavaLong(YGNodeStyleGetGap( + _jlong2YGNodeRef(nativePointer), static_cast(gutter))); } static void jni_YGNodeStyleSetGapJNI( @@ -1057,7 +1057,7 @@ static JNINativeMethod methods[] = { {"jni_YGNodeSetHasMeasureFuncJNI", "(JZ)V", (void*)jni_YGNodeSetHasMeasureFuncJNI}, - {"jni_YGNodeStyleGetGapJNI", "(JI)F", (void*)jni_YGNodeStyleGetGapJNI}, + {"jni_YGNodeStyleGetGapJNI", "(JI)J", (void*)jni_YGNodeStyleGetGapJNI}, {"jni_YGNodeStyleSetGapJNI", "(JIF)V", (void*)jni_YGNodeStyleSetGapJNI}, {"jni_YGNodeStyleSetGapPercentJNI", "(JIF)V", diff --git a/javascript/src/Node.cpp b/javascript/src/Node.cpp index 5284ddb5b0..42f6d82f63 100644 --- a/javascript/src/Node.cpp +++ b/javascript/src/Node.cpp @@ -439,8 +439,9 @@ Value Node::getPadding(int edge) const { YGNodeStyleGetPadding(m_node, static_cast(edge))); } -float Node::getGap(int gutter) { - return YGNodeStyleGetGap(m_node, static_cast(gutter)); +Value Node::getGap(int gutter) const { + return Value::fromYGValue( + YGNodeStyleGetGap(m_node, static_cast(gutter))); } bool Node::isReferenceBaseline() { diff --git a/javascript/src/Node.h b/javascript/src/Node.h index 0ed4d1d416..e101b436db 100644 --- a/javascript/src/Node.h +++ b/javascript/src/Node.h @@ -186,7 +186,7 @@ class Node { Value getPadding(int edge) const; - float getGap(int gutter); + Value getGap(int gutter) const; int getBoxSizing(void) const; diff --git a/yoga/YGNodeStyle.cpp b/yoga/YGNodeStyle.cpp index 3f1be42e46..4e77405b6c 100644 --- a/yoga/YGNodeStyle.cpp +++ b/yoga/YGNodeStyle.cpp @@ -293,13 +293,8 @@ void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) { node, scopedEnum(gutter), StyleLength::percent(percent)); } -float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) { - auto gapLength = resolveRef(node)->style().gap(scopedEnum(gutter)); - if (gapLength.isUndefined() || gapLength.isAuto()) { - return YGUndefined; - } - - return static_cast(gapLength).value; +YGValue YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) { + return (YGValue)resolveRef(node)->style().gap(scopedEnum(gutter)); } void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) { diff --git a/yoga/YGNodeStyle.h b/yoga/YGNodeStyle.h index a971138bb9..21b8326d85 100644 --- a/yoga/YGNodeStyle.h +++ b/yoga/YGNodeStyle.h @@ -96,7 +96,7 @@ YG_EXPORT void YGNodeStyleSetGap(YGNodeRef node, YGGutter gutter, float gapLength); YG_EXPORT void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float gapLength); -YG_EXPORT float YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter); +YG_EXPORT YGValue YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter); YG_EXPORT void YGNodeStyleSetBoxSizing(YGNodeRef node, YGBoxSizing boxSizing); YG_EXPORT YGBoxSizing YGNodeStyleGetBoxSizing(YGNodeConstRef node);