Skip to content

Instantly share code, notes, and snippets.

@agammahajan1
Last active August 29, 2021 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agammahajan1/9f5b3b267b8f417b3b8289cfef256c92 to your computer and use it in GitHub Desktop.
Save agammahajan1/9f5b3b267b8f417b3b8289cfef256c92 to your computer and use it in GitHub Desktop.
Custom Actions handling in Food item
let addItemAction = UIAccessibilityCustomAction(name: "Add one quantity of this item.") { [weak self] _ in
// add 1 quantity of the item selected
UIAccessibility.post(notification: .announcement, argument: "Item added, total number of items in cart now is \(noOfItems) with a subtotal of \(cartTotal) rupees")
}
let removeItemAction = UIAccessibilityCustomAction(name: "Remove one quantity of this item.") { [weak self] _ in
if itemsInCart {
//remove 1 quantity of the item selected
if noOfItems == 0 {
UIAccessibility.post(notification: .announcement, argument: "Item removed, no items in cart now")
} else {
UIAccessibility.post(notification: .announcement, argument: "Item removed, total number of items in cart now is \(noOfItems) with a subtotal of \(cartTotal) rupees")
}
} else if let addButton = self?.buyButton.addButton?.addButton {
UIAccessibility.post(notification: .announcement, argument: "No quantity of this item added.")
}
}
let goToCartAction = UIAccessibilityCustomAction(name: "Go to cart") { [weak self] _ in
if noOfItems > 0 {
// go to cart page
} else {
UIAccessibility.post(notification: .announcement, argument: "No items in cart. Please add an item first.")
}
}
itemView.accessibilityCustomActions = [addItemAction, removeItemAction, goToCartAction]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment