Skip to content

[Compose] Port Podcasts tab (part 1: grid drag state) - #6332

Draft
sztomek wants to merge 1 commit into
compose/pr21-files-list-afrom
compose/pr23-podcasts-tab-a
Draft

sztomek wants to merge 1 commit into
compose/pr21-files-list-afrom
compose/pr23-podcasts-tab-a

Conversation

@sztomek

@sztomek sztomek commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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 the ItemTouchHelper rules 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, and chooseDropTarget in all four directions (a cell swaps once the dragged cell has fully passed it).
  • GridDragState + Modifier.gridDragGestures: the RearrangeDragState behaviour for a LazyGridState. Long-press anywhere on a cell (not in the gaps between cells, like findChildViewUnder), 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 of LockableListAdapter + LockingDragAndDropCallback. It freezes the list while dragging, moves the item on each swap (with the CONTEXT_CLICK haptic), 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).
  • AccelerateDecelerate is now public so the Podcasts page can reuse the move animation.

Tests: GridDragRulesTest covers the threshold, swaps right/left/down, non-overlapping cells and the winner choice. The existing ItemTouchDragRulesTest and RearrangeDragStateTest still pass.

Parity ledger (pre-existing, kept)

  • None in this part.

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

  • If this is a user-facing change, I have added an entry in CHANGELOG.md
  • Ensure the linter passes (./gradlew spotlessApply to automatically apply formatting/linting)
  • I have considered whether it makes sense to add tests for my changes
  • All strings that need to be localized are in modules/services/localization/src/main/res/values/strings.xml
  • Any jetpack compose components I added or changed are covered by compose previews
  • I have updated (or requested that someone edit) the Event Horizon schema to reflect any new or changed analytics.

I have tested any UI changes...

  • with different themes
  • with a landscape orientation
  • with the device set to have a large display and font size
  • for accessibility with TalkBack

@claude

claude Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @sztomek's task in 1m 36s —— View job


The grid rules match ItemTouchHelper's findSwapTargets, chooseDropTarget and scrollIfNecessary, and LockedReorder behaves the same as LockingDragAndDropCallback. One issue is specific to LazyGrid: its scroll position follows the key of the first visible item, so moving that item scrolls the grid. Once part 4 switches the tab over, this will show up as soon as someone drags the first podcast down a row.

Blocking

  • modules/services/views/src/main/java/au/com/shiftyjelly/pocketcasts/views/compose/GridDragState.kt:140: dragging the top-left podcast down a row makes the grid scroll by a row on its own, because LazyGridState moves firstVisibleItemIndex along with the moved key. Save the first visible index and offset before onMove and restore them after the move (requestScrollToItem / scrollToItem), as GridLayoutManager.prepareForDrop does. [Compose] Port Podcasts tab (part 1: grid drag state) #6332 (comment)

@dangermattic

Copy link
Copy Markdown
Collaborator
1 Error
🚫 Please add tests for class GridDragState (or add unit-tests-exemption label to ignore this).
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@sztomek sztomek added [Type] Other Issues not covered by other types, such as refactoring and documentation. [Type] Tech Debt Involving upgrades or refactoring to maintain or enhance the codebase. [Area] Compose labels Nov 3, 2026
@sztomek sztomek added this to the 8.25 milestone Nov 3, 2026
val target = ItemTouchDragRules.gridDropTarget(selected, rects, startLeft + dx, startTop + dy) ?: return
if (isReorderable(target.key)) {
pendingMoveIndex = index
onMove(key, target.key)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@wpmobilebot wpmobilebot modified the milestones: 8.25, 8.26 Nov 9, 2026
@wpmobilebot

Copy link
Copy Markdown
Collaborator

Version 8.25 has now entered code-freeze, so the milestone of this PR has been updated to 8.26.

@wpmobilebot wpmobilebot modified the milestones: 8.26, 8.27 Nov 23, 2026
@wpmobilebot

Copy link
Copy Markdown
Collaborator

Version 8.26 has now entered code-freeze, so the milestone of this PR has been updated to 8.27.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Compose [Type] Other Issues not covered by other types, such as refactoring and documentation. [Type] Tech Debt Involving upgrades or refactoring to maintain or enhance the codebase.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants