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

@ -88,11 +88,34 @@ struct UsersView: View {
.navigationTitle(selectedUser == nil ? "Add user" : "Edit user") .navigationTitle(selectedUser == nil ? "Add user" : "Edit user")
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.toolbar { .toolbar {
ToolbarItem(placement: .navigationBarLeading) { ToolbarItem(placement: .navigationBarLeading) {
Button(action: cancelAction) { // Sigh, for iOS 14 we need to add a "Delete" menu item, because it doesn't support
Text("Cancel") // 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) { ToolbarItem(placement: .navigationBarTrailing) {
Button(action: saveAction) { Button(action: saveAction) {
Text("Save") Text("Save")
@ -117,6 +140,11 @@ struct UsersView: View {
resetAndHide() resetAndHide()
} }
private func deleteAction() {
store.delete(user: selectedUser!)
resetAndHide()
}
private func isValid() -> Bool { private func isValid() -> Bool {
if selectedUser == nil { // New user if selectedUser == nil { // New user
if baseUrl.range(of: "^https?://.+", options: .regularExpression, range: nil, locale: nil) == nil { 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) { VStack(alignment: .leading, spacing: 0) {
Form { Form {
Section( 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) TextField("Username", text: $username)
.disableAutocapitalization() .disableAutocapitalization()