| 1 |
//
|
|
| 2 |
// ChatLayout
|
|
| 3 |
// ItemKind.swift
|
|
| 4 |
// https://github.com/ekazaev/ChatLayout
|
|
| 5 |
//
|
|
| 6 |
// Created by Eugene Kazaev in 2020-2023.
|
|
| 7 |
// Distributed under the MIT license.
|
|
| 8 |
//
|
|
| 9 |
// Become a sponsor:
|
|
| 10 |
// https://github.com/sponsors/ekazaev
|
|
| 11 |
//
|
|
| 12 |
|
|
| 13 |
import Foundation
|
|
| 14 |
import UIKit
|
|
| 15 |
|
|
| 16 |
/// Type of the item supported by `CollectionViewChatLayout`
|
|
| 17 |
public enum ItemKind: CaseIterable, Hashable {
|
|
| 18 |
|
|
| 19 |
/// Header item
|
|
| 20 |
case header
|
|
| 21 |
|
|
| 22 |
/// Cell item
|
|
| 23 |
case cell
|
|
| 24 |
|
|
| 25 |
/// Footer item
|
|
| 26 |
case footer
|
|
| 27 |
|
|
| 28 |
init(_ elementKind: String) {
|
4x |
| 29 |
switch elementKind {
|
4x |
| 30 |
case UICollectionView.elementKindSectionHeader:
|
4x |
| 31 |
self = .header
|
2x |
| 32 |
case UICollectionView.elementKindSectionFooter:
|
4x |
| 33 |
self = .footer
|
2x |
| 34 |
default:
|
4x |
| 35 |
preconditionFailure("Unsupported supplementary view kind.")
|
! |
| 36 |
}
|
4x |
| 37 |
}
|
4x |
| 38 |
|
|
| 39 |
/// Returns: `true` if this `ItemKind` is equal to `ItemKind.header` or `ItemKind.footer`
|
|
| 40 |
public var isSupplementaryItem: Bool {
|
3x |
| 41 |
switch self {
|
3x |
| 42 |
case .cell:
|
3x |
| 43 |
return false
|
1x |
| 44 |
case .header, .footer:
|
3x |
| 45 |
return true
|
2x |
| 46 |
}
|
3x |
| 47 |
}
|
3x |
| 48 |
|
|
| 49 |
var supplementaryElementStringType: String {
|
2x |
| 50 |
switch self {
|
2x |
| 51 |
case .cell:
|
2x |
| 52 |
preconditionFailure("Cell type is not a supplementary view.")
|
! |
| 53 |
case .header:
|
2x |
| 54 |
return UICollectionView.elementKindSectionHeader
|
1x |
| 55 |
case .footer:
|
2x |
| 56 |
return UICollectionView.elementKindSectionFooter
|
1x |
| 57 |
}
|
2x |
| 58 |
}
|
2x |
| 59 |
|
|
| 60 |
}
|
|