Skip to content

Commit 0b619fe

Browse files
author
Eugene Kazaev
committed
Fix for 1.1.11
1 parent 376b8ea commit 0b619fe

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
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.11'
3+
s.version = '1.1.12'
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/Model/StateController.swift

+32-24
Original file line numberDiff line numberDiff line change
@@ -631,31 +631,39 @@ final class StateController {
631631
break
632632
}
633633

634-
guard let firstMatchIndex = Array(section.items.enumerated()).binarySearch(predicate: { itemIndex, _ in
635-
let itemPath = ItemPath(item: itemIndex, section: sectionIndex)
636-
guard let itemFrame = self.itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
637-
return .orderedDescending
638-
}
639-
if itemFrame.intersects(visibleRect) {
640-
return .orderedSame
641-
}
642-
if itemFrame.minY > visibleRect.maxY {
643-
return .orderedDescending
644-
}
645-
return .orderedAscending
646-
}) else {
647-
break
648-
}
649-
var startingIndex = firstMatchIndex
650-
for itemIndex in (0..<firstMatchIndex).reversed() {
651-
let itemPath = ItemPath(item: itemIndex, section: sectionIndex)
652-
guard let itemFrame = itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
653-
continue
654-
}
655-
guard itemFrame.maxY >= visibleRect.minY else {
656-
break
634+
var startingIndex = 0
635+
// If header is not visible
636+
if traverseState == .notFound {
637+
// Find if any of the items of the section is visible
638+
if let firstMatchIndex = Array(section.items.enumerated()).binarySearch(predicate: { itemIndex, _ in
639+
let itemPath = ItemPath(item: itemIndex, section: sectionIndex)
640+
guard let itemFrame = self.itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
641+
return .orderedDescending
642+
}
643+
if itemFrame.intersects(visibleRect) {
644+
return .orderedSame
645+
}
646+
if itemFrame.minY > visibleRect.maxY {
647+
return .orderedDescending
648+
}
649+
return .orderedAscending
650+
}) {
651+
// Find first item that is visible
652+
startingIndex = firstMatchIndex
653+
for itemIndex in (0..<firstMatchIndex).reversed() {
654+
let itemPath = ItemPath(item: itemIndex, section: sectionIndex)
655+
guard let itemFrame = itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
656+
continue
657+
}
658+
guard itemFrame.maxY >= visibleRect.minY else {
659+
break
660+
}
661+
startingIndex = itemIndex
662+
}
663+
} else {
664+
// Otherwise we can safely skip all the items in the section and go to footer.
665+
startingIndex = section.items.count - 1
657666
}
658-
startingIndex = itemIndex
659667
}
660668

661669
if startingIndex < section.items.count {

Example/ChatLayout/Chat/View/ChatViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ extension ChatViewController: ChatControllerDelegate {
464464
return false
465465
},
466466
onInterruptedReload: {
467-
let positionSnapshot = ChatLayoutPositionSnapshot(indexPath: IndexPath(item: 0, section: 0), kind: .footer, edge: .bottom)
467+
let positionSnapshot = ChatLayoutPositionSnapshot(indexPath: IndexPath(item: 0, section: sections.count - 1), kind: .footer, edge: .bottom)
468468
self.collectionView.reloadData()
469469
// We want so that user on reload appeared at the very bottom of the layout
470470
self.chatLayout.restoreContentOffset(with: positionSnapshot)

Example/Podfile.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
PODS:
2-
- ChatLayout (1.1.10):
3-
- ChatLayout/Ultimate (= 1.1.10)
4-
- ChatLayout/Core (1.1.10)
5-
- ChatLayout/Extras (1.1.10):
2+
- ChatLayout (1.1.12):
3+
- ChatLayout/Ultimate (= 1.1.12)
4+
- ChatLayout/Core (1.1.12)
5+
- ChatLayout/Extras (1.1.12):
66
- ChatLayout/Core
7-
- ChatLayout/Ultimate (1.1.10):
7+
- ChatLayout/Ultimate (1.1.12):
88
- ChatLayout/Core
99
- ChatLayout/Extras
1010
- DifferenceKit (1.2.0):
@@ -35,7 +35,7 @@ EXTERNAL SOURCES:
3535
:path: "../"
3636

3737
SPEC CHECKSUMS:
38-
ChatLayout: 5d310eca192fd52bf44c51f668a788e9abcb126d
38+
ChatLayout: 8f41f556773cc215fad67a1064ec40badcd99c83
3939
DifferenceKit: 5659c430bb7fe45876fa32ce5cba5d6167f0c805
4040
FPSCounter: 884afec377de66637808c4f52ecc3b85a404732b
4141
InputBarAccessoryView: 74d471ab1fa1736806be50328df79257e52865a9

0 commit comments

Comments
 (0)