diff options
| author | 2024-11-16 09:43:09 +0000 | |
|---|---|---|
| committer | 2024-11-16 09:43:09 +0000 | |
| commit | 4c7da25d8978e11ad708779aa000eb272ea8a090 (patch) | |
| tree | cf97f987f2106c68548367218a1da79e4adcff60 | |
| parent | c7a89b8067be1064ac283541d92004b5e4211682 (diff) | |
| parent | 8e08e35243c99c1a7099ae76e721912e1ddf5c00 (diff) | |
Merge "Fix issue where widget disappears when reordering" into main
| -rw-r--r-- | packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/GridDragDropState.kt | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/GridDragDropState.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/GridDragDropState.kt index 1551ca97a2e3..ef5e90bd7aad 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/GridDragDropState.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/GridDragDropState.kt @@ -179,11 +179,18 @@ internal constructor( val targetItem = if (communalWidgetResizing()) { state.layoutInfo.visibleItemsInfo.findLast { item -> + val lastVisibleItemIndex = state.layoutInfo.visibleItemsInfo.last().index val itemBoundingBox = IntRect(item.offset, item.size) draggingItemKey != item.key && contentListState.isItemEditable(item.index) && (draggingBoundingBox.contains(itemBoundingBox.center) || - itemBoundingBox.contains(draggingBoundingBox.center)) + itemBoundingBox.contains(draggingBoundingBox.center)) && + // If we swap with the last visible item, and that item doesn't fit + // in the gap created by moving the current item, then the current item + // will get placed after the last visible item. In this case, it gets + // placed outside of the viewport. We avoid this here, so the user + // has to scroll first before the swap can happen. + (item.index != lastVisibleItemIndex || item.span <= draggingItem.span) } } else { state.layoutInfo.visibleItemsInfo |