Skip to content

Commit b79fac9

Browse files
committed
Deprecated supplementary views.
1 parent 19cc55d commit b79fac9

File tree

89 files changed

+504
-297
lines changed

Some content is hidden

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

89 files changed

+504
-297
lines changed

ChatLayout.podspec

Lines changed: 2 additions & 2 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.2.3'
3+
s.version = '2.3.0'
44
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
5-
s.swift_version = '6.1'
5+
s.swift_version = '6.2'
66

77
s.description = <<-DESC
88
ChatLayout is a Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the

ChatLayout/Classes/Core/ChatLayoutAttributes.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {
4343
var id: UUID?
4444
#endif
4545

46+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
4647
convenience init(kind: ItemKind, indexPath: IndexPath = IndexPath(item: 0, section: 0)) {
4748
switch kind {
4849
case .cell:
@@ -54,6 +55,10 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {
5455
}
5556
}
5657

58+
convenience init(indexPath: IndexPath = IndexPath(item: 0, section: 0)) {
59+
self.init(forCellWith: indexPath)
60+
}
61+
5762
/// Returns an exact copy of `ChatLayoutAttributes`.
5863
public override func copy(with zone: NSZone? = nil) -> Any {
5964
let copy = super.copy(with: zone) as! ChatLayoutAttributes

ChatLayout/Classes/Core/ChatLayoutDelegate.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public protocol ChatLayoutDelegate: AnyObject {
3030
/// - chatLayout: `CollectionViewChatLayout` reference.
3131
/// - sectionIndex: Index of the section.
3232
/// - Returns: `Bool`.
33+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
3334
func shouldPresentHeader(
3435
_ chatLayout: CollectionViewChatLayout,
3536
at sectionIndex: Int
@@ -40,6 +41,7 @@ public protocol ChatLayoutDelegate: AnyObject {
4041
/// - chatLayout: `CollectionViewChatLayout` reference.
4142
/// - sectionIndex: Index of the section.
4243
/// - Returns: `Bool`.
44+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
4345
func shouldPresentFooter(
4446
_ chatLayout: CollectionViewChatLayout,
4547
at sectionIndex: Int
@@ -52,6 +54,7 @@ public protocol ChatLayoutDelegate: AnyObject {
5254
/// - Returns: `Bool`.
5355
///
5456
/// **NB:** This method will be called only if the `ChatLayoutSettings.pinnableItems` is set to `.supplementaryViews`
57+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
5558
func shouldPinHeaderToVisibleBounds(
5659
_ chatLayout: CollectionViewChatLayout,
5760
at sectionIndex: Int
@@ -64,6 +67,7 @@ public protocol ChatLayoutDelegate: AnyObject {
6467
/// - Returns: `Bool`.
6568
///
6669
/// **NB:** This method will be called only if the `ChatLayoutSettings.pinnableItems` is set to `.supplementaryViews`
70+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
6771
func shouldPinFooterToVisibleBounds(
6872
_ chatLayout: CollectionViewChatLayout,
6973
at sectionIndex: Int
@@ -176,6 +180,7 @@ public protocol ChatLayoutDelegate: AnyObject {
176180
/// Default extension.
177181
public extension ChatLayoutDelegate {
178182
/// Default implementation returns: `false`.
183+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
179184
func shouldPresentHeader(
180185
_ chatLayout: CollectionViewChatLayout,
181186
at sectionIndex: Int
@@ -184,6 +189,7 @@ public extension ChatLayoutDelegate {
184189
}
185190

186191
/// Default implementation returns: `false`.
192+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
187193
func shouldPresentFooter(
188194
_ chatLayout: CollectionViewChatLayout,
189195
at sectionIndex: Int
@@ -192,6 +198,7 @@ public extension ChatLayoutDelegate {
192198
}
193199

194200
/// Default implementation returns: `false`.
201+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
195202
func shouldPinHeaderToVisibleBounds(
196203
_ chatLayout: CollectionViewChatLayout,
197204
at sectionIndex: Int
@@ -208,6 +215,7 @@ public extension ChatLayoutDelegate {
208215
}
209216

210217
/// Default implementation returns: `false`.
218+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
211219
func shouldPinFooterToVisibleBounds(
212220
_ chatLayout: CollectionViewChatLayout,
213221
at sectionIndex: Int

ChatLayout/Classes/Core/ChatLayoutPositionSnapshot.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public struct ChatLayoutPositionSnapshot: Hashable, Sendable {
2828
public var indexPath: IndexPath
2929

3030
/// Kind of item at the `indexPath`
31+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
3132
public var kind: ItemKind
3233

3334
/// The edge of the offset.
@@ -42,6 +43,7 @@ public struct ChatLayoutPositionSnapshot: Hashable, Sendable {
4243
/// - edge: The edge of the offset.
4344
/// - offset: The offset from the `edge`.
4445
/// - kind: Kind of item at the `indexPath`
46+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
4547
public init(
4648
indexPath: IndexPath,
4749
kind: ItemKind,
@@ -53,4 +55,20 @@ public struct ChatLayoutPositionSnapshot: Hashable, Sendable {
5355
self.offset = offset
5456
self.kind = kind
5557
}
58+
59+
/// Constructor
60+
/// - Parameters:
61+
/// - indexPath: Item's `IndexPath`
62+
/// - edge: The edge of the offset.
63+
/// - offset: The offset from the `edge`.
64+
public init(
65+
indexPath: IndexPath,
66+
edge: Edge,
67+
offset: CGFloat = 0
68+
) {
69+
self.indexPath = indexPath
70+
self.edge = edge
71+
self.offset = offset
72+
kind = .cell
73+
}
5674
}

ChatLayout/Classes/Core/ChatLayoutSettings.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public struct ChatLayoutSettings: Equatable, Sendable {
1818
/// Represents type of pinnable elements in the layout.
1919
public enum PinneableItems: Equatable, Sendable {
2020
/// Pin supplementary views (header and/or footer).
21+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
2122
case supplementaryViews
2223
/// Pin cells
2324
case cells

ChatLayout/Classes/Core/Model/ItemKind.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,30 @@ import UIKit
1616
/// Type of the item supported by `CollectionViewChatLayout`
1717
public enum ItemKind: CaseIterable, Hashable, Sendable {
1818
/// Header item
19+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
1920
case header
2021

2122
/// Cell item
2223
case cell
2324

2425
/// Footer item
26+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
2527
case footer
2628

29+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
2730
init(_ elementKind: String) {
2831
switch elementKind {
2932
case UICollectionView.elementKindSectionHeader:
3033
self = .header
3134
case UICollectionView.elementKindSectionFooter:
3235
self = .footer
3336
default:
34-
preconditionFailure("Unsupported supplementary view kind.")
37+
preconditionFailure("Unsupported supplementary view kind: \(elementKind).")
3538
}
3639
}
3740

3841
/// Returns: `true` if this `ItemKind` is equal to `ItemKind.header` or `ItemKind.footer`
42+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
3943
public var isSupplementaryItem: Bool {
4044
switch self {
4145
case .cell:
@@ -47,6 +51,7 @@ public enum ItemKind: CaseIterable, Hashable, Sendable {
4751
}
4852

4953
@MainActor
54+
@available(*, deprecated, message: "Support for supplementary views is deprecated and will be discontinued in future versions.")
5055
var supplementaryElementStringType: String {
5156
switch self {
5257
case .cell:
@@ -57,4 +62,7 @@ public enum ItemKind: CaseIterable, Hashable, Sendable {
5762
UICollectionView.elementKindSectionFooter
5863
}
5964
}
65+
66+
/// A collection of all values of this type.
67+
public static var allCases: [ItemKind] { [.header, .cell, .footer] }
6068
}

Example/ChatLayout/AppDelegate.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2020
guard !ProcessInfo.isRunningTests else {
2121
return false
2222
}
23-
if #available(iOS 13.0, *) {
24-
} else {
25-
let window = UIWindow()
26-
27-
let chatViewController = ChatViewControllerBuilder().build()
28-
let viewController = UINavigationController(rootViewController: chatViewController)
29-
30-
self.window = window
31-
window.rootViewController = viewController
32-
window.makeKeyAndVisible()
33-
}
3423
return true
3524
}
3625

Example/ChatLayout/Chat/View/ChatViewController.swift

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ final class ChatViewController: UIViewController {
105105
super.viewDidLoad()
106106
fpsCounter.delegate = self
107107
fpsCounter.startTracking()
108-
if #available(iOS 13.0, *) {
109-
view.backgroundColor = .systemBackground
110-
} else {
111-
view.backgroundColor = .white
112-
}
108+
view.backgroundColor = .systemBackground
113109

114110
inputBarView.delegate = self
115111

@@ -118,13 +114,8 @@ final class ChatViewController: UIViewController {
118114
fpsView.layoutMargins = UIEdgeInsets(top: 8, left: 16, bottom: 0, right: 16)
119115
fpsView.customView.font = .preferredFont(forTextStyle: .caption2)
120116
fpsView.customView.text = "FPS: unknown"
121-
if #available(iOS 13.0, *) {
122-
fpsView.backgroundColor = .systemBackground
123-
fpsView.customView.textColor = .systemGray3
124-
} else {
125-
fpsView.backgroundColor = .white
126-
fpsView.customView.textColor = .lightGray
127-
}
117+
fpsView.backgroundColor = .systemBackground
118+
fpsView.customView.textColor = .systemGray3
128119
inputBarView.topStackView.addArrangedSubview(fpsView)
129120
inputBarView.shouldAnimateTextDidChangeLayout = true
130121
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Show Keyboard", style: .plain, target: self, action: #selector(ChatViewController.showHideKeyboard))
@@ -353,7 +344,11 @@ extension ChatViewController: UIScrollViewDelegate {
353344
collectionView.contentOffset = CGPoint(x: collectionView.contentOffset.x, y: initialOffset + (delta * percentage))
354345
if percentage == 1.0 {
355346
animator = nil
356-
let positionSnapshot = ChatLayoutPositionSnapshot(indexPath: IndexPath(item: 0, section: 0), kind: .footer, edge: .bottom)
347+
guard let lastSection = dataSource.sections.last else {
348+
collectionView.reloadData()
349+
return
350+
}
351+
let positionSnapshot = ChatLayoutPositionSnapshot(indexPath: IndexPath(item: lastSection.cells.count - 1, section: dataSource.sections.count - 1), edge: .bottom)
357352
chatLayout.restoreContentOffset(with: positionSnapshot)
358353
currentInterfaceActions.options.remove(.scrollingToBottom)
359354
completion?()
@@ -516,7 +511,11 @@ extension ChatViewController: ChatControllerDelegate {
516511
return false
517512
},
518513
onInterruptedReload: {
519-
let positionSnapshot = ChatLayoutPositionSnapshot(indexPath: IndexPath(item: 0, section: sections.count - 1), kind: .footer, edge: .bottom)
514+
guard let lastSection = sections.last else {
515+
self.collectionView.reloadData()
516+
return
517+
}
518+
let positionSnapshot = ChatLayoutPositionSnapshot(indexPath: IndexPath(item: lastSection.cells.count - 1, section: sections.count - 1), edge: .bottom)
520519
self.collectionView.reloadData()
521520
// We want so that user on reload appeared at the very bottom of the layout
522521
self.chatLayout.restoreContentOffset(with: positionSnapshot)

0 commit comments

Comments
 (0)