Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89ac47b8 authored by Olivier St-Onge's avatar Olivier St-Onge
Browse files

Use the same key between the tile and its spacer when dragged

I previously used a different key to stop the spacer from animating, but a recent update to the DragAndDrop api revealed a bug with this approach where the tile would appear blank when dropped. Using the same key fixes this issue.

Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Fixes: 390155330
Test: manually dragging tiles
Change-Id: Id05e1836147ae18484042fc9671411763ad0ccd1
parent d559273f
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -498,11 +498,9 @@ fun gridHeight(rows: Int, tileHeight: Dp, tilePadding: Dp, gridPadding: Dp): Dp
    return ((tileHeight + tilePadding) * rows) + gridPadding * 2
}

private fun GridCell.key(index: Int, dragAndDropState: DragAndDropState): Any {
private fun GridCell.key(index: Int): Any {
    return when (this) {
        is TileGridCell -> {
            if (dragAndDropState.isMoving(tile.tileSpec)) index else key
        }
        is TileGridCell -> key
        is SpacerGridCell -> index
    }
}
@@ -510,10 +508,13 @@ private fun GridCell.key(index: Int, dragAndDropState: DragAndDropState): Any {
/**
 * Adds a list of [GridCell] to the lazy grid
 *
 * @param cells the pairs of [GridCell] to [AnimatableTileViewModel]
 * @param cells the pairs of [GridCell] to [BounceableTileViewModel]
 * @param columns the number of columns of this tile grid
 * @param dragAndDropState the [DragAndDropState] for this grid
 * @param selectionState the [MutableSelectionState] for this grid
 * @param onToggleSize the callback when a tile's size is toggled
 * @param coroutineScope the [CoroutineScope] to be used for the tiles
 * @param largeTilesSpan the width used for large tiles
 * @param onResize the callback when a tile has a new [ResizeOperation]
 */
fun LazyGridScope.EditTiles(
    cells: List<Pair<GridCell, BounceableTileViewModel>>,
@@ -526,7 +527,7 @@ fun LazyGridScope.EditTiles(
) {
    items(
        count = cells.size,
        key = { cells[it].first.key(it, dragAndDropState) },
        key = { cells[it].first.key(it) },
        span = { cells[it].first.span },
        contentType = { TileType },
    ) { index ->
@@ -542,7 +543,6 @@ fun LazyGridScope.EditTiles(
                                ),
                            shape = RoundedCornerShape(InactiveCornerRadius),
                        )
                            .animateItem()
                    )
                } else {
                    TileGridCell(