Skip to content

Commit

Permalink
Expose Gap Percentage to ReactNative
Browse files Browse the repository at this point in the history
Summary:
Expose the Gap Percent from Yoga to RN Layer

Changelog: [Internal]
- Enable flex gap percentage value for RN.

Differential Revision: D56160597
  • Loading branch information
realsoelynn authored and facebook-github-bot committed Apr 17, 2024
1 parent cd4a1b8 commit ab09d82
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions java/com/facebook/yoga/YogaNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class YogaNative {
static native float 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_YGNodeStyleSetGapAutoJNI(long nativePointer, int gutter);
static native void jni_YGNodeSetHasMeasureFuncJNI(long nativePointer, boolean hasMeasureFunc);
static native void jni_YGNodeSetHasBaselineFuncJNI(long nativePointer, boolean hasMeasureFunc);
static native void jni_YGNodeSetStyleInputsJNI(long nativePointer, float[] styleInputsArray, int size);
Expand Down
2 changes: 2 additions & 0 deletions java/com/facebook/yoga/YogaNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public interface Inputs {

public abstract void setGapPercent(YogaGutter gutter, float gapLength);

public abstract void setGapAuto(YogaGutter gutter);

public abstract float getLayoutX();

public abstract float getLayoutY();
Expand Down
5 changes: 5 additions & 0 deletions java/com/facebook/yoga/YogaNodeJNIBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -726,4 +726,9 @@ public void setGap(YogaGutter gutter, float gapLength) {
public void setGapPercent(YogaGutter gutter, float gapLength) {
YogaNative.jni_YGNodeStyleSetGapPercentJNI(mNativePointer, gutter.intValue(), gapLength);
}

@Override
public void setGapAuto(YogaGutter gutter) {
YogaNative.jni_YGNodeStyleSetGapAutoJNI(mNativePointer, gutter.intValue());
}
}
12 changes: 12 additions & 0 deletions java/jni/YGJNIVanilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,15 @@ static void jni_YGNodeStyleSetGapPercentJNI(
static_cast<float>(gapLength));
}

static void jni_YGNodeStyleSetGapAutoJNI(
JNIEnv* /*env*/,
jobject /*obj*/,
jlong nativePointer,
jint gutter) {
YGNodeStyleSetGapAuto(
_jlong2YGNodeRef(nativePointer), static_cast<YGGutter>(gutter));
}

// Yoga specific properties, not compatible with flexbox specification
YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio);

Expand Down Expand Up @@ -959,6 +968,9 @@ static JNINativeMethod methods[] = {
{"jni_YGNodeStyleSetGapPercentJNI",
"(JIF)V",
(void*)jni_YGNodeStyleSetGapPercentJNI},
{"jni_YGNodeStyleSetGapAutoJNI",
"(JI)V",
(void*)jni_YGNodeStyleSetGapAutoJNI},
{"jni_YGNodeSetHasBaselineFuncJNI",
"(JZ)V",
(void*)jni_YGNodeSetHasBaselineFuncJNI},
Expand Down
5 changes: 5 additions & 0 deletions yoga/YGNodeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ void YGNodeStyleSetGap(
node, scopedEnum(gutter), value::points(gapLength));
}

void YGNodeStyleSetGapAuto(YGNodeRef node, YGGutter gutter) {
updateStyle<&Style::gap, &Style::setGap>(
node, scopedEnum(gutter), value::ofAuto());
}

void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) {
updateStyle<&Style::gap, &Style::setGap>(
node, scopedEnum(gutter), value::percent(percent));
Expand Down
1 change: 1 addition & 0 deletions yoga/YGNodeStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ YG_EXPORT float YGNodeStyleGetBorder(YGNodeConstRef node, YGEdge edge);

YG_EXPORT void
YGNodeStyleSetGap(YGNodeRef node, YGGutter gutter, float gapLength);
YG_EXPORT void YGNodeStyleSetGapAuto(YGNodeRef node, YGGutter gutter);
YG_EXPORT void
YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float gapLength);
YG_EXPORT float YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter);
Expand Down

0 comments on commit ab09d82

Please sign in to comment.