SwipeCollectionViewCellDelegate.swift 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // SwipeCollectionViewCellDelegate.swift
  3. //
  4. // Created by Jeremy Koch
  5. // Copyright © 2017 Jeremy Koch. All rights reserved.
  6. //
  7. import UIKit
  8. /**
  9. The `SwipeCollectionViewCellDelegate` protocol is adopted by an object that manages the display of action buttons when the item is swiped.
  10. */
  11. public protocol SwipeCollectionViewCellDelegate: class {
  12. /**
  13. Asks the delegate for the actions to display in response to a swipe in the specified item.
  14. - parameter collectionView: The collection view object which owns the item requesting this information.
  15. - parameter indexPath: The index path of the item.
  16. - parameter orientation: The side of the item requesting this information.
  17. - returns: An array of `SwipeAction` objects representing the actions for the item. Each action you provide is used to create a button that the user can tap. Returning `nil` will prevent swiping for the supplied orientation.
  18. */
  19. func collectionView(_ collectionView: UICollectionView, editActionsForItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]?
  20. /**
  21. Asks the delegate for the display options to be used while presenting the action buttons.
  22. - parameter collectionView: The collection view object which owns the item requesting this information.
  23. - parameter indexPath: The index path of the item.
  24. - parameter orientation: The side of the item requesting this information.
  25. - returns: A `SwipeOptions` instance which configures the behavior of the action buttons.
  26. - note: If not implemented, a default `SwipeOptions` instance is used.
  27. */
  28. func collectionView(_ collectionView: UICollectionView, editActionsOptionsForItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions
  29. /**
  30. Tells the delegate that the collection view is about to go into editing mode.
  31. - parameter collectionView: The collection view object providing this information.
  32. - parameter indexPath: The index path of the item.
  33. - parameter orientation: The side of the item.
  34. */
  35. func collectionView(_ collectionView: UICollectionView, willBeginEditingItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation)
  36. /**
  37. Tells the delegate that the collection view has left editing mode.
  38. - parameter collectionView: The collection view object providing this information.
  39. - parameter indexPath: The index path of the item.
  40. - parameter orientation: The side of the item.
  41. */
  42. func collectionView(_ collectionView: UICollectionView, didEndEditingItemAt indexPath: IndexPath?, for orientation: SwipeActionsOrientation)
  43. /**
  44. Asks the delegate for visibile rectangle of the collection view, which is used to ensure swipe actions are vertically centered within the visible portion of the item.
  45. - parameter collectionView: The collection view object providing this information.
  46. - returns: The visible rectangle of the collection view.
  47. - note: The returned rectange should be in the collection view's own coordinate system. Returning `nil` will result in no vertical offset to be be calculated.
  48. */
  49. func visibleRect(for collectionView: UICollectionView) -> CGRect?
  50. }
  51. /**
  52. Default implementation of `SwipeCollectionViewCellDelegate` methods
  53. */
  54. public extension SwipeCollectionViewCellDelegate {
  55. func collectionView(_ collectionView: UICollectionView, editActionsOptionsForItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions {
  56. return SwipeOptions()
  57. }
  58. func collectionView(_ collectionView: UICollectionView, willBeginEditingItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) {}
  59. func collectionView(_ collectionView: UICollectionView, didEndEditingItemAt indexPath: IndexPath?, for orientation: SwipeActionsOrientation) {}
  60. func visibleRect(for collectionView: UICollectionView) -> CGRect? {
  61. return nil
  62. }
  63. }