1 |
//
|
|
2 |
// ChatLayout
|
|
3 |
// ItemSize.swift
|
|
4 |
// https://github.com/ekazaev/ChatLayout
|
|
5 |
//
|
|
6 |
// Created by Eugene Kazaev in 2020-2022.
|
|
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 |
/// Represents desired item size.
|
|
17 |
public enum ItemSize: Hashable {
|
|
18 |
|
|
19 |
/// Item size should be fully calculated by the `CollectionViewChatLayout`. Initial estimated size will be taken from `ChatLayoutSettings`.
|
|
20 |
case auto
|
|
21 |
|
|
22 |
/// Item size should be fully calculated by the `CollectionViewChatLayout`. Initial estimated size should be taken from the value provided.
|
|
23 |
case estimated(CGSize)
|
|
24 |
|
|
25 |
/// Item size should be exactly equal to the value provided.
|
|
26 |
case exact(CGSize)
|
|
27 |
|
|
28 |
/// Represents current item size case type.
|
|
29 |
public enum CaseType: Hashable, CaseIterable {
|
|
30 |
/// Represents `ItemSize.auto`
|
|
31 |
case auto
|
|
32 |
/// Represents `ItemSize.estimated`
|
|
33 |
case estimated
|
|
34 |
/// Represents `ItemSize.exact`
|
|
35 |
case exact
|
|
36 |
}
|
|
37 |
|
|
38 |
/// Returns current item size case type.
|
|
39 |
public var caseType: CaseType {
|
! |
40 |
switch self {
|
! |
41 |
case .auto:
|
! |
42 |
return .auto
|
! |
43 |
case .estimated:
|
! |
44 |
return .estimated
|
! |
45 |
case .exact:
|
! |
46 |
return .exact
|
! |
47 |
}
|
! |
48 |
}
|
! |
49 |
|
|
50 |
public func hash(into hasher: inout Hasher) {
|
! |
51 |
hasher.combine(caseType)
|
! |
52 |
switch self {
|
! |
53 |
case .auto:
|
! |
54 |
break
|
! |
55 |
case let .estimated(size):
|
! |
56 |
hasher.combine(size.width)
|
! |
57 |
hasher.combine(size.height)
|
! |
58 |
case let .exact(size):
|
! |
59 |
hasher.combine(size.width)
|
! |
60 |
hasher.combine(size.height)
|
! |
61 |
}
|
! |
62 |
}
|
! |
63 |
|
|
64 |
}
|
|