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

Commit db6f2b27 authored by William Leshner's avatar William Leshner Committed by Android (Google) Code Review
Browse files

Merge "Fix an IndexOutOfBoundsException when dragging to add widgets." into main

parents 2fa5f194 1e6c421f
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyHorizontalGrid
import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.selection.selectable
@@ -690,21 +691,20 @@ private fun BoxScope.CommunalHubLazyGrid(
        horizontalArrangement = Arrangement.spacedBy(Dimensions.ItemSpacing),
        verticalArrangement = Arrangement.spacedBy(Dimensions.ItemSpacing),
    ) {
        items(
            count = list.size,
            key = { index -> list[index].key },
            contentType = { index -> list[index].key },
            span = { index -> GridItemSpan(list[index].size.span) },
        ) { index ->
        itemsIndexed(
            items = list,
            key = { _, item -> item.key },
            contentType = { _, item -> item.key },
            span = { _, item -> GridItemSpan(item.size.span) },
        ) { index, item ->
            val size =
                SizeF(
                    Dimensions.CardWidth.value,
                    list[index].size.dp().value,
                    item.size.dp().value,
                )
            val cardModifier = Modifier.requiredSize(width = size.width.dp, height = size.height.dp)
            if (viewModel.isEditMode && dragDropState != null) {
                val selected by
                    remember(index) { derivedStateOf { list[index].key == selectedKey.value } }
                val selected = item.key == selectedKey.value
                DraggableItem(
                    modifier =
                        if (dragDropState.draggingItemIndex == index) {
@@ -716,12 +716,12 @@ private fun BoxScope.CommunalHubLazyGrid(
                        },
                    dragDropState = dragDropState,
                    selected = selected,
                    enabled = list[index].isWidgetContent(),
                    enabled = item.isWidgetContent(),
                    index = index,
                ) { isDragging ->
                    CommunalContent(
                        modifier = cardModifier,
                        model = list[index],
                        model = item,
                        viewModel = viewModel,
                        size = size,
                        selected = selected && !isDragging,
@@ -734,7 +734,7 @@ private fun BoxScope.CommunalHubLazyGrid(
                }
            } else {
                CommunalContent(
                    model = list[index],
                    model = item,
                    viewModel = viewModel,
                    size = size,
                    selected = false,