Files
MessageKit/Sources/Protocols/MessagesLayoutDelegate.swift
T
Martin PúčikandGitHub 81395b6575 Swift Package Manager support without RxSwift dependency (#1341)
* feat: SPM support

Using InputAccessoryView dependency without Rx

* feat: SPM support

Add missing imports

* feat: Swift Package Manager support

Added Package description with Assets support for Swift 5.3

* feat: Swift Package Manager support

Remove .swiftpm temp files

* feat: Swift Package Manager support

Ignore .swiftpm temp files

* feat: Swift Package Manager support

Remove Package.resolved

* feat: Swift Package Manager support

Ignore Package.resolved

* feat: Swift Package Manager support

Assets in framework project

* feat: Swift Package Manager support

Fix tests

* feat: Swift Package Manager support

Fix tests

* feat: Swift Package Manager support

Fix tests

* feat: Swift Package Manager support

Try Bundle.module to get MessageKit bundle

* feat: Swift Package Manager support

SPM condition in bundle

* feat: Swift Package Manager support

Remove previous Swift 5.2 version Package.swift

* feat: Swift Package Manager support

Update Readme with SPM installation
2020-06-30 17:24:07 +02:00

165 lines
7.4 KiB
Swift

/*
MIT License
Copyright (c) 2017-2019 MessageKit
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import Foundation
import UIKit
/// A protocol used by the `MessagesCollectionViewFlowLayout` object to determine
/// the size and layout of a `MessageCollectionViewCell` and its contents.
public protocol MessagesLayoutDelegate: AnyObject {
/// Specifies the size to use for a header view.
///
/// - Parameters:
/// - section: The section number of the header.
/// - messagesCollectionView: The `MessagesCollectionView` in which this header will be displayed.
///
/// - Note:
/// The default value returned by this method is a size of `GGSize.zero`.
func headerViewSize(for section: Int, in messagesCollectionView: MessagesCollectionView) -> CGSize
/// Specifies the size to use for a footer view.
///
/// - Parameters:
/// - section: The section number of the footer.
/// - messagesCollectionView: The `MessagesCollectionView` in which this footer will be displayed.
///
/// - Note:
/// The default value returned by this method is a size of `GGSize.zero`.
func footerViewSize(for section: Int, in messagesCollectionView: MessagesCollectionView) -> CGSize
/// Specifies the size to use for a typing indicator view.
///
/// - Parameters:
/// - messagesCollectionView: The `MessagesCollectionView` in which this view will be displayed.
///
/// - Note:
/// The default value returned by this method is the width of the `messagesCollectionView` and
/// a height of 52.
func typingIndicatorViewSize(in messagesCollectionView: MessagesCollectionView) -> CGSize
/// Specifies the top inset to use for a typing indicator view.
///
/// - Parameters:
/// - messagesCollectionView: The `MessagesCollectionView` in which this view will be displayed.
///
/// - Note:
/// The default value returned by this method is a top inset of 15.
func typingIndicatorViewTopInset(in messagesCollectionView: MessagesCollectionView) -> CGFloat
/// Specifies the height for the `MessageContentCell`'s top label.
///
/// - Parameters:
/// - message: The `MessageType` that will be displayed for this cell.
/// - indexPath: The `IndexPath` of the cell.
/// - messagesCollectionView: The `MessagesCollectionView` in which this cell will be displayed.
///
/// - Note:
/// The default value returned by this method is zero.
func cellTopLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat
/// Specifies the height for the `MessageContentCell`'s bottom label.
///
/// - Parameters:
/// - message: The `MessageType` that will be displayed for this cell.
/// - indexPath: The `IndexPath` of the cell.
/// - messagesCollectionView: The `MessagesCollectionView` in which this cell will be displayed.
///
/// - Note:
/// The default value returned by this method is zero.
func cellBottomLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat
/// Specifies the height for the message bubble's top label.
///
/// - Parameters:
/// - message: The `MessageType` that will be displayed for this cell.
/// - indexPath: The `IndexPath` of the cell.
/// - messagesCollectionView: The `MessagesCollectionView` in which this cell will be displayed.
///
/// - Note:
/// The default value returned by this method is zero.
func messageTopLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat
/// Specifies the height for the `MessageContentCell`'s bottom label.
///
/// - Parameters:
/// - message: The `MessageType` that will be displayed for this cell.
/// - indexPath: The `IndexPath` of the cell.
/// - messagesCollectionView: The `MessagesCollectionView` in which this cell will be displayed.
///
/// - Note:
/// The default value returned by this method is zero.
func messageBottomLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat
/// Custom cell size calculator for messages with MessageType.custom.
///
/// - Parameters:
/// - message: The custom message
/// - indexPath: The `IndexPath` of the cell.
/// - messagesCollectionView: The `MessagesCollectionView` in which this cell will be displayed.
///
/// - Note:
/// The default implementation will throw fatalError(). You must override this method if you are using messages with MessageType.custom.
func customCellSizeCalculator(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CellSizeCalculator
}
public extension MessagesLayoutDelegate {
func headerViewSize(for section: Int, in messagesCollectionView: MessagesCollectionView) -> CGSize {
return .zero
}
func footerViewSize(for section: Int, in messagesCollectionView: MessagesCollectionView) -> CGSize {
return .zero
}
func typingIndicatorViewSize(in messagesCollectionView: MessagesCollectionView) -> CGSize {
return CGSize(width: messagesCollectionView.bounds.width, height: 48)
}
func typingIndicatorViewTopInset(in messagesCollectionView: MessagesCollectionView) -> CGFloat {
return 15
}
func cellTopLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat {
return 0
}
func cellBottomLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat {
return 0
}
func messageTopLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat {
return 0
}
func messageBottomLabelHeight(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGFloat {
return 0
}
func customCellSizeCalculator(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CellSizeCalculator {
fatalError("Must return a CellSizeCalculator for MessageKind.custom(Any?)")
}
}