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

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

Avoid using animateItem on selected tiles

Changing the span of a lazy grid item using the animateItem modifier causes it to "jump" position in RTL layouts.
This modifier isn't actually needed for selected tiles since they can only be resized, not moved. A quick workaround for this issue is to only use animateItem on unselected tiles

Test: manually resizing in LTR and RTL
Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Bug: 411560538
Change-Id: I746499ded478f181a501956c7cbf5afe45d1d7f8
parent 465c4874
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyGridItemScope
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.itemsIndexed
@@ -733,15 +734,6 @@ fun LazyGridScope.EditTiles(
                        onRemoveTile = onRemoveTile,
                        coroutineScope = coroutineScope,
                        largeTilesSpan = listState.largeTilesSpan,
                        modifier =
                            Modifier.animateItem(
                                placementSpec =
                                    spring(
                                        stiffness = Spring.StiffnessMediumLow,
                                        dampingRatio = Spring.DampingRatioLowBouncy,
                                        visibilityThreshold = IntOffset.VisibilityThreshold,
                                    )
                            ),
                    )
                }
            is SpacerGridCell ->
@@ -771,7 +763,7 @@ private fun rememberTileState(
}

@Composable
private fun TileGridCell(
private fun LazyGridItemScope.TileGridCell(
    cell: TileGridCell,
    index: Int,
    dragAndDropState: DragAndDropState,
@@ -838,10 +830,25 @@ private fun TileGridCell(
            TileState.Placeable,
            TileState.GreyedOut -> null
        }

    InteractiveTileContainer(
        tileState = tileState,
        resizingState = resizingState,
        modifier = modifier.height(TileHeight).fillMaxWidth(),
        modifier =
            modifier.height(TileHeight).fillMaxWidth().thenIf(tileState != TileState.Selected) {
                // TODO(b/412357793) Remove this workaround when animateItem is fixed for RTL grids
                // Don't apply the animateItem modifier to the selected tile as it interferes with
                // the resizing animation. The selection can't change positions without selecting a
                // different tile, so this isn't needed regardless.
                Modifier.animateItem(
                    placementSpec =
                        spring(
                            stiffness = Spring.StiffnessMediumLow,
                            dampingRatio = Spring.DampingRatioLowBouncy,
                            visibilityThreshold = IntOffset.VisibilityThreshold,
                        )
                )
            },
        onClick = {
            if (tileState == TileState.Removable) {
                onRemoveTile(cell.tile.tileSpec)