Skip to content

Commit 7a62e82

Browse files
author
Eugene Kazaev
committed
Renamed ChatLayout object to CollectionViewChatLayout to avoid name clashes with the library name.
1 parent 971db15 commit 7a62e82

File tree

98 files changed

+4726
-4170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+4726
-4170
lines changed

ChatLayout.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'ChatLayout'
3-
s.version = '1.1.17'
3+
s.version = '1.2.0'
44
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
55
s.swift_version = '5.2'
66

ChatLayout/Classes/Core/ChatLayoutAttributes.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {
1616
/// Alignment of the current item. Can be changed within `UICollectionViewCell.preferredLayoutAttributesFitting(...)`
1717
public var alignment: ChatItemAlignment = .fullWidth
1818

19-
/// `ChatLayout`s additional insets setup using `ChatLayoutSettings`. Added for convenience.
19+
/// `CollectionViewChatLayout`s additional insets setup using `ChatLayoutSettings`. Added for convenience.
2020
public internal(set) var additionalInsets: UIEdgeInsets = .zero
2121

2222
/// `UICollectionView`s frame size. Added for convenience.
@@ -25,10 +25,10 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {
2525
/// `UICollectionView`s adjusted content insets. Added for convenience.
2626
public internal(set) var adjustedContentInsets: UIEdgeInsets = .zero
2727

28-
/// `ChatLayout`s visible bounds size excluding `adjustedContentInsets`. Added for convenience.
28+
/// `CollectionViewChatLayout`s visible bounds size excluding `adjustedContentInsets`. Added for convenience.
2929
public internal(set) var visibleBoundsSize: CGSize = .zero
3030

31-
/// `ChatLayout`s visible bounds size excluding `adjustedContentInsets` and `additionalInsets`. Added for convenience.
31+
/// `CollectionViewChatLayout`s visible bounds size excluding `adjustedContentInsets` and `additionalInsets`. Added for convenience.
3232
public internal(set) var layoutFrame: CGRect = .zero
3333

3434
#if DEBUG

ChatLayout/Classes/Core/ChatLayoutDelegate.swift

+26-26
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import Foundation
1111
import UIKit
1212

13-
/// Represents the point in time `ChatLayout` when chat layout asks about layout attributes modification.
13+
/// Represents the point in time when `CollectionViewChatLayout` asks about layout attributes modification.
1414
public enum InitialAttributesRequestType {
1515

1616
/// `UICollectionView` initially asks about the layout of an item.
@@ -21,26 +21,26 @@ public enum InitialAttributesRequestType {
2121

2222
}
2323

24-
/// `ChatLayout` delegate
24+
/// `CollectionViewChatLayout` delegate
2525
public protocol ChatLayoutDelegate: AnyObject {
2626

27-
/// `ChatLayout` will call this method to ask if it should present the header in the current layout.
27+
/// `CollectionViewChatLayout` will call this method to ask if it should present the header in the current layout.
2828
/// - Parameters:
29-
/// - chatLayout: ChatLayout reference.
29+
/// - chatLayout: `CollectionViewChatLayout` reference.
3030
/// - sectionIndex: Index of the section.
3131
/// - Returns: `Bool`.
32-
func shouldPresentHeader(_ chatLayout: ChatLayout,
32+
func shouldPresentHeader(_ chatLayout: CollectionViewChatLayout,
3333
at sectionIndex: Int) -> Bool
3434

35-
/// `ChatLayout` will call this method to ask if it should present the footer in the current layout.
35+
/// `CollectionViewChatLayout` will call this method to ask if it should present the footer in the current layout.
3636
/// - Parameters:
37-
/// - chatLayout: ChatLayout reference.
37+
/// - chatLayout: `CollectionViewChatLayout` reference.
3838
/// - sectionIndex: Index of the section.
3939
/// - Returns: `Bool`.
40-
func shouldPresentFooter(_ chatLayout: ChatLayout,
40+
func shouldPresentFooter(_ chatLayout: CollectionViewChatLayout,
4141
at sectionIndex: Int) -> Bool
4242

43-
/// `ChatLayout` will call this method to ask what size the item should have.
43+
/// `CollectionViewChatLayout` will call this method to ask what size the item should have.
4444
///
4545
/// **NB:**
4646
///
@@ -50,21 +50,21 @@ public protocol ChatLayoutDelegate: AnyObject {
5050
/// using Autolayout Engine anyway.
5151
///
5252
/// - Parameters:
53-
/// - chatLayout: ChatLayout reference.
53+
/// - chatLayout: `CollectionViewChatLayout` reference.
5454
/// - kind: Type of element represented by `ItemKind`.
5555
/// - indexPath: Index path of the item.
5656
/// - Returns: `ItemSize`.
57-
func sizeForItem(_ chatLayout: ChatLayout,
57+
func sizeForItem(_ chatLayout: CollectionViewChatLayout,
5858
of kind: ItemKind,
5959
at indexPath: IndexPath) -> ItemSize
6060

61-
/// `ChatLayout` will call this method to ask what type of alignment the item should have.
61+
/// `CollectionViewChatLayout` will call this method to ask what type of alignment the item should have.
6262
/// - Parameters:
63-
/// - chatLayout: ChatLayout reference.
63+
/// - chatLayout: `CollectionViewChatLayout` reference.
6464
/// - kind: Type of element represented by `ItemKind`.
6565
/// - indexPath: Index path of the item.
6666
/// - Returns: `ChatItemAlignment`.
67-
func alignmentForItem(_ chatLayout: ChatLayout,
67+
func alignmentForItem(_ chatLayout: CollectionViewChatLayout,
6868
of kind: ItemKind,
6969
at indexPath: IndexPath) -> ChatItemAlignment
7070

@@ -74,12 +74,12 @@ public protocol ChatLayoutDelegate: AnyObject {
7474
/// The `originalAttributes` instance is a reference type, and therefore can be modified directly.
7575
///
7676
/// - Parameters:
77-
/// - chatLayout: ChatLayout reference.
77+
/// - chatLayout: `CollectionViewChatLayout` reference.
7878
/// - kind: Type of element represented by `ItemKind`.
7979
/// - indexPath: Index path of the item.
80-
/// - originalAttributes: `ChatLayoutAttributes` that the `ChatLayout` is going to use.
80+
/// - originalAttributes: `ChatLayoutAttributes` that the `CollectionViewChatLayout` is going to use.
8181
/// - state: `InitialAttributesRequestType` instance. Represents when is this method being called.
82-
func initialLayoutAttributesForInsertedItem(_ chatLayout: ChatLayout,
82+
func initialLayoutAttributesForInsertedItem(_ chatLayout: CollectionViewChatLayout,
8383
of kind: ItemKind,
8484
at indexPath: IndexPath,
8585
modifying originalAttributes: ChatLayoutAttributes,
@@ -91,11 +91,11 @@ public protocol ChatLayoutDelegate: AnyObject {
9191
/// The `originalAttributes` instance is a reference type, and therefore can be modified directly.
9292
///
9393
/// - Parameters:
94-
/// - chatLayout: ChatLayout reference.
94+
/// - chatLayout: `CollectionViewChatLayout` reference.
9595
/// - kind: Type of element represented by `ItemKind`.
9696
/// - indexPath: Index path of the item.
97-
/// - originalAttributes: `ChatLayoutAttributes` that the `ChatLayout` is going to use.
98-
func finalLayoutAttributesForDeletedItem(_ chatLayout: ChatLayout,
97+
/// - originalAttributes: `ChatLayoutAttributes` that the `CollectionViewChatLayout` is going to use.
98+
func finalLayoutAttributesForDeletedItem(_ chatLayout: CollectionViewChatLayout,
9999
of kind: ItemKind,
100100
at indexPath: IndexPath,
101101
modifying originalAttributes: ChatLayoutAttributes)
@@ -106,33 +106,33 @@ public protocol ChatLayoutDelegate: AnyObject {
106106
public extension ChatLayoutDelegate {
107107

108108
/// Default implementation returns: `false`.
109-
func shouldPresentHeader(_ chatLayout: ChatLayout,
109+
func shouldPresentHeader(_ chatLayout: CollectionViewChatLayout,
110110
at sectionIndex: Int) -> Bool {
111111
return false
112112
}
113113

114114
/// Default implementation returns: `false`.
115-
func shouldPresentFooter(_ chatLayout: ChatLayout,
115+
func shouldPresentFooter(_ chatLayout: CollectionViewChatLayout,
116116
at sectionIndex: Int) -> Bool {
117117
return false
118118
}
119119

120120
/// Default implementation returns: `ItemSize.auto`.
121-
func sizeForItem(_ chatLayout: ChatLayout,
121+
func sizeForItem(_ chatLayout: CollectionViewChatLayout,
122122
of kind: ItemKind,
123123
at indexPath: IndexPath) -> ItemSize {
124124
return .auto
125125
}
126126

127127
/// Default implementation returns: `ChatItemAlignment.fullWidth`.
128-
func alignmentForItem(_ chatLayout: ChatLayout,
128+
func alignmentForItem(_ chatLayout: CollectionViewChatLayout,
129129
of kind: ItemKind,
130130
at indexPath: IndexPath) -> ChatItemAlignment {
131131
return .fullWidth
132132
}
133133

134134
/// Default implementation sets a `ChatLayoutAttributes.alpha` to zero.
135-
func initialLayoutAttributesForInsertedItem(_ chatLayout: ChatLayout,
135+
func initialLayoutAttributesForInsertedItem(_ chatLayout: CollectionViewChatLayout,
136136
of kind: ItemKind,
137137
at indexPath: IndexPath,
138138
modifying originalAttributes: ChatLayoutAttributes,
@@ -141,7 +141,7 @@ public extension ChatLayoutDelegate {
141141
}
142142

143143
/// Default implementation sets a `ChatLayoutAttributes.alpha` to zero.
144-
func finalLayoutAttributesForDeletedItem(_ chatLayout: ChatLayout,
144+
func finalLayoutAttributesForDeletedItem(_ chatLayout: CollectionViewChatLayout,
145145
of kind: ItemKind,
146146
at indexPath: IndexPath,
147147
modifying originalAttributes: ChatLayoutAttributes) {

ChatLayout/Classes/Core/ChatLayoutSettings.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
import Foundation
1111
import UIKit
1212

13-
/// `ChatLayout` settings.
13+
/// `CollectionViewChatLayout` settings.
1414
public struct ChatLayoutSettings: Equatable {
1515

16-
/// Estimated item size for `ChatLayout`. This value will be used as the initial size of the item and the final size
16+
/// Estimated item size for `CollectionViewChatLayout`. This value will be used as the initial size of the item and the final size
1717
/// will be calculated using `UICollectionViewCell.preferredLayoutAttributesFitting(...)`.
1818
public var estimatedItemSize: CGSize?
1919

@@ -23,7 +23,7 @@ public struct ChatLayoutSettings: Equatable {
2323
/// Spacing between the sections.
2424
public var interSectionSpacing: CGFloat = 0
2525

26-
/// Additional insets for the `ChatLayout` content.
26+
/// Additional insets for the `CollectionViewChatLayout` content.
2727
public var additionalInsets: UIEdgeInsets = .zero
2828

2929
}

ChatLayout/Classes/Core/ChatLayout.swift renamed to ChatLayout/Classes/Core/CollectionViewChatLayout.swift

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// ChatLayout
3-
// ChatLayout.swift
3+
// CollectionViewChatLayout.swift
44
// https://github.com/ekazaev/ChatLayout
55
//
66
// Created by Eugene Kazaev in 2020-2022.
@@ -14,28 +14,28 @@ import UIKit
1414
/// to the leading or trailing edge of the `UICollectionView`. Helps to maintain chat like behavior by keeping
1515
/// content offset from the bottom constant. Can deal with autosizing cells and supplementary views.
1616
/// ### Custom Properties:
17-
/// `ChatLayout.delegate`
17+
/// `CollectionViewChatLayout.delegate`
1818
///
19-
/// `ChatLayout.settings`
19+
/// `CollectionViewChatLayout.settings`
2020
///
21-
/// `ChatLayout.keepContentOffsetAtBottomOnBatchUpdates`
21+
/// `CollectionViewChatLayout.keepContentOffsetAtBottomOnBatchUpdates`
2222
///
23-
/// `ChatLayout.visibleBounds`
23+
/// `CollectionViewChatLayout.visibleBounds`
2424
///
25-
/// `ChatLayout.layoutFrame`
25+
/// `CollectionViewChatLayout.layoutFrame`
2626
///
2727
/// ### Custom Methods:
28-
/// `ChatLayout.getContentOffsetSnapshot(...)`
28+
/// `CollectionViewChatLayout.getContentOffsetSnapshot(...)`
2929
///
30-
/// `ChatLayout.restoreContentOffset(...)`
31-
public final class ChatLayout: UICollectionViewLayout {
30+
/// `CollectionViewChatLayout.restoreContentOffset(...)`
31+
public final class CollectionViewChatLayout: UICollectionViewLayout {
3232

3333
// MARK: Custom Properties
3434

35-
/// `ChatLayout` delegate.
35+
/// `CollectionViewChatLayout` delegate.
3636
public weak var delegate: ChatLayoutDelegate?
3737

38-
/// Additional settings for `ChatLayout`.
38+
/// Additional settings for `CollectionViewChatLayout`.
3939
public var settings = ChatLayoutSettings() {
4040
didSet {
4141
guard collectionView != nil,
@@ -47,11 +47,11 @@ public final class ChatLayout: UICollectionViewLayout {
4747
}
4848

4949
/// Default `UIScrollView` behaviour is to keep content offset constant from the top edge. If this flag is set to `true`
50-
/// `ChatLayout` should try to compensate batch update changes to keep the current content at the bottom of the visible
50+
/// `CollectionViewChatLayout` should try to compensate batch update changes to keep the current content at the bottom of the visible
5151
/// part of `UICollectionView`.
5252
///
5353
/// **NB:**
54-
/// Keep in mind that if during the batch content inset changes also (e.g. keyboard frame changes), `ChatLayout` will usually get that information after
54+
/// Keep in mind that if during the batch content inset changes also (e.g. keyboard frame changes), `CollectionViewChatLayout` will usually get that information after
5555
/// the animation starts and wont be able to compensate that change too. It should be done manually.
5656
public var keepContentOffsetAtBottomOnBatchUpdates: Bool = false
5757

@@ -80,7 +80,7 @@ public final class ChatLayout: UICollectionViewLayout {
8080

8181
// MARK: Inherited Properties
8282

83-
/// The direction of the language you used when designing `ChatLayout` layout.
83+
/// The direction of the language you used when designing `CollectionViewChatLayout` layout.
8484
public override var developmentLayoutDirection: UIUserInterfaceLayoutDirection {
8585
return .leftToRight
8686
}
@@ -382,8 +382,8 @@ public final class ChatLayout: UICollectionViewLayout {
382382
// immediately after an update is sent to the collection view via the insert/delete/reload/move
383383
// functions. Unfortunately, this is impossible - when batch updates occur, `invalidateLayout:`
384384
// is invoked immediately with a context that has `invalidateDataSourceCounts` set to `true`.
385-
// At this time, `ChatLayout` has no way of knowing the details of this data source count
386-
// change (where the insert/delete/move took place). `ChatLayout` only gets this additional
385+
// At this time, `CollectionViewChatLayout` has no way of knowing the details of this data source count
386+
// change (where the insert/delete/move took place). `CollectionViewChatLayout` only gets this additional
387387
// information once `prepareForCollectionViewUpdates:` is invoked. At that time, we're able to
388388
// update our layout's source of truth, the `StateController`, which allows us to resolve the
389389
// post-batch-update layout and return post-batch-update layout attributes from this function.
@@ -857,7 +857,7 @@ public final class ChatLayout: UICollectionViewLayout {
857857

858858
}
859859

860-
extension ChatLayout {
860+
extension CollectionViewChatLayout {
861861

862862
func configuration(for element: ItemKind, at itemPath: ItemPath) -> ItemModel.Configuration {
863863
let indexPath = itemPath.indexPath
@@ -925,7 +925,7 @@ extension ChatLayout {
925925

926926
}
927927

928-
extension ChatLayout: ChatLayoutRepresentation {
928+
extension CollectionViewChatLayout: ChatLayoutRepresentation {
929929

930930
func numberOfItems(in section: Int) -> Int {
931931
guard let collectionView = collectionView else {
@@ -944,7 +944,7 @@ extension ChatLayout: ChatLayoutRepresentation {
944944

945945
}
946946

947-
extension ChatLayout {
947+
extension CollectionViewChatLayout {
948948

949949
private var maxPossibleContentOffset: CGPoint {
950950
guard let collectionView = collectionView else {

ChatLayout/Classes/Core/Model/ItemKind.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import Foundation
1111
import UIKit
1212

13-
/// Type of the item supported by `ChatLayout`
13+
/// Type of the item supported by `CollectionViewChatLayout`
1414
public enum ItemKind: CaseIterable, Hashable {
1515

1616
/// Header item

ChatLayout/Classes/Core/Model/ItemSize.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import UIKit
1313
/// Represents desired item size.
1414
public enum ItemSize {
1515

16-
/// Item size should be fully calculated by the `ChatLayout`. Initial estimated size will be taken from `ChatLayoutSettings`.
16+
/// Item size should be fully calculated by the `CollectionViewChatLayout`. Initial estimated size will be taken from `ChatLayoutSettings`.
1717
case auto
1818

19-
/// Item size should be fully calculated by the `ChatLayout`. Initial estimated size should be taken from the value provided.
19+
/// Item size should be fully calculated by the `CollectionViewChatLayout`. Initial estimated size should be taken from the value provided.
2020
case estimated(CGSize)
2121

2222
/// Item size should be exactly equal to the value provided.

ChatLayout/Classes/Extras/ContainerCollectionViewCellDelegate.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ public protocol ContainerCollectionViewCellDelegate: AnyObject {
2222
///
2323
/// **NB**: You must override it to avoid unnecessary autolayout calculations if you are providing exact cell size
2424
/// in `ChatLayoutDelegate.sizeForItem(...)` and return `layoutAttributes` without modifications.
25-
/// - Parameter layoutAttributes: `ChatLayoutAttributes` provided by `ChatLayout`
25+
/// - Parameter layoutAttributes: `ChatLayoutAttributes` provided by `CollectionViewChatLayout`
2626
/// - Returns: Modified `ChatLayoutAttributes` on nil if `UICollectionReusableView.preferredLayoutAttributesFitting(...)`
2727
/// should be called instead.
2828
func preferredLayoutAttributesFitting(_ layoutAttributes: ChatLayoutAttributes) -> ChatLayoutAttributes?
2929

3030
/// Allows to additionally modify `ChatLayoutAttributes` after the `UICollectionReusableView.preferredLayoutAttributesFitting(...)`
3131
/// call.
32-
/// - Parameter layoutAttributes: `ChatLayoutAttributes` provided by `ChatLayout`.
32+
/// - Parameter layoutAttributes: `ChatLayoutAttributes` provided by `CollectionViewChatLayout`.
3333
/// - Returns: Modified `ChatLayoutAttributes`
3434
func modifyPreferredLayoutAttributesFitting(_ layoutAttributes: ChatLayoutAttributes)
3535

3636
/// Apply the specified layout attributes to the view.
3737
/// Keep in mind that this method can be called multiple times.
38-
/// - Parameter layoutAttributes: `ChatLayoutAttributes` provided by `ChatLayout`.
38+
/// - Parameter layoutAttributes: `ChatLayoutAttributes` provided by `CollectionViewChatLayout`.
3939
func apply(_ layoutAttributes: ChatLayoutAttributes)
4040

4141
}

Example/ChatLayout/Chat/View/ChatViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ final class ChatViewController: UIViewController {
5050
private let editNotifier: EditNotifier
5151
private let swipeNotifier: SwipeNotifier
5252
private var collectionView: UICollectionView!
53-
private var chatLayout = ChatLayout()
53+
private var chatLayout = CollectionViewChatLayout()
5454
private let inputBarView = InputBarAccessoryView()
5555
private let chatController: ChatController
5656
private let dataSource: ChatCollectionDataSource
@@ -184,7 +184,7 @@ final class ChatViewController: UIViewController {
184184
if let positionSnapshot = positionSnapshot,
185185
!self.isUserInitiatedScrolling {
186186
// As contentInsets may change when size transition has already started. For example, `UINavigationBar` height may change
187-
// to compact and back. `ChatLayout` may not properly predict the final position of the element. So we try
187+
// to compact and back. `CollectionViewChatLayout` may not properly predict the final position of the element. So we try
188188
// to restore it after the rotation manually.
189189
self.chatLayout.restoreContentOffset(with: positionSnapshot)
190190
}

0 commit comments

Comments
 (0)