AvatarPosition.swift 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /// Used to determine the `Horizontal` and `Vertical` position of
  22. // an `AvatarView` in a `MessageCollectionViewCell`.
  23. public struct AvatarPosition {
  24. /// An enum representing the horizontal alignment of an `AvatarView`.
  25. public enum Horizontal {
  26. /// Positions the `AvatarView` on the side closest to the cell's leading edge.
  27. case cellLeading
  28. /// Positions the `AvatarView` on the side closest to the cell's trailing edge.
  29. case cellTrailing
  30. /// Positions the `AvatarView` based on whether the message is from the current Sender.
  31. /// The cell is positioned `.cellTrailling` if `isFromCurrentSender` is true
  32. /// and `.cellLeading` if false.
  33. case natural
  34. }
  35. /// An enum representing the verical alignment for an `AvatarView`.
  36. public enum Vertical {
  37. /// Aligns the `AvatarView`'s top edge to the cell's top edge.
  38. case cellTop
  39. /// Aligns the `AvatarView`'s top edge to the `messageTopLabel`'s top edge.
  40. case messageLabelTop
  41. /// Aligns the `AvatarView`'s top edge to the `MessageContainerView`'s top edge.
  42. case messageTop
  43. /// Aligns the `AvatarView` center to the `MessageContainerView` center.
  44. case messageCenter
  45. /// Aligns the `AvatarView`'s bottom edge to the `MessageContainerView`s bottom edge.
  46. case messageBottom
  47. /// Aligns the `AvatarView`'s bottom edge to the cell's bottom edge.
  48. case cellBottom
  49. }
  50. // MARK: - Properties
  51. // The vertical position
  52. public var vertical: Vertical
  53. // The horizontal position
  54. public var horizontal: Horizontal
  55. // MARK: - Initializers
  56. public init(horizontal: Horizontal, vertical: Vertical) {
  57. self.horizontal = horizontal
  58. self.vertical = vertical
  59. }
  60. public init(vertical: Vertical) {
  61. self.init(horizontal: .natural, vertical: vertical)
  62. }
  63. }
  64. // MARK: - Equatable Conformance
  65. extension AvatarPosition: Equatable {
  66. public static func == (lhs: AvatarPosition, rhs: AvatarPosition) -> Bool {
  67. return lhs.vertical == rhs.vertical && lhs.horizontal == rhs.horizontal
  68. }
  69. }