Conversation
f6764d6 to
58c2109
Compare
|
Drafted to wait for Android counterpart |
dea14f2 to
838ffaf
Compare
| context.coordinator.itemHeight = itemHeight | ||
| context.coordinator.originalIndex = originalIndex | ||
| context.coordinator.itemCount = itemCount | ||
| } |
There was a problem hiding this comment.
Bug: updateUIView never refreshes the drag callbacks — stale closures
In UIViewRepresentable, makeCoordinator() is called exactly once per view lifetime. The three closure properties on Coordinator (onDragBegan, onDragChanged, onDragEnded) are set there but never reassigned in updateUIView. Every time SwiftUI re-renders DraggableItem (which happens as soon as a drag starts, because @State vars like dragHandleFrames and overlayFrameDuringDrag change), updateUIView is called but the coordinator keeps the closures from the very first render.
In practice the @State captures are stable, so simple drags may work fine. The real exposure is that originalIndex and itemHeight captured by the stale onDragChanged closure can diverge from the coordinator's freshly-updated values if the row's position changes mid-session — causing incorrect clamping vs. what handleLongPress computes.
bitkit-ios/Bitkit/Components/Core/DraggableItem.swift
Lines 169 to 175 in eaf8fe1
Suggested fix:
| } | |
| func updateUIView(_ uiView: UIView, context: Context) { | |
| context.coordinator.itemHeight = itemHeight | |
| context.coordinator.originalIndex = originalIndex | |
| context.coordinator.itemCount = itemCount | |
| context.coordinator.onDragBegan = onDragBegan | |
| context.coordinator.onDragChanged = onDragChanged | |
| context.coordinator.onDragEnded = onDragEnded | |
| } |
Description
Screenshots
Simulator.Screen.Recording.-.iPhone.17.-.2026-02-13.at.19.11.46.mov