We have a feature requirement where we need to use LazyVGrid and DropDelegate. Our view hierarchy is as follows:
Color.white.ignoresSafeArea()
VStack(spacing: 0) {
customNavigationView
ScrollView(showsIndicators: true) {
LazyVGrid(columns: columns,
alignment: .center,
spacing: 16) {
ForEach(viewModel.selectedReferences, id: \.self) { item in
ZStack {
Rectangle()
.fill(Color.yellow.opacity(0.5))
Text(item.title)
}
.frame (height: 120)
.background(Color.white)
.padding([.leading, .trailing], 4)
.overlay((draggedItem?.uuid == item.uuid && changedView) ? Color.white.opacity(0.8) : Color.clear)
.clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
.onDrag {
initialIndex = viewModel.selectedReferences.firstIndex { $0 == item }
draggedItem = item
changedView = false
return NSItemProvider(object: String(item.uuid) as NSString)
}
.clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
.onDrop(of: [UTType.text], delegate: DragRelocateDelegate(item: item,
listData: $viewModel.selectedReferences,
current: $draggedItem,
changedView: $changedView) { endIndex in
})
}
}
.animation(.default, value: viewModel.selectedReferences)
}
.frame(width:(UIScreen.main.bounds.width))
.onDrop(of: [UTType.text], delegate: DropOutsideDelegate(current: $draggedItem, changedView: $changedView))
bottomBarView
}
.frame(maxWidth: .infinity)
}
While performing a reshuffle, auto-scroll works within the bounds of the ScrollView content. However, according to the feature requirement, auto-scroll should also work when we place an uplifted view at the top or bottom of the view.
STEPS TO REPRODUCE
Launch the demo.
Scroll to the bottom of the LazyVGrid.
Pick any item using the DropDelegate.
Try to place that uplifted view on the custom navigation view.
Expected Result:
The ScrollView should auto-scroll.
Actual Result:
Auto-scroll is not working.