Skip to content

Commit 1eaf483

Browse files
hunterstichimhappi
authored andcommitted
[ChipGroup] Updated flow layout to correctly layout padding when in RTL.
maxChildEnd is used to track when to move a child onto the next row. It can't be used to layout a child since it uses paddingEnd and children need to be laid out relative to the start of the container. PiperOrigin-RevId: 744800898
1 parent ede1bdc commit 1eaf483

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/java/com/google/android/material/internal/FlowLayout.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ protected void onLayout(boolean sizeChanged, int left, int top, int right, int b
197197
int childBottom = childTop;
198198
int childEnd;
199199

200-
final int maxChildEnd = right - left - paddingEnd;
201-
202200
for (int i = 0; i < getChildCount(); i++) {
203201
View child = getChildAt(i);
204202

@@ -218,21 +216,28 @@ protected void onLayout(boolean sizeChanged, int left, int top, int right, int b
218216

219217
childEnd = childStart + startMargin + child.getMeasuredWidth();
220218

219+
final int maxChildEnd = right - left - paddingEnd;
221220
if (!singleLine && (childEnd > maxChildEnd)) {
222221
childStart = paddingStart;
222+
childEnd = childStart + startMargin + child.getMeasuredWidth();
223223
childTop = childBottom + lineSpacing;
224224
rowCount++;
225225
}
226226
child.setTag(R.id.row_index_key, rowCount - 1);
227-
228-
childEnd = childStart + startMargin + child.getMeasuredWidth();
229227
childBottom = childTop + child.getMeasuredHeight();
230228

231229
if (isRtl) {
232230
child.layout(
233-
maxChildEnd - childEnd, childTop, maxChildEnd - childStart - startMargin, childBottom);
231+
/* left= */ right - left - childEnd,
232+
/* top= */ childTop,
233+
/* right= */ right - left - childStart - startMargin,
234+
/* bottom= */ childBottom);
234235
} else {
235-
child.layout(childStart + startMargin, childTop, childEnd, childBottom);
236+
child.layout(
237+
/* left= */ childStart + startMargin,
238+
/* top= */ childTop,
239+
/* right= */ childEnd,
240+
/* bottom= */ childBottom);
236241
}
237242

238243
childStart += (startMargin + endMargin + child.getMeasuredWidth()) + itemSpacing;

0 commit comments

Comments
 (0)