Skip to content

Commit

Permalink
Fix for 1.1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Kazaev committed Oct 20, 2021
1 parent 376b8ea commit 0b619fe
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion ChatLayout.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ChatLayout'
s.version = '1.1.11'
s.version = '1.1.12'
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
s.swift_version = '5.2'

Expand Down
56 changes: 32 additions & 24 deletions ChatLayout/Classes/Core/Model/StateController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -631,31 +631,39 @@ final class StateController {
break
}

guard let firstMatchIndex = Array(section.items.enumerated()).binarySearch(predicate: { itemIndex, _ in
let itemPath = ItemPath(item: itemIndex, section: sectionIndex)
guard let itemFrame = self.itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
return .orderedDescending
}
if itemFrame.intersects(visibleRect) {
return .orderedSame
}
if itemFrame.minY > visibleRect.maxY {
return .orderedDescending
}
return .orderedAscending
}) else {
break
}
var startingIndex = firstMatchIndex
for itemIndex in (0..<firstMatchIndex).reversed() {
let itemPath = ItemPath(item: itemIndex, section: sectionIndex)
guard let itemFrame = itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
continue
}
guard itemFrame.maxY >= visibleRect.minY else {
break
var startingIndex = 0
// If header is not visible
if traverseState == .notFound {
// Find if any of the items of the section is visible
if let firstMatchIndex = Array(section.items.enumerated()).binarySearch(predicate: { itemIndex, _ in
let itemPath = ItemPath(item: itemIndex, section: sectionIndex)
guard let itemFrame = self.itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
return .orderedDescending
}
if itemFrame.intersects(visibleRect) {
return .orderedSame
}
if itemFrame.minY > visibleRect.maxY {
return .orderedDescending
}
return .orderedAscending
}) {
// Find first item that is visible
startingIndex = firstMatchIndex
for itemIndex in (0..<firstMatchIndex).reversed() {
let itemPath = ItemPath(item: itemIndex, section: sectionIndex)
guard let itemFrame = itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
continue
}
guard itemFrame.maxY >= visibleRect.minY else {
break
}
startingIndex = itemIndex
}
} else {
// Otherwise we can safely skip all the items in the section and go to footer.
startingIndex = section.items.count - 1
}
startingIndex = itemIndex
}

if startingIndex < section.items.count {
Expand Down
2 changes: 1 addition & 1 deletion Example/ChatLayout/Chat/View/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ extension ChatViewController: ChatControllerDelegate {
return false
},
onInterruptedReload: {
let positionSnapshot = ChatLayoutPositionSnapshot(indexPath: IndexPath(item: 0, section: 0), kind: .footer, edge: .bottom)
let positionSnapshot = ChatLayoutPositionSnapshot(indexPath: IndexPath(item: 0, section: sections.count - 1), kind: .footer, edge: .bottom)
self.collectionView.reloadData()
// We want so that user on reload appeared at the very bottom of the layout
self.chatLayout.restoreContentOffset(with: positionSnapshot)
Expand Down
12 changes: 6 additions & 6 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PODS:
- ChatLayout (1.1.10):
- ChatLayout/Ultimate (= 1.1.10)
- ChatLayout/Core (1.1.10)
- ChatLayout/Extras (1.1.10):
- ChatLayout (1.1.12):
- ChatLayout/Ultimate (= 1.1.12)
- ChatLayout/Core (1.1.12)
- ChatLayout/Extras (1.1.12):
- ChatLayout/Core
- ChatLayout/Ultimate (1.1.10):
- ChatLayout/Ultimate (1.1.12):
- ChatLayout/Core
- ChatLayout/Extras
- DifferenceKit (1.2.0):
Expand Down Expand Up @@ -35,7 +35,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
ChatLayout: 5d310eca192fd52bf44c51f668a788e9abcb126d
ChatLayout: 8f41f556773cc215fad67a1064ec40badcd99c83
DifferenceKit: 5659c430bb7fe45876fa32ce5cba5d6167f0c805
FPSCounter: 884afec377de66637808c4f52ecc3b85a404732b
InputBarAccessoryView: 74d471ab1fa1736806be50328df79257e52865a9
Expand Down

0 comments on commit 0b619fe

Please sign in to comment.