| 1 |
//
|
|
| 2 |
// ChatLayout
|
|
| 3 |
// ItemSize.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 |
/// 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 {
|
17x |
| 40 |
switch self {
|
17x |
| 41 |
case .auto:
|
17x |
| 42 |
return .auto
|
5x |
| 43 |
case .estimated:
|
17x |
| 44 |
return .estimated
|
7x |
| 45 |
case .exact:
|
17x |
| 46 |
return .exact
|
5x |
| 47 |
}
|
17x |
| 48 |
}
|
17x |
| 49 |
|
|
| 50 |
public func hash(into hasher: inout Hasher) {
|
17x |
| 51 |
hasher.combine(caseType)
|
17x |
| 52 |
switch self {
|
17x |
| 53 |
case .auto:
|
17x |
| 54 |
break
|
5x |
| 55 |
case let .estimated(size):
|
17x |
| 56 |
hasher.combine(size.width)
|
7x |
| 57 |
hasher.combine(size.height)
|
7x |
| 58 |
case let .exact(size):
|
17x |
| 59 |
hasher.combine(size.width)
|
5x |
| 60 |
hasher.combine(size.height)
|
5x |
| 61 |
}
|
17x |
| 62 |
}
|
17x |
| 63 |
|
|
| 64 |
}
|
|