diff options
| -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 |