@@ -23,22 +23,27 @@ public enum InitialAttributesRequestType: Hashable {
2323}
2424
2525/// `CollectionViewChatLayout` delegate
26+ @MainActor
2627public protocol ChatLayoutDelegate : AnyObject {
2728 /// `CollectionViewChatLayout` will call this method to ask if it should present the header in the current layout.
2829 /// - Parameters:
2930 /// - chatLayout: `CollectionViewChatLayout` reference.
3031 /// - sectionIndex: Index of the section.
3132 /// - Returns: `Bool`.
32- func shouldPresentHeader( _ chatLayout: CollectionViewChatLayout ,
33- at sectionIndex: Int ) -> Bool
33+ func shouldPresentHeader(
34+ _ chatLayout: CollectionViewChatLayout ,
35+ at sectionIndex: Int
36+ ) -> Bool
3437
3538 /// `CollectionViewChatLayout` will call this method to ask if it should present the footer in the current layout.
3639 /// - Parameters:
3740 /// - chatLayout: `CollectionViewChatLayout` reference.
3841 /// - sectionIndex: Index of the section.
3942 /// - Returns: `Bool`.
40- func shouldPresentFooter( _ chatLayout: CollectionViewChatLayout ,
41- at sectionIndex: Int ) -> Bool
43+ func shouldPresentFooter(
44+ _ chatLayout: CollectionViewChatLayout ,
45+ at sectionIndex: Int
46+ ) -> Bool
4247
4348 /// `CollectionViewChatLayout` will call this method to ask if it should pin (stick) the header to the visible bounds in the current layout.
4449 /// - Parameters:
@@ -47,8 +52,10 @@ public protocol ChatLayoutDelegate: AnyObject {
4752 /// - Returns: `Bool`.
4853 ///
4954 /// **NB:** This method will be called only if the `ChatLayoutSettings.pinnableItems` is set to `.supplementaryViews`
50- func shouldPinHeaderToVisibleBounds( _ chatLayout: CollectionViewChatLayout ,
51- at sectionIndex: Int ) -> Bool
55+ func shouldPinHeaderToVisibleBounds(
56+ _ chatLayout: CollectionViewChatLayout ,
57+ at sectionIndex: Int
58+ ) -> Bool
5259
5360 /// `CollectionViewChatLayout` will call this method to ask if it should pin (stick) the footer to the visible bounds in the current layout.
5461 /// - Parameters:
@@ -57,8 +64,10 @@ public protocol ChatLayoutDelegate: AnyObject {
5764 /// - Returns: `Bool`.
5865 ///
5966 /// **NB:** This method will be called only if the `ChatLayoutSettings.pinnableItems` is set to `.supplementaryViews`
60- func shouldPinFooterToVisibleBounds( _ chatLayout: CollectionViewChatLayout ,
61- at sectionIndex: Int ) -> Bool
67+ func shouldPinFooterToVisibleBounds(
68+ _ chatLayout: CollectionViewChatLayout ,
69+ at sectionIndex: Int
70+ ) -> Bool
6271
6372 /// `CollectionViewChatLayout` will call this method to ask if it should pin (stick) the cell to the visible bounds in the current layout.
6473 /// - Parameters:
@@ -67,8 +76,10 @@ public protocol ChatLayoutDelegate: AnyObject {
6776 /// - Returns: `ChatItemPinningType` to configure pinning behaviour or `nil` if pinning is not required.
6877 ///
6978 /// **NB:** This method will be called only if the `ChatLayoutSettings.pinnableItems` is set to `.cells`
70- func pinningTypeForItem( _ chatLayout: CollectionViewChatLayout ,
71- at indexPath: IndexPath ) -> ChatItemPinningType ?
79+ func pinningTypeForItem(
80+ _ chatLayout: CollectionViewChatLayout ,
81+ at indexPath: IndexPath
82+ ) -> ChatItemPinningType ?
7283
7384 /// `CollectionViewChatLayout` will call this method to ask what size the item should have.
7485 ///
@@ -84,19 +95,23 @@ public protocol ChatLayoutDelegate: AnyObject {
8495 /// - kind: Type of element represented by `ItemKind`.
8596 /// - indexPath: Index path of the item.
8697 /// - Returns: `ItemSize`.
87- func sizeForItem( _ chatLayout: CollectionViewChatLayout ,
88- of kind: ItemKind ,
89- at indexPath: IndexPath ) -> ItemSize
98+ func sizeForItem(
99+ _ chatLayout: CollectionViewChatLayout ,
100+ of kind: ItemKind ,
101+ at indexPath: IndexPath
102+ ) -> ItemSize
90103
91104 /// `CollectionViewChatLayout` will call this method to ask what type of alignment the item should have.
92105 /// - Parameters:
93106 /// - chatLayout: `CollectionViewChatLayout` reference.
94107 /// - kind: Type of element represented by `ItemKind`.
95108 /// - indexPath: Index path of the item.
96109 /// - Returns: `ChatItemAlignment`.
97- func alignmentForItem( _ chatLayout: CollectionViewChatLayout ,
98- of kind: ItemKind ,
99- at indexPath: IndexPath ) -> ChatItemAlignment
110+ func alignmentForItem(
111+ _ chatLayout: CollectionViewChatLayout ,
112+ of kind: ItemKind ,
113+ at indexPath: IndexPath
114+ ) -> ChatItemAlignment
100115
101116 /// Asks the delegate to modify a layout attributes instance so that it represents the initial visual state of an item
102117 /// being inserted.
@@ -109,11 +124,13 @@ public protocol ChatLayoutDelegate: AnyObject {
109124 /// - indexPath: Index path of the item.
110125 /// - originalAttributes: `ChatLayoutAttributes` that the `CollectionViewChatLayout` is going to use.
111126 /// - state: `InitialAttributesRequestType` instance. Represents when is this method being called.
112- func initialLayoutAttributesForInsertedItem( _ chatLayout: CollectionViewChatLayout ,
113- of kind: ItemKind ,
114- at indexPath: IndexPath ,
115- modifying originalAttributes: ChatLayoutAttributes ,
116- on state: InitialAttributesRequestType )
127+ func initialLayoutAttributesForInsertedItem(
128+ _ chatLayout: CollectionViewChatLayout ,
129+ of kind: ItemKind ,
130+ at indexPath: IndexPath ,
131+ modifying originalAttributes: ChatLayoutAttributes ,
132+ on state: InitialAttributesRequestType
133+ )
117134
118135 /// Asks the delegate to modify a layout attributes instance so that it represents the final visual state of an item
119136 /// being removed via `UICollectionView.deleteSections(_:)`.
@@ -125,104 +142,132 @@ public protocol ChatLayoutDelegate: AnyObject {
125142 /// - kind: Type of element represented by `ItemKind`.
126143 /// - indexPath: Index path of the item.
127144 /// - originalAttributes: `ChatLayoutAttributes` that the `CollectionViewChatLayout` is going to use.
128- func finalLayoutAttributesForDeletedItem( _ chatLayout: CollectionViewChatLayout ,
129- of kind: ItemKind ,
130- at indexPath: IndexPath ,
131- modifying originalAttributes: ChatLayoutAttributes )
145+ func finalLayoutAttributesForDeletedItem(
146+ _ chatLayout: CollectionViewChatLayout ,
147+ of kind: ItemKind ,
148+ at indexPath: IndexPath ,
149+ modifying originalAttributes: ChatLayoutAttributes
150+ )
132151
133152 /// Returns the interval between items. If returns `nil` - the value from `ChatLayoutSettings` will be used.
134153 ///
135154 /// - Parameters:
136155 /// - chatLayout: `CollectionViewChatLayout` reference.
137156 /// - kind: Type of element represented by `ItemKind`.
138157 /// - indexPath: Index path of the item.
139- func interItemSpacing( _ chatLayout: CollectionViewChatLayout ,
140- of kind: ItemKind ,
141- after indexPath: IndexPath ) -> CGFloat ?
158+ func interItemSpacing(
159+ _ chatLayout: CollectionViewChatLayout ,
160+ of kind: ItemKind ,
161+ after indexPath: IndexPath
162+ ) -> CGFloat ?
142163
143164 /// Returns the interval between sections. If returns `nil` - the value from `ChatLayoutSettings` will be used.
144165 ///
145166 /// - Parameters:
146167 /// - chatLayout: `CollectionViewChatLayout` reference.
147168 /// - kind: Type of element represented by `ItemKind`.
148169 /// - sectionIndex: Index of the section.
149- func interSectionSpacing( _ chatLayout: CollectionViewChatLayout ,
150- after sectionIndex: Int ) -> CGFloat ?
170+ func interSectionSpacing(
171+ _ chatLayout: CollectionViewChatLayout ,
172+ after sectionIndex: Int
173+ ) -> CGFloat ?
151174}
152175
153176/// Default extension.
154177public extension ChatLayoutDelegate {
155178 /// Default implementation returns: `false`.
156- func shouldPresentHeader( _ chatLayout: CollectionViewChatLayout ,
157- at sectionIndex: Int ) -> Bool {
179+ func shouldPresentHeader(
180+ _ chatLayout: CollectionViewChatLayout ,
181+ at sectionIndex: Int
182+ ) -> Bool {
158183 false
159184 }
160185
161186 /// Default implementation returns: `false`.
162- func shouldPresentFooter( _ chatLayout: CollectionViewChatLayout ,
163- at sectionIndex: Int ) -> Bool {
187+ func shouldPresentFooter(
188+ _ chatLayout: CollectionViewChatLayout ,
189+ at sectionIndex: Int
190+ ) -> Bool {
164191 false
165192 }
166193
167194 /// Default implementation returns: `false`.
168- func shouldPinHeaderToVisibleBounds( _ chatLayout: CollectionViewChatLayout ,
169- at sectionIndex: Int ) -> Bool {
195+ func shouldPinHeaderToVisibleBounds(
196+ _ chatLayout: CollectionViewChatLayout ,
197+ at sectionIndex: Int
198+ ) -> Bool {
170199 false
171200 }
172201
173202 /// Default implementation returns: `nil`.
174- func pinningTypeForItem( _ chatLayout: CollectionViewChatLayout ,
175- at indexPath: IndexPath ) -> ChatItemPinningType ? {
203+ func pinningTypeForItem(
204+ _ chatLayout: CollectionViewChatLayout ,
205+ at indexPath: IndexPath
206+ ) -> ChatItemPinningType ? {
176207 nil
177208 }
178209
179210 /// Default implementation returns: `false`.
180- func shouldPinFooterToVisibleBounds( _ chatLayout: CollectionViewChatLayout ,
181- at sectionIndex: Int ) -> Bool {
211+ func shouldPinFooterToVisibleBounds(
212+ _ chatLayout: CollectionViewChatLayout ,
213+ at sectionIndex: Int
214+ ) -> Bool {
182215 false
183216 }
184217
185218 /// Default implementation returns: `ItemSize.auto`.
186- func sizeForItem( _ chatLayout: CollectionViewChatLayout ,
187- of kind: ItemKind ,
188- at indexPath: IndexPath ) -> ItemSize {
219+ func sizeForItem(
220+ _ chatLayout: CollectionViewChatLayout ,
221+ of kind: ItemKind ,
222+ at indexPath: IndexPath
223+ ) -> ItemSize {
189224 . auto
190225 }
191226
192227 /// Default implementation returns: `ChatItemAlignment.fullWidth`.
193- func alignmentForItem( _ chatLayout: CollectionViewChatLayout ,
194- of kind: ItemKind ,
195- at indexPath: IndexPath ) -> ChatItemAlignment {
228+ func alignmentForItem(
229+ _ chatLayout: CollectionViewChatLayout ,
230+ of kind: ItemKind ,
231+ at indexPath: IndexPath
232+ ) -> ChatItemAlignment {
196233 . fullWidth
197234 }
198235
199236 /// Default implementation sets a `ChatLayoutAttributes.alpha` to zero.
200- func initialLayoutAttributesForInsertedItem( _ chatLayout: CollectionViewChatLayout ,
201- of kind: ItemKind ,
202- at indexPath: IndexPath ,
203- modifying originalAttributes: ChatLayoutAttributes ,
204- on state: InitialAttributesRequestType ) {
237+ func initialLayoutAttributesForInsertedItem(
238+ _ chatLayout: CollectionViewChatLayout ,
239+ of kind: ItemKind ,
240+ at indexPath: IndexPath ,
241+ modifying originalAttributes: ChatLayoutAttributes ,
242+ on state: InitialAttributesRequestType
243+ ) {
205244 originalAttributes. alpha = 0
206245 }
207246
208247 /// Default implementation sets a `ChatLayoutAttributes.alpha` to zero.
209- func finalLayoutAttributesForDeletedItem( _ chatLayout: CollectionViewChatLayout ,
210- of kind: ItemKind ,
211- at indexPath: IndexPath ,
212- modifying originalAttributes: ChatLayoutAttributes ) {
248+ func finalLayoutAttributesForDeletedItem(
249+ _ chatLayout: CollectionViewChatLayout ,
250+ of kind: ItemKind ,
251+ at indexPath: IndexPath ,
252+ modifying originalAttributes: ChatLayoutAttributes
253+ ) {
213254 originalAttributes. alpha = 0
214255 }
215256
216257 /// Default implementation returns: `nil`.
217- func interItemSpacing( _ chatLayout: CollectionViewChatLayout ,
218- of kind: ItemKind ,
219- after indexPath: IndexPath ) -> CGFloat ? {
258+ func interItemSpacing(
259+ _ chatLayout: CollectionViewChatLayout ,
260+ of kind: ItemKind ,
261+ after indexPath: IndexPath
262+ ) -> CGFloat ? {
220263 nil
221264 }
222265
223266 /// Default implementation returns: `nil`.
224- func interSectionSpacing( _ chatLayout: CollectionViewChatLayout ,
225- after sectionIndex: Int ) -> CGFloat ? {
267+ func interSectionSpacing(
268+ _ chatLayout: CollectionViewChatLayout ,
269+ after sectionIndex: Int
270+ ) -> CGFloat ? {
226271 nil
227272 }
228273}
0 commit comments