I have exactly the same question, nobody has been able to solve it on Stack Overflow, so I'm going to try to get lucky here.
Question Source, at: Stack Overflow - Question asked by Miosser
When the ability to delete is disabled [.deleteDisabled(true)] on a list and the list's edit button [EditButton()] is pressed, the extra space to the left of each list item still appears as if it were still show the delete buttons (I don't want to do multi-selection of list rows either, just organize the list items individually), but I haven't found or been able to remove that space on the left, which belongs to the delete buttons and I want strip to make the text fill the entire line, because the stripping capability still leaves that space even if it's disabled.
List {
ForEach(projectListVM.projects
.filter{filterFavorites ?
$0.isFavorite == true :
($0.isFavorite || !$0.isFavorite)},
id: \.id) { itemProject in
ProjectListRowScreen(itemProject: itemProject, projectListVM: projectListVM)
}
.onMove(perform: moveItem)
.deleteDisabled(true)
.listRowBackground(Color.clear)
}
ProjectListRowScreen.swift
VStack(alignment: .leading) {
NavigationLink {
ProjectDetailScreen(projectVM: itemProject)
} label: {
VStack(alignment: .leading) {
HStack(alignment: .top) {
if itemProject.isFavorite {
Image(systemName: "star.fill")
.frame(width: 18, alignment: .top)
.foregroundColor(Color(itemProject.color.isEmpty ? tagColors[0] : itemProject.color))//Color("Favorite"))
.padding(.top, paddingMicro)
} else {
Image(systemName: "cube.fill")
.frame(height: 18, alignment: .top)
.foregroundColor(Color(itemProject.color.isEmpty ? tagColors[0] : itemProject.color))
.padding(.top, paddingMicro)
}
HStack(alignment: .top) {
VStack(alignment: .leading) {
Text(itemProject.title).fontWeight(.thin)
.multilineTextAlignment(.leading)
}
Spacer()
}
}
}
}
}
.sheet(isPresented: $showEditView,
onDismiss: {projectListVM.fetchAllProjects()},
content: {ProjectEditScreen(projectItem: itemProject)})
.swipeActions(edge: .leading, allowsFullSwipe: true) {
Button {
self.toogleFavorite(projectId: itemProject.id)
} label: {
if itemProject.isFavorite {
Label("Unfavorite", systemImage: "star.slash")
} else {
Label("Favorite", systemImage: "star.fill")
}
}
.tint(itemProject.isFavorite ? .gray: .yellow)
}
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button(role: .destructive) {
showConfirmationDelete = true
} label: {
Label("Delete", systemImage: "trash")
}
.tint(.red)
Button {
showEditView = true
} label: {
Label("Edit",systemImage: "square.and.pencil")
}
.tint(.blue)
}
.confirmationDialog(
"Are you shure? Action cannot be undone",
isPresented: $showConfirmationDelete,
titleVisibility: .visible,
actions: {
Button("Delete", role: .destructive) {
withAnimation {
self.deleteProjectById(projectId: itemProject.id)
showConfirmationDelete = false
}
}
Button("Cancel", role: .cancel) { showConfirmationDelete = false }
})
.padding(EdgeInsets(top: 15, leading: 10, bottom: 15, trailing: 10))
.background(Color("BackgroundPanel"))
.clipShape(RoundedRectangle(cornerRadius: cornerMedium, style: .continuous))