Last active
August 29, 2021 21:51
-
-
Save agammahajan1/9f5b3b267b8f417b3b8289cfef256c92 to your computer and use it in GitHub Desktop.
Custom Actions handling in Food item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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