I have a TextField and a swappable list view. I wanted to copy the text value of item swiped to the state variable binded to the TextField, so that if I click the edit button, I don’t need to retype all the content of the item selected/swiped
but currently, I am only allowed to define buttons to display on swipeAction and define what will happen when that button is pressed
but what I need is to define what will happen between the item is swiped and before a button is pressed
sample codes:
List(problems) { p in
// maybe contain the text on zstack rectange?? so the Text boundary will expand?
Text(p.content ?? "")
.swipeActions(allowsFullSwipe: false) {
// *** I want to inset here to update a state variable on swipe***
//
Button {
viewContext.delete(p)
do {
try viewContext.save()
} catch {
}
} label: {
Label("Delete", systemImage: "minus.circle")
}
.tint(.red)
Button {
let str = problemValue.trimmingCharacters(in: .whitespacesAndNewlines)
p.content = str
do {
try viewContext.save()
} catch {
}
problemValue = ""
} label: {
Label("Edit", systemImage: "pencil.circle")
}
.tint(.blue)
}
}
I also tried to use Gesture → DragGesture, but it only executes when the text it self is dragged and not executed when space around the text is dragged, also with this, the swipeAction no longer execute when drag is performed on text.