Skip to content

Commit cd4a1b8

Browse files
realsoelynnfacebook-github-bot
authored andcommitted
Implement Percentage support for gap styles (#1643)
Summary: X-link: facebook/react-native#44067 X-link: facebook/litho#980 Pull Request resolved: #1643 Changelog [Internal]: - Added percentage value for flex layout gap - Wired up to pass proper available width and height to implement this feature Reviewed By: NickGerleman Differential Revision: D56002340 fbshipit-source-id: c0bc86ac70a1391f115c87da99c2ef411535f68b
1 parent d4247d6 commit cd4a1b8

18 files changed

Lines changed: 2933 additions & 13 deletions

File tree

gentest/fixtures/YGGapTest.html

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,72 @@
171171
<div style="height: 20px"></div>
172172
<div style="height: 30px"></div>
173173
</div>
174+
175+
<div id="row_gap_percent_wrapping" style="flex-direction: row; width: 300px; height: 700px; padding: 10px; gap: 10%; flex-wrap: wrap;">
176+
<div style="width: 100px; height: 100px;"></div>
177+
<div style="width: 100px; height: 100px;"></div>
178+
<div style="width: 100px; height: 100px;"></div>
179+
<div style="width: 100px; height: 100px;"></div>
180+
<div style="width: 100px; height: 100px;"></div>
181+
</div>
182+
183+
<div id="row_gap_percent_determines_parent_height" style="flex-direction: row; width: 300px; gap: 10%; flex-wrap: wrap;">
184+
<div style="width: 100px; height: 100px;"></div>
185+
<div style="width: 100px; height: 100px;"></div>
186+
<div style="width: 100px; height: 100px;"></div>
187+
<div style="width: 100px; height: 100px;"></div>
188+
<div style="width: 100px; height: 100px;"></div>
189+
</div>
190+
191+
<div id="row_gap_percent_wrapping_with_both_content_padding_and_item_padding" style="flex-direction: row; width: 300px; height: 700px; padding: 10px; gap: 10%; flex-wrap: wrap;">
192+
<div style="width: 100px; height: 100px; padding: 10px;"></div>
193+
<div style="width: 100px; height: 100px; padding: 10px;"></div>
194+
<div style="width: 100px; height: 100px; padding: 10px;"></div>
195+
<div style="width: 100px; height: 100px; padding: 10px;"></div>
196+
<div style="width: 100px; height: 100px; padding: 10px;"></div>
197+
</div>
198+
199+
<div id="row_gap_percent_wrapping_with_both_content_padding" style="flex-direction: row; width: 300px; height: 700px; padding: 10px; gap: 10%; flex-wrap: wrap;">
200+
<div style="width: 100px; height: 100px;"></div>
201+
<div style="width: 100px; height: 100px;"></div>
202+
<div style="width: 100px; height: 100px;"></div>
203+
<div style="width: 100px; height: 100px;"></div>
204+
<div style="width: 100px; height: 100px;"></div>
205+
</div>
206+
207+
<div id="row_gap_percent_wrapping_with_content_margin" style="flex-direction: row; width: 300px; height: 700px; margin: 10px; gap: 10%; flex-wrap: wrap;">
208+
<div style="width: 100px; height: 100px;"></div>
209+
<div style="width: 100px; height: 100px;"></div>
210+
<div style="width: 100px; height: 100px;"></div>
211+
<div style="width: 100px; height: 100px;"></div>
212+
<div style="width: 100px; height: 100px;"></div>
213+
</div>
214+
215+
<div id="row_gap_percent_wrapping_with_content_margin_and_padding" style="flex-direction: row; width: 300px; height: 700px; margin: 10px; padding: 10px; gap: 10%; flex-wrap: wrap;">
216+
<div style="width: 100px; height: 100px;"></div>
217+
<div style="width: 100px; height: 100px;"></div>
218+
<div style="width: 100px; height: 100px;"></div>
219+
<div style="width: 100px; height: 100px;"></div>
220+
<div style="width: 100px; height: 100px;"></div>
221+
</div>
222+
223+
<div id="row_gap_percent_wrapping_with_flexible_content" style="flex-direction: row; width: 300px; height: 300px; gap: 10%;">
224+
<div style="flex: 1;"></div>
225+
<div style="flex: 1;"></div>
226+
<div style="flex: 1;"></div>
227+
</div>
228+
229+
<div id="row_gap_percent_wrapping_with_mixed_flexible_content" style="flex-direction: row; width: 300px; height: 300px; gap: 10%;">
230+
<div style="width: 10px;"></div>
231+
<div style="flex: 1;"></div>
232+
<div style="width: 10%;"></div>
233+
</div>
234+
235+
<!-- TODO: Existing bug that Yoga is not inline with Chromium for calculation with min-width -->
236+
<div id="row_gap_percent_wrapping_with_min_width" data-disabled="true" style="flex-direction: row; min-width: 300px; gap: 10%; flex-wrap: wrap;">
237+
<div style="width: 100px; height: 100px;"></div>
238+
<div style="width: 100px; height: 100px;"></div>
239+
<div style="width: 100px; height: 100px;"></div>
240+
<div style="width: 100px; height: 100px;"></div>
241+
<div style="width: 100px; height: 100px;"></div>
242+
</div>

java/com/facebook/yoga/YogaNative.java

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

java/com/facebook/yoga/YogaNode.java

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

193193
public abstract void setGap(YogaGutter gutter, float gapLength);
194194

195+
public abstract void setGapPercent(YogaGutter gutter, float gapLength);
196+
195197
public abstract float getLayoutX();
196198

197199
public abstract float getLayoutY();

java/com/facebook/yoga/YogaNodeJNIBase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,4 +721,9 @@ public float getGap(YogaGutter gutter) {
721721
public void setGap(YogaGutter gutter, float gapLength) {
722722
YogaNative.jni_YGNodeStyleSetGapJNI(mNativePointer, gutter.intValue(), gapLength);
723723
}
724+
725+
@Override
726+
public void setGapPercent(YogaGutter gutter, float gapLength) {
727+
YogaNative.jni_YGNodeStyleSetGapPercentJNI(mNativePointer, gutter.intValue(), gapLength);
728+
}
724729
}

java/jni/YGJNIVanilla.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,18 @@ static void jni_YGNodeStyleSetGapJNI(
715715
static_cast<float>(gapLength));
716716
}
717717

718+
static void jni_YGNodeStyleSetGapPercentJNI(
719+
JNIEnv* /*env*/,
720+
jobject /*obj*/,
721+
jlong nativePointer,
722+
jint gutter,
723+
jfloat gapLength) {
724+
YGNodeStyleSetGapPercent(
725+
_jlong2YGNodeRef(nativePointer),
726+
static_cast<YGGutter>(gutter),
727+
static_cast<float>(gapLength));
728+
}
729+
718730
// Yoga specific properties, not compatible with flexbox specification
719731
YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio);
720732

@@ -944,6 +956,9 @@ static JNINativeMethod methods[] = {
944956
(void*)jni_YGNodeSetHasMeasureFuncJNI},
945957
{"jni_YGNodeStyleGetGapJNI", "(JI)F", (void*)jni_YGNodeStyleGetGapJNI},
946958
{"jni_YGNodeStyleSetGapJNI", "(JIF)V", (void*)jni_YGNodeStyleSetGapJNI},
959+
{"jni_YGNodeStyleSetGapPercentJNI",
960+
"(JIF)V",
961+
(void*)jni_YGNodeStyleSetGapPercentJNI},
947962
{"jni_YGNodeSetHasBaselineFuncJNI",
948963
"(JZ)V",
949964
(void*)jni_YGNodeSetHasBaselineFuncJNI},

0 commit comments

Comments
 (0)