2

I have the following view:

    var body: some View {
        HStack(
            alignment: .top
        ) {
            // List {
                ForEach(taskLists, id: \.self) { list in
                    VStack(alignment: .leading) {
                        TaskListView(list: list)
                            .padding(10)
                    }
                }
                .onMove { indices, newOffset in
                    print("mooooooooove")
                }
            }
        //}
    }

So, it is a horizontal stack of several VStacks. This works fine (e.g):

■ ■ ■

Now, I want to wrap ForEach with the List to enable the drag-n-drop. When I uncomment the lines in the above code, the view changes to the vertical stack of the inner VStacks, i.e. they are now one above the other:

■
■
■

How can I use List&ForEach and remain the horizontal stack AND to enable the onMove()?

Please note that putting List before HStack gives the correct view, but the method onMove is not being called.

igr
  • 10,199
  • 13
  • 65
  • 111
  • You can achieve it using LazyVGrid (with one column). https://stackoverflow.com/questions/62606907/swiftui-using-ondrag-and-ondrop-to-reorder-items-within-one-single-lazygrid – Levan Karanadze Oct 11 '22 at 07:54

0 Answers0