summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lucas Silva <lusilva@google.com> 2024-11-14 15:36:48 -0500
committer Lucas Silva <lusilva@google.com> 2024-11-15 10:54:58 -0500
commit8e08e35243c99c1a7099ae76e721912e1ddf5c00 (patch)
treebb926c2244698ef91c375439ba7ab7cc5b8ff222
parent4b817c8fecf1fa4c6aadaa6ad2ab38916e53aa6d (diff)
Fix issue where widget disappears when reordering
The issue is that if the last widget in the grid is larger than the current widget being dragged, and we attempt to swap places with the last widget in the grid, we will end up placing the widget outside of the viewport. Therefore we explictly check for this case and don't swap places. This would force the user to scroll before they can swap. Fixes: 376493654 Test: manually on device by having a full size widget at the end of the grid Flag: com.android.systemui.communal_widget_resizing Change-Id: I817a277377332fab709ef5a4c7a0216570a94f76
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/GridDragDropState.kt9
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