Skip to content

Commit d85947c

Browse files
authored
Merge pull request #87 from ekazaev/chore/swift6.1_support
Swift 6.1 support
2 parents 4f54535 + 7418102 commit d85947c

Some content is hidden

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

47 files changed

+839
-697
lines changed

.swiftformat

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
--stripunusedargs closure-only
3030
--tabwidth unspecified
3131
--trimwhitespace always
32-
--wraparguments preserve
33-
--wrapcollections preserve
32+
--wraparguments before-first
33+
--wrapparameters before-first
34+
--wrapcollections before-first
3435
--xcodeindentation disabled
3536
--modifierorder public,override
3637
--nevertrailing map, flatMap, compactMap

ChatLayout.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Pod::Spec.new do |s|
22
s.name = 'ChatLayout'
3-
s.version = '2.1.1'
3+
s.version = '2.2.0'
44
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
5-
s.swift_version = '5.10'
5+
s.swift_version = '6.1'
66

77
s.description = <<-DESC
88
ChatLayout is a Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the
@@ -15,7 +15,7 @@ supplementary view sizes.
1515
s.author = { 'Eugene Kazaev' => 'eugene.kazaev@gmail.com' }
1616
s.source = { :git => 'https://github.com/ekazaev/ChatLayout.git', :tag => s.version.to_s }
1717

18-
s.ios.deployment_target = '12.0'
18+
s.ios.deployment_target = '13.0'
1919

2020
s.default_subspec = "Ultimate"
2121

ChatLayout.xcodeproj/project.pbxproj

Lines changed: 43 additions & 191 deletions
Large diffs are not rendered by default.

ChatLayout.xcodeproj/xcshareddata/xcschemes/ChatLayout.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1240"
3+
LastUpgradeVersion = "1640"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

ChatLayout/Classes/Core/ChatItemAlignment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414
import UIKit
1515

1616
/// Represent item alignment in collection view layout
17-
public enum ChatItemAlignment: Hashable {
17+
public enum ChatItemAlignment: Hashable, Sendable {
1818
/// Should be aligned at the leading edge of the layout. That includes all the additional content offsets.
1919
case leading
2020

ChatLayout/Classes/Core/ChatItemPinningType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Foundation
1414

1515
/// Represents pinning behavour of the element.
16-
public enum ChatItemPinningType: Hashable {
16+
public enum ChatItemPinningType: Hashable, Sendable {
1717
/// Represents top edge of the visible area.
1818
case top
1919

ChatLayout/Classes/Core/ChatLayoutAttributes.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,17 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {
7474
/// Returns a Boolean value indicating whether two `ChatLayoutAttributes` are considered equal.
7575
public override func isEqual(_ object: Any?) -> Bool {
7676
let chatLayoutAttributes = (object as? ChatLayoutAttributes)
77-
return super.isEqual(object)
78-
&& pinningType == chatLayoutAttributes?.pinningType
79-
&& alignment == chatLayoutAttributes?.alignment
80-
&& interItemSpacing == chatLayoutAttributes?.interItemSpacing
77+
/* isEqual inherits from ObjC and is not isolated.
78+
* ChatLayoutAttributes is MainActor isolated; in theory it **cannot** be used outside of the main actor.
79+
* If isEqual is called outside of the main actor, we’ll crash, which is good, because it would be unsafe anyway.
80+
* (One possible example would be to have a collection type that would do things on the background and compare two ChatLayoutAttributes,
81+
* but as stated above, that would be unsafe, so it’s good to crash if that happens.) */
82+
return MainActor.assumeIsolated {
83+
super.isEqual(chatLayoutAttributes)
84+
&& pinningType == chatLayoutAttributes?.pinningType
85+
&& alignment == chatLayoutAttributes?.alignment
86+
&& interItemSpacing == chatLayoutAttributes?.interItemSpacing
87+
}
8188
}
8289

8390
/// `ItemKind` represented by this attributes object.

ChatLayout/Classes/Core/ChatLayoutDelegate.swift

Lines changed: 105 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,27 @@ public enum InitialAttributesRequestType: Hashable {
2323
}
2424

2525
/// `CollectionViewChatLayout` delegate
26+
@MainActor
2627
public 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.
154177
public 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

Comments
 (0)