You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Legacy (SwiftUI) grid: dragged icon stays stuck on screen after release #263
When moving an icon on the main grid, the drag preview often stays frozen where the
mouse was released, and the drop is never completed.
Cause
The drag is handled by a DragGesture attached to each tile in itemDraggable.
Its onEnded is the only place that calls finalizeDragOperation and clears draggingItem. With debug logging I found that, right after the drag starts,
the tile hosting the gesture is torn down:
drag started
dragged tile disappeared
gridRefreshTrigger changed (draggingItem=true)
Two things destroy it:
The pages use .id("grid_\(index)_\(appStore.gridRefreshTrigger.uuidString)"),
and triggerGridRefresh() is called from many places (rescans, icon loading,
saves), so a refresh during a drag rebuilds every tile.
The tile itself is re-rendered once the drag starts (hidden, reordered).
When the hosting view goes away, SwiftUI cancels the gesture and onEnded is
never called, so draggingItem stays set and the preview remains on screen.
Fix (works for me)
Window-level mouse-up fallback: when a normal drag starts, install NSEvent.addLocalMonitorForEvents(matching: [.leftMouseDragged, .leftMouseUp]),
the same approach already used for the folder handoff drag. On mouse-up it calls
a shared endItemDrag(...), which runs finalizeDragOperation exactly once,
whichever arrives first between the monitor and onEnded. If the gesture stops
delivering updates for more than 0.1 s, the monitor keeps the preview following
the pointer via handleHandoffDragMove.
Defer grid rebuilds during a drag: the pages use a separate @State displayedGridRefreshID, which follows gridRefreshTrigger only while draggingItem == nil. Any pending refresh is applied as soon as the drag ends.
With both changes the drag works correctly (same page, across pages,
folder creation).
Thank you for your detailed investigation and suggested fix. The legacy SwiftUI engine is no longer actively maintained. 🥲In fact, I plan to remove the legacy engine. Please switch to the new engine in Settings. If you encounter any issues, please let me know.
Thanks for the reply, and for 4dc37ab and 63e8953! Both fixes work for me.
"Next Engine" was already selected. I had turned the
"Next Engine With Core Animation" toggle off on purpose, because with it
enabled I couldn't place icons where I wanted. That is how I ended up on the
SwiftUI grid and hit the stuck-drag bug.
So the real problem is drag placement on the Core Animation grid. I looked
into it and found these causes (all in CAGridView):
Gaps don't stay under the pointer. Icons shift visually, but hit-testing
still uses the original layout. After a gap opens, the cell under the
pointer is still treated as holding the icon that moved away, so the gap
jumps elsewhere or a folder-merge starts over an empty slot. Aiming between
two icons while dragging left-to-right ends up after the second one.
The SwiftUI grid hit-tests the displayed layout (visualItems), so the gap
stays where you point.
Gap between cells goes entirely to the left cell.gridPositionAt()
uses Int(x / stride), while the SwiftUI grid splits the spacing in half
(GeometryUtils.indexAt: (x + spacing / 2) / stride).
Dropping into the first column flips to the previous page. The edge zone
is 60 pt inside the grid (edgeDragThreshold) and contentInsets.left is 0
in windowed mode, so it overlaps the first column's drop area.
Edge paging skips pages. After a flip edgeDragTimer is cleared and the
next mouse move immediately arms a new 0.4 s timer, so a pointer resting
past the edge flips every ~0.4 s.
What I changed locally, and it now feels as precise as the SwiftUI grid:
Hit-test the displayed layout: the gap stays under the pointer, and a merge
targets the icon actually shown in the cell.
Split the spacing between neighbouring cells, as GeometryUtils.indexAt does.
Edge zone of 15 pt (same as the SwiftUI grid). In windowed mode, flip only
once the pointer leaves the grid, so the first and last columns stay usable.
0.6 s cooldown after each edge flip.
Environment: Xcode 27.0 (27A266a), macOS 27.0.1, LaunchNext 2.4.2 (63e8953).
The Core Animation issues are still present on 63e8953.
Activity
RoversX commentedon Oct 3, 2026
Thank you for your detailed investigation and suggested fix. The legacy SwiftUI engine is no longer actively maintained. 🥲In fact, I plan to remove the legacy engine. Please switch to the new engine in Settings. If you encounter any issues, please let me know.
RoversX commentedon Oct 3, 2026
63e8953
Dino0005 commentedon Oct 3, 2026
Thanks for the reply, and for 4dc37ab and 63e8953! Both fixes work for me.
"Next Engine" was already selected. I had turned the
"Next Engine With Core Animation" toggle off on purpose, because with it
enabled I couldn't place icons where I wanted. That is how I ended up on the
SwiftUI grid and hit the stuck-drag bug.
So the real problem is drag placement on the Core Animation grid. I looked
into it and found these causes (all in
CAGridView):still uses the original layout. After a gap opens, the cell under the
pointer is still treated as holding the icon that moved away, so the gap
jumps elsewhere or a folder-merge starts over an empty slot. Aiming between
two icons while dragging left-to-right ends up after the second one.
The SwiftUI grid hit-tests the displayed layout (
visualItems), so the gapstays where you point.
gridPositionAt()uses
Int(x / stride), while the SwiftUI grid splits the spacing in half(
GeometryUtils.indexAt:(x + spacing / 2) / stride).is 60 pt inside the grid (
edgeDragThreshold) andcontentInsets.leftis 0in windowed mode, so it overlaps the first column's drop area.
edgeDragTimeris cleared and thenext mouse move immediately arms a new 0.4 s timer, so a pointer resting
past the edge flips every ~0.4 s.
What I changed locally, and it now feels as precise as the SwiftUI grid:
targets the icon actually shown in the cell.
GeometryUtils.indexAtdoes.once the pointer leaves the grid, so the first and last columns stay usable.
Environment: Xcode 27.0 (27A266a), macOS 27.0.1, LaunchNext 2.4.2 (63e8953).
The Core Animation issues are still present on 63e8953.