r/iOSDevelopment • u/Kozakiewicz122112 • 14h ago
Drag-and-resize on a timeline grid: two SwiftUI things that cost me a week
I built a day planner where every task carries a start time and a length, so the day is a 2D layout and overlaps are visible before they happen. Two things took far longer than expected.
- A DragGesture inside a LazyVStack loses to the scroll view almost every time. What finally worked was one high-priority gesture on the container that hit-tests which block is under the finger, instead of a gesture attached to each row.
- Collision detection belongs in the model, not the view. I spent days computing overlaps during layout, which made dragging stutter. Moving it into the store made the drag instant and let the same code show a conflict before you drop.
It is live and free of review gatekeeping, so you can poke at the interaction directly: https://apps.apple.com/app/id6804453041
1
Upvotes
1
u/Kozakiewicz122112 3h ago
Same bridge here, long press at 0.35s with allowableMovement 10 so a swipe still scrolls the day. No auto-scroll during drag, and there is a reason worth knowing: scrolling to a specific task block freezes for about a second on iOS 26 because the block gets a focus highlight, so I scroll to a placeholder anchor instead.
1
u/the_tech_mastery 5h ago
Nice write-up, #1 matches what I've run into too. One option if you ever want per-block gestures back: only start the drag after a short long-press.
Until the press fires, the scroll view keeps the pan, so normal scrolling still works. Once it fires, the drag is yours. If SwiftUI still fights you, iOS 18's
UIGestureRecognizerRepresentablelets you attach a realUILongPressGestureRecognizer: after the press it keeps reporting.changedwith the finger location, so one recognizer gives you both the press and the drag, and UIKit's own arbitration with the scroll view just works. That's what I ended up using for a drag-to-reorder grid.Agree on #2. Did you also need auto-scroll when a block is dragged to the top or bottom edge of the visible day? That was the fiddliest part for me.