SectionActionSheet.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // SectionActionSheet.swift
  3. // SheeeeeeeeetExample
  4. //
  5. // Created by Jonas Ullström on 2018-03-16.
  6. // Copyright © 2018 Jonas Ullström. All rights reserved.
  7. //
  8. import Sheeeeeeeeet
  9. class SectionActionSheet: ActionSheet {
  10. init(options: [FoodOption], action: @escaping ([ActionSheetItem]) -> ()) {
  11. let items = SectionActionSheet.items(for: options)
  12. super.init(items: items) { _, item in
  13. if item.value == nil { return }
  14. action([item])
  15. }
  16. }
  17. required init?(coder aDecoder: NSCoder) {
  18. super.init(coder: aDecoder)
  19. }
  20. }
  21. private extension SectionActionSheet {
  22. static func items(for options: [FoodOption]) -> [ActionSheetItem] {
  23. var items = [ActionSheetItem]()
  24. items.append(titleItem(title: standardTitle))
  25. items.append(ActionSheetSectionTitle(title: "Cheap"))
  26. let cheap = options.filter { $0.isCheap }.map { $0.item() }
  27. cheap.forEach { items.append($0) }
  28. items.append(ActionSheetSectionMargin())
  29. items.append(ActionSheetSectionTitle(title: "Expensive"))
  30. let expensive = options.filter { !$0.isCheap }.map { $0.item() }
  31. expensive.forEach { items.append($0) }
  32. items.append(cancelButton)
  33. return items
  34. }
  35. }