ViewController.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // ViewController.swift
  3. // SheeeeeeeeetExample
  4. //
  5. // Created by Daniel Saidi on 2017-11-18.
  6. // Copyright © 2017 Daniel Saidi. All rights reserved.
  7. //
  8. /*
  9. To make the example easier to overview, the view controller
  10. has been split up into multiple files.
  11. The action sheet appearance is setup by `AppDelegate`, with
  12. the `AppDelegate+Appearance` extension. You can play around
  13. with it to see how it affects the example sheets and items.
  14. */
  15. import UIKit
  16. import Sheeeeeeeeet
  17. class ViewController: UIViewController {
  18. // MARK: - Properties
  19. var foodOptions: [FoodOption] {
  20. return [.fast, .light, .homeMade, .fancy, .none]
  21. }
  22. var tableViewOptions: [TableViewOption] = [
  23. .standard,
  24. .singleSelect,
  25. .multiSelect,
  26. .links,
  27. .headerView,
  28. .sections,
  29. .collections,
  30. .customView,
  31. .danger,
  32. .nonDismissable
  33. ]
  34. // MARK: - Outlets
  35. @IBOutlet weak var tableView: UITableView? {
  36. didSet {
  37. tableView?.delegate = self
  38. tableView?.dataSource = self
  39. }
  40. }
  41. @IBAction func testBarButtonTapped(_ sender: UIBarButtonItem) {
  42. let path = IndexPath(row: 1, section: 0)
  43. guard let sheet = actionSheet(at: path) else { return }
  44. sheet.presenter.events.didDismissWithBackgroundTap = { print("Background tap!") }
  45. sheet.present(in: self, from: sender)
  46. }
  47. // MARK: - Functions
  48. func actionSheet(at indexPath: IndexPath) -> ActionSheet? {
  49. let options = foodOptions
  50. switch tableViewOptions[indexPath.row] {
  51. case .collections: return CollectionActionSheet(options: options, action: alert)
  52. case .customView: return CustomActionSheet(options: options, buttonTapAction: alert)
  53. case .danger: return DestructiveActionSheet(options: options, action: alert)
  54. case .headerView: return HeaderActionSheet(options: options, action: alert)
  55. case .links: return LinkActionSheet(options: options, action: alert)
  56. case .multiSelect: return MultiSelectActionSheet(options: options, preselected: [.fancy, .fast], action: alert)
  57. case .sections: return SectionActionSheet(options: options, action: alert)
  58. case .singleSelect: return SingleSelectActionSheet(options: options, preselected: [.fancy, .fast], action: alert)
  59. case .standard: return StandardActionSheet(options: options, action: alert)
  60. case .nonDismissable:
  61. let sheet = StandardActionSheet(options: options, action: alert)
  62. sheet.presenter.isDismissableWithTapOnBackground = false
  63. return sheet
  64. }
  65. }
  66. }