1

Here is a simple macOS demo app that compares using a SwiftUI List and a LazyVStack. I prefer to use a LazyVStack because it's easier to customize the style. But it seems some of the built-in functionality is missing, such as reordering list items (as shown below)

import SwiftUI

class MyData: ObservableObject{
  @Published var items = ["One", "Two", "Three", "Four", "Five"]
}

struct ContentView: View {
  @StateObject var model = MyData()

  var body: some View {
    HStack{
      //--- List ---
      VStack{
        Text("List")
          .fontWeight(.bold)
        List{
          ForEach(model.items, id: \.self){ item in
            Text(item)
          }
          .onMove(perform: move)
        }
      }
      //--- LazyVStack ---
      VStack{
        Text("LazyVStack")
          .fontWeight(.bold)
        ScrollView {
          LazyVStack {
            ForEach(model.items, id: \.self){ item in
              Text(item)
            }
            .onMove(perform: move)
          }
        }
      }
    }
  }
  //Reorder List
  func move(from source: IndexSet, to destination: Int) {
    model.items.move(fromOffsets: source, toOffset: destination )
  }
}

enter image description here

The reordering of items works fine in the List example. But nothing happens in the LazyVStack.

Is there a way to get the .onMove functionality to work in the LazyVStack instance? Or do I have to implement a full bevy of custom .onDrag stuff with NSItemProvider?

Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
  • `.onMove` and `.onDelete` commands are only available embedded in `Lists` :/ – AlbertUI Mar 02 '21 at 00:21
  • this post uses move with animation, LazyVStack and Drag & Drop Reorder List https://avitsadok.medium.com/reorder-items-in-swiftui-lazyvstack-6d238efab04 – finalpets Oct 07 '21 at 21:32

0 Answers0