Skip to content

Commit 3e4b31d

Browse files
realsoelynnfacebook-github-bot
authored andcommitted
Expose Gap Percentage to ReactNative (facebook#983)
Summary: X-link: facebook/react-native#44129 X-link: facebook/yoga#1647 Expose the Gap Percent from Yoga to RN Layer Changelog: [Internal] - Enable flex gap percentage value for RN. Differential Revision: D56160597
1 parent 46b76f4 commit 3e4b31d

6 files changed

Lines changed: 26 additions & 0 deletions

File tree

lib/yoga/src/main/cpp/yoga/YGNodeStyle.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ void YGNodeStyleSetGap(
267267
node, scopedEnum(gutter), value::points(gapLength));
268268
}
269269

270+
void YGNodeStyleSetGapAuto(YGNodeRef node, YGGutter gutter) {
271+
updateStyle<&Style::gap, &Style::setGap>(
272+
node, scopedEnum(gutter), value::ofAuto());
273+
}
274+
270275
void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) {
271276
updateStyle<&Style::gap, &Style::setGap>(
272277
node, scopedEnum(gutter), value::percent(percent));

lib/yoga/src/main/cpp/yoga/YGNodeStyle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ YG_EXPORT float YGNodeStyleGetBorder(YGNodeConstRef node, YGEdge edge);
8989

9090
YG_EXPORT void
9191
YGNodeStyleSetGap(YGNodeRef node, YGGutter gutter, float gapLength);
92+
YG_EXPORT void YGNodeStyleSetGapAuto(YGNodeRef node, YGGutter gutter);
9293
YG_EXPORT void
9394
YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float gapLength);
9495
YG_EXPORT float YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter);

lib/yoga/src/main/java/com/facebook/yoga/YogaNative.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public class YogaNative {
109109
static native float jni_YGNodeStyleGetGapJNI(long nativePointer, int gutter);
110110
static native void jni_YGNodeStyleSetGapJNI(long nativePointer, int gutter, float gapLength);
111111
static native void jni_YGNodeStyleSetGapPercentJNI(long nativePointer, int gutter, float gapLength);
112+
static native void jni_YGNodeStyleSetGapAutoJNI(long nativePointer, int gutter);
112113
static native void jni_YGNodeSetHasMeasureFuncJNI(long nativePointer, boolean hasMeasureFunc);
113114
static native void jni_YGNodeSetHasBaselineFuncJNI(long nativePointer, boolean hasMeasureFunc);
114115
static native void jni_YGNodeSetStyleInputsJNI(long nativePointer, float[] styleInputsArray, int size);

lib/yoga/src/main/java/com/facebook/yoga/YogaNode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ public interface Inputs {
194194

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

197+
public abstract void setGapAuto(YogaGutter gutter);
198+
197199
public abstract float getLayoutX();
198200

199201
public abstract float getLayoutY();

lib/yoga/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,4 +726,9 @@ public void setGap(YogaGutter gutter, float gapLength) {
726726
public void setGapPercent(YogaGutter gutter, float gapLength) {
727727
YogaNative.jni_YGNodeStyleSetGapPercentJNI(mNativePointer, gutter.intValue(), gapLength);
728728
}
729+
730+
@Override
731+
public void setGapAuto(YogaGutter gutter) {
732+
YogaNative.jni_YGNodeStyleSetGapAutoJNI(mNativePointer, gutter.intValue());
733+
}
729734
}

lib/yogajni/src/main/cpp/jni/YGJNIVanilla.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,15 @@ static void jni_YGNodeStyleSetGapPercentJNI(
727727
static_cast<float>(gapLength));
728728
}
729729

730+
static void jni_YGNodeStyleSetGapAutoJNI(
731+
JNIEnv* /*env*/,
732+
jobject /*obj*/,
733+
jlong nativePointer,
734+
jint gutter) {
735+
YGNodeStyleSetGapAuto(
736+
_jlong2YGNodeRef(nativePointer), static_cast<YGGutter>(gutter));
737+
}
738+
730739
// Yoga specific properties, not compatible with flexbox specification
731740
YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio);
732741

@@ -959,6 +968,9 @@ static JNINativeMethod methods[] = {
959968
{"jni_YGNodeStyleSetGapPercentJNI",
960969
"(JIF)V",
961970
(void*)jni_YGNodeStyleSetGapPercentJNI},
971+
{"jni_YGNodeStyleSetGapAutoJNI",
972+
"(JI)V",
973+
(void*)jni_YGNodeStyleSetGapAutoJNI},
962974
{"jni_YGNodeSetHasBaselineFuncJNI",
963975
"(JZ)V",
964976
(void*)jni_YGNodeSetHasBaselineFuncJNI},

0 commit comments

Comments
 (0)