# ContainerCollectionViewCellDelegate

    public protocol ContainerCollectionViewCellDelegate : AnyObject

A delegate of `ContainerCollectionViewCell`/`ContainerCollectionReusableView` should implement this methods if it is required to participate in containers lifecycle.

- `prepareForReuse()` Default implementation

  Perform any clean up necessary to prepare the view for use again.

  #### Default Implementation

  Default implementation does nothing.

  #### Declaration

  Swift

      func prepareForReuse()

- `preferredLayoutAttributesFitting(_:)` Default implementation

  Allows to override the call of `ContainerCollectionViewCell`/`ContainerCollectionReusableView` `UICollectionReusableView.preferredLayoutAttributesFitting(...)` and make the layout calculations.

  NB: You must override it to avoid unnecessary autolayout calculations if you are providing exact cell size in `ChatLayoutDelegate.sizeForItem(...)` and return `layoutAttributes` without modifications.

  #### Default Implementation

  Default implementation returns: `nil`.

  #### Declaration

  Swift

      func preferredLayoutAttributesFitting(_ layoutAttributes: ChatLayoutAttributes) -> ChatLayoutAttributes?

  #### Parameters

  `layoutAttributes` | `ChatLayoutAttributes` provided by `CollectionViewChatLayout`

  #### Return Value

  Modified `ChatLayoutAttributes` on nil if `UICollectionReusableView.preferredLayoutAttributesFitting(...)` should be called instead.

- `modifyPreferredLayoutAttributesFitting(_:)` Default implementation

  Allows to additionally modify `ChatLayoutAttributes` after the `UICollectionReusableView.preferredLayoutAttributesFitting(...)` call.

  #### Default Implementation

  Default implementation does nothing.

  #### Declaration

  Swift

      func modifyPreferredLayoutAttributesFitting(_ layoutAttributes: ChatLayoutAttributes)

  #### Parameters

  `layoutAttributes` | `ChatLayoutAttributes` provided by `CollectionViewChatLayout`.

  #### Return Value

  Modified `ChatLayoutAttributes`

- `apply(_:)` Default implementation

  Apply the specified layout attributes to the view. Keep in mind that this method can be called multiple times.

  #### Default Implementation

  Default implementation does nothing.

  #### Declaration

  Swift

      func apply(_ layoutAttributes: ChatLayoutAttributes)

  #### Parameters

  `layoutAttributes` | `ChatLayoutAttributes` provided by `CollectionViewChatLayout`.