Add Delete button for iOS 14

This commit is contained in:
Philipp Heckel 2022-06-05 11:39:54 -04:00
parent 50f502436f
commit 67819f440c
2 changed files with 33 additions and 5 deletions

View file

@ -89,9 +89,32 @@ struct UsersView: View {
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
// Sigh, for iOS 14 we need to add a "Delete" menu item, because it doesn't support
// swipe actions. Quite annoying.
if #available(iOS 15.0, *) {
Button(action: cancelAction) {
Text("Cancel")
}
} else {
if selectedUser == nil {
Button("Cancel") {
cancelAction()
}
} else {
Menu {
Button("Cancel") {
cancelAction()
}
Button("Delete") {
deleteAction()
}
} label: {
Image(systemName: "ellipsis.circle")
.padding([.leading], 40)
}
}
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: saveAction) {
@ -117,6 +140,11 @@ struct UsersView: View {
resetAndHide()
}
private func deleteAction() {
store.delete(user: selectedUser!)
resetAndHide()
}
private func isValid() -> Bool {
if selectedUser == nil { // New user
if baseUrl.range(of: "^https?://.+", options: .regularExpression, range: nil, locale: nil) == nil {

View file

@ -97,7 +97,7 @@ struct SubscriptionAddView: View {
VStack(alignment: .leading, spacing: 0) {
Form {
Section(
footer: Text("This topic requires that you login with username and password. The user will be stored on your device, and will be re-used for other topics.")
footer: Text("This topic requires that you log in with username and password. The user will be stored on your device, and will be re-used for other topics.")
) {
TextField("Username", text: $username)
.disableAutocapitalization()