MessagesLayoutDelegate.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. MIT License
  3. Copyright (c) 2017-2018 MessageKit
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. */
  20. import Foundation
  21. /// A protocol used by the `MessagesCollectionViewFlowLayout` object to determine
  22. /// the size and layout of a `MessageCollectionViewCell` and its contents.
  23. public protocol MessagesLayoutDelegate: AnyObject {
  24. /// Specifies the size to use for a header view.
  25. ///
  26. /// - Parameters:
  27. /// - section: The section number of the header.
  28. /// - messagesCollectionView: The `MessagesCollectionView` in which this header will be displayed.
  29. ///
  30. /// - Note:
  31. /// The default value returned by this method is a size of `GGSize.zero`.
  32. func headerViewSize(for section: Int, in messagesCollectionView: MessagesCollectionView) -> CGSize
  33. /// Specifies the size to use for a footer view.
  34. ///
  35. /// - Parameters:
  36. /// - section: The section number of the footer.
  37. /// - messagesCollectionView: The `MessagesCollectionView` in which this footer will be displayed.
  38. ///
  39. /// - Note:
  40. /// The default value returned by this method is a size of `GGSize.zero`.
  41. func footerViewSize(for section: Int, in messagesCollectionView: MessagesCollectionView) -> CGSize
  42. /// Specifies the height for the `MessageContentCell`'s top label.
  43. ///
  44. /// - Parameters:
  45. /// - message: The `MessageType` that will be displayed for this cell.
  46. /// - indexPath: The `IndexPath` of the cell.
  47. /// - messagesCollectionView: The `MessagesCollectionView` in which this cell will be displayed.
  48. ///
  49. /// - Note:
  50. /// The default value returned by this method is zero.
  51. func cellTopLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat
  52. /// Specifies the height for the message bubble's top label.
  53. ///
  54. /// - Parameters:
  55. /// - message: The `MessageType` that will be displayed for this cell.
  56. /// - indexPath: The `IndexPath` of the cell.
  57. /// - messagesCollectionView: The `MessagesCollectionView` in which this cell will be displayed.
  58. ///
  59. /// - Note:
  60. /// The default value returned by this method is zero.
  61. func messageTopLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat
  62. /// Specifies the height for the `MessageContentCell`'s bottom label.
  63. ///
  64. /// - Parameters:
  65. /// - message: The `MessageType` that will be displayed for this cell.
  66. /// - indexPath: The `IndexPath` of the cell.
  67. /// - messagesCollectionView: The `MessagesCollectionView` in which this cell will be displayed.
  68. ///
  69. /// - Note:
  70. /// The default value returned by this method is zero.
  71. func messageBottomLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat
  72. }
  73. public extension MessagesLayoutDelegate {
  74. func headerViewSize(for section: Int, in messagesCollectionView: MessagesCollectionView) -> CGSize {
  75. return .zero
  76. }
  77. func footerViewSize(for section: Int, in messagesCollectionView: MessagesCollectionView) -> CGSize {
  78. return .zero
  79. }
  80. func cellTopLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat {
  81. return 0
  82. }
  83. func messageTopLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat {
  84. return 0
  85. }
  86. func messageBottomLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat {
  87. return 0
  88. }
  89. }