Why does .swipeAction set editMode?

Why does a swipe action (using the new .swipeAction in SwiftUI 5.5, currently beta 3) set editMode? Notice when you swipe that "Edit" changes to "Done"?

And yet this is not like full edit mode because tapping the EditButton shows the move handles (and the ever-annoying ugly blank indentation for the absent onDelete modifier).

I think my next project won't use SwiftUI.

import SwiftUI

struct Fruit: Identifiable {
    let id: UUID = UUID()
    let name: String
    let color: Color
}

struct ListingView: View {
    @State var fruits: [Fruit] = [
        Fruit(name: "banana", color: .yellow),
        Fruit(name: "apple", color: .green),
        Fruit(name: "tomato", color: .red)]
    
    @Environment(\.editMode) private var editMode
    
    var body: some View {
        NavigationView {
            VStack(alignment: .leading) {
                List {
                    ForEach(fruits) { fruit in
                        NavigationLink(
                            destination: ZStack {
                                fruit.color
                                Text(fruit.name).bold().font(.largeTitle)
                            }
                                .navigationTitle(fruit.name),
                            label: {
                                HStack(alignment: .center) {
                                    fruit.color.frame(width: 30, height: 30)
                                    Text(fruit.name)
                                }
                            })
                            .swipeActions(edge: .leading, allowsFullSwipe: false) {
                                Button(action: { delete(fruit) },
                                       label: { Image(systemName: "trash") }).tint(.red)
                            }
                    }
                    .onMove(perform: { from, to in
                        fruits.move(fromOffsets: from, toOffset: to)
                    })
                }
            }
            .navigationBarTitle("Fruits")
            .toolbar {
                ToolbarItem(placement: .primaryAction) {
                    EditButton()
                }
            }
        }
    }

    private func delete(_ fruit: Fruit) {
        guard let index = fruits.firstIndex(where: {$0.id == fruit.id}) else { return }
        fruits.remove(at: index)
    }
}

struct ListingView_Previews: PreviewProvider {
    static var previews: some View {
        ListingView()
    }
}
Answered by ForumsContributor in
Accepted Answer

I understand now. The Done button is useful for cancelling the swipe.

  1. swipe to reveal the hidden button(s) behind the row.
  2. decide you don't want to use those buttons.
  3. A) swipe the row back
  4. B) OR interact somewhere else
  5. C) OR tap Done to have the row return to normal.

The EditMode isActive is true while the row is swiped aside, but the value is not .active.

Why does .swipeAction set editMode?
 
 
Q