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