How do you set an action to perform when the user hits the EditButton
when it appears as "Done"? Is it even possible to do so?
Note that this is not the same as performing an action at each of the individual edits the user might do (like onDelete
or onMove
). How do you set an action to perform when the user is finished making all changes and ready to commit them?
It's necessary because I'm making all changes on a temporary copy of the model and will not commit the changes to the actual model until the user hits "Done". I am also providing a "Cancel" Button to discard the changes.
struct MyView: View {
@Environment(\.editMode) var mode
var body: some View {
VStack {
HStack {
if self.mode?.value == .active {
Button(action: {
// discard changes here
self.mode?.value = .inactive
}) {
Text("Cancel")
}
}
Spacer()
EditButton()
// how to commit changes??
}
// controls to change the model
}
}
}
Is it even possible to set an action for "Done" on the EditButton
or would I have to provide my own button to act like an EditButton
? I could certainly do that, but it seems like it should be easy to do with the EditButton
.