Skip to content

Commit 1ceea08

Browse files
committed
Fix item X position when using FixedSize in RTL
1 parent 9d31114 commit 1ceea08

7 files changed

+11
-3
lines changed

grid/src/commonMain/kotlin/com/cheonjaeung/compose/grid/BoxGridMeasurePolicy.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,22 @@ private class BoxGridMeasureHelper(
189189
val horizontalSpacingPx = horizontalSpacing.roundToPx()
190190
val verticalSpacingPx = verticalSpacing.roundToPx()
191191

192-
var currentX = 0
193-
var currentY = 0
192+
var currentX = if (layoutDirection == LayoutDirection.Rtl) {
193+
val horizontalSpacingCount = (columnCount - 1).coerceAtLeast(0)
194+
val horizontalSpacingSumPx = horizontalSpacingPx * horizontalSpacingCount
195+
val contentWidth = cellWidthConstraintList.sum() + horizontalSpacingSumPx
196+
measureResult.layoutSize.width.roundToInt() - contentWidth
197+
} else {
198+
0
199+
}
194200
val xPositions = IntArray(columnCount)
195-
val yPositions = IntArray(rowCount)
196201
for (i in 0 until columnCount) {
197202
xPositions[i] = currentX
198203
currentX += cellWidthConstraintList[i] + horizontalSpacingPx
199204
}
205+
206+
var currentY = 0
207+
val yPositions = IntArray(rowCount)
200208
for (i in 0 until rowCount) {
201209
yPositions[i] = currentY
202210
currentY += cellHeightConstraintList[i] + verticalSpacingPx
-20 Bytes
Loading
-17 Bytes
Loading
-54 Bytes
Loading
-26 Bytes
Loading
-22 Bytes
Loading
-17 Bytes
Loading

0 commit comments

Comments
 (0)