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