.onMove does not work properly

Hello, I have a problem with the .onMove function. I believe I have set everything up properly. However, the moving does not seem to be working correctly. When I try to move the item, it is highlighted first, as it is supposed to be. Then, while I am moving it through the list, it disappears for some reason, and at the end of the move, it comes back to its initial place. (I use iOS 16.0 minimum, so I don't have to include the EditButton(). It works the same in the edit mode tho)

import SwiftUI

struct Animal: Identifiable {
    var id = UUID()
    var name: String
}

struct ListMove: View {
    
    @State var animals = [Animal(name: "Dog"), Animal(name: "Cat"), Animal(name: "Cow"), Animal(name: "Goat"), Animal(name: "Chicken")]
    
    var body: some View {
        List {
            ForEach(animals) { animal in
                Text(animal.name)
            }
            .onMove(perform: move)
        }
    }
    
    func move(from source: IndexSet, to destination: Int) {
        animals.move(fromOffsets: source, toOffset: destination)
    }
    
}

#Preview {
    ListMove()
}

Hello @dennissavchenko,

What version of Xcode are you using? I just ran your code and it behaved as you would expect for me.

Best regards,

Greg

I am having exactly the same behavior with XCode Version 16.1 beta 2 (16B5014f). In the following code, onDelete is working, onMove is not and displays the same behavior as shown by the OP. "Move" is not printed and the display reverts to the original order after attempting to drag an item in Edit mode.


import MapKit
import SwiftData
import SwiftUI

struct WaypointList: View {
    @Environment(\.modelContext) var modelContext
    @Query(sort: \Location.latitude) var locations: [Location]
    @State private var listSelection: Location?
    @State private var searchResult = [Location]()
    
    var body: some View {
        NavigationSplitView {
            List(selection: $listSelection) {
                ForEach(searchResult) { location in
                    Text(location.name)
                        .tag(location)
                }
                .onMove(perform: move)
                .onDelete {
                    print("Delete")
                    for index in $0 {
                        let item = searchResult[index]
                        let offset = locations.firstIndex(of: item)!
                        modelContext.delete(locations[offset])
                        searchResult.remove(at: index)
                    }
                }
            }
            .frame(minWidth: 220)
            .navigationTitle("Waypoints")
            .toolbar {
                EditButton()
            }
        } detail: {
            if let selection = listSelection {
                VStack {
                    LandmarkDetail(location: selection)
                }
            } else {
                Text("Select a waypoint")
            }
        }
        .onAppear {
            searchResult = locations
        }
    }
    
    func move(from source: IndexSet, to destination: Int) {
        print("Move")
        searchResult.move(fromOffsets: source, toOffset: destination)
    }
}
.onMove does not work properly
 
 
Q