Repository navigation
Conversation
|
Claude finished @sztomek's task in 1m 36s —— View job The grid rules match Blocking
|
Generated by 🚫 Danger |
| val target = ItemTouchDragRules.gridDropTarget(selected, rects, startLeft + dx, startTop + dy) ?: return | ||
| if (isReorderable(target.key)) { | ||
| pendingMoveIndex = index | ||
| onMove(key, target.key) |
There was a problem hiding this comment.
If you long-press the top-left podcast and drag it down a row, the grid scrolls by a row on its own while you drag. RecyclerView doesn't do this, because GridLayoutManager.prepareForDrop re-anchors the scroll position after onMoved.
Why it happens: LazyGridState anchors its scroll position to the key of the first visible item. When onMove moves that key (either the dragged item or the target is at firstVisibleItemIndex) to an index in a later row, firstVisibleItemIndex follows the key. The rows above it scroll out of view, and the next moveIfNecessary then runs on the shifted layout.
Fix: before calling onMove, save gridState.firstVisibleItemIndex / firstVisibleItemScrollOffset. If from or to is that index, restore the position after the move with gridState.requestScrollToItem(index, offset), or with scope.launch { scrollToItem(...) }. The Compose foundation drag-and-drop demo handles it the same way.
|
Version |
|
Version |
Description
Plan PR 23 (Podcasts tab), part 1 of 4. Adds the drag infrastructure the Compose Podcasts grid needs. Nothing uses it yet; part 4 (#6335) switches the tab over.
ItemTouchDragRules.gridDropTarget: the 2D version of theItemTouchHelperrules ported in the rearrange screen ([Compose] Port multi-select overflow sheet and rearrange screen: rearrange drag #6252): the half-size move threshold on either axis, swap targets that overlap the dragged cell sorted by centre distance, andchooseDropTargetin all four directions (a cell swaps once the dragged cell has fully passed it).GridDragState+Modifier.gridDragGestures: theRearrangeDragStatebehaviour for aLazyGridState. Long-press anywhere on a cell (not in the gaps between cells, likefindChildViewUnder), translation in both axes that follows the finger, edge auto-scroll with the 20dp cap and 2s ramp using the decorated bounds, 250ms accelerate/decelerate recover. Item decoration insets and content padding are passed in so the rules run on the same bounds the View used.LockedReorder: port ofLockableListAdapter+LockingDragAndDropCallback. It freezes the list while dragging, moves the item on each swap (with theCONTEXT_CLICKhaptic), commits once on drop only if something moved, and unlocks when the commit finishes (a new drag cancels a pending commit and keeps the lock).AccelerateDecelerateis now public so the Podcasts page can reuse the move animation.Tests:
GridDragRulesTestcovers the threshold, swaps right/left/down, non-overlapping cells and the winner choice. The existingItemTouchDragRulesTestandRearrangeDragStateTeststill pass.Parity ledger (pre-existing, kept)
Testing Instructions
Nothing to test in the app yet.
./gradlew :modules:services:views:testDebugUnitTest. The drag is exercised end to end in part 4.Screenshots or Screencast
No UI change in this part. See part 4 for the before/after collage.
Checklist
./gradlew spotlessApplyto automatically apply formatting/linting)modules/services/localization/src/main/res/values/strings.xmlI have tested any UI changes...