Slather logo

Coverage for "ContainerCollectionViewCellDelegate.swift" : 0.00%

(0 of 6 relevant lines covered)

ChatLayout/Classes/Extras/ContainerCollectionViewCellDelegate.swift

1
//
2
// ChatLayout
3
// ContainerCollectionViewCellDelegate.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
/// A delegate of `ContainerCollectionViewCell`/`ContainerCollectionReusableView` should implement this methods if
17
/// it is required to participate in containers lifecycle.
18
public protocol ContainerCollectionViewCellDelegate: AnyObject {
19
20
    /// Perform any clean up necessary to prepare the view for use again.
21
    func prepareForReuse()
22
23
    /// Allows to override the call of `ContainerCollectionViewCell`/`ContainerCollectionReusableView`
24
    /// `UICollectionReusableView.preferredLayoutAttributesFitting(...)` and make the layout calculations.
25
    ///
26
    /// **NB**: You must override it to avoid unnecessary autolayout calculations if you are providing exact cell size
27
    /// in `ChatLayoutDelegate.sizeForItem(...)` and return `layoutAttributes` without modifications.
28
    /// - Parameter layoutAttributes: `ChatLayoutAttributes` provided by `CollectionViewChatLayout`
29
    /// - Returns: Modified `ChatLayoutAttributes` on nil if `UICollectionReusableView.preferredLayoutAttributesFitting(...)`
30
    ///            should be called instead.
31
    func preferredLayoutAttributesFitting(_ layoutAttributes: ChatLayoutAttributes) -> ChatLayoutAttributes?
32
33
    /// Allows to additionally modify `ChatLayoutAttributes` after the `UICollectionReusableView.preferredLayoutAttributesFitting(...)`
34
    /// call.
35
    /// - Parameter layoutAttributes: `ChatLayoutAttributes` provided by `CollectionViewChatLayout`.
36
    /// - Returns: Modified `ChatLayoutAttributes`
37
    func modifyPreferredLayoutAttributesFitting(_ layoutAttributes: ChatLayoutAttributes)
38
39
    /// Apply the specified layout attributes to the view.
40
    /// Keep in mind that this method can be called multiple times.
41
    /// - Parameter layoutAttributes: `ChatLayoutAttributes` provided by `CollectionViewChatLayout`.
42
    func apply(_ layoutAttributes: ChatLayoutAttributes)
43
44
}
45
46
/// Default extension to make the methods optional for implementation in the successor
47
public extension ContainerCollectionViewCellDelegate {
48
49
    /// Default implementation does nothing.
50
    func prepareForReuse() {}
!
51
52
    /// Default implementation returns: `nil`.
53
    func preferredLayoutAttributesFitting(_ layoutAttributes: ChatLayoutAttributes) -> ChatLayoutAttributes? {
!
54
        nil
!
55
    }
!
56
57
    /// Default implementation does nothing.
58
    func modifyPreferredLayoutAttributesFitting(_ layoutAttributes: ChatLayoutAttributes) {}
!
59
60
    /// Default implementation does nothing.
61
    func apply(_ layoutAttributes: ChatLayoutAttributes) {}
!
62
63
}