Skip to content

Commit e5f9f87

Browse files
committed
Fixed restoring position at the top for the last message in the conversation
1 parent e5a72f9 commit e5f9f87

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ChatLayout/Classes/Core/CollectionViewChatLayout.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,12 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
620620
if let frame = controller.itemFrame(for: currentPositionSnapshot.indexPath.itemPath, kind: currentPositionSnapshot.kind, at: state, isFinal: true),
621621
contentHeight != 0,
622622
contentHeight > visibleBounds.size.height {
623+
let maxAllowed = max(-collectionView.adjustedContentInset.top, contentHeight - collectionView.frame.height + collectionView.adjustedContentInset.bottom)
623624
switch currentPositionSnapshot.edge {
624625
case .top:
625-
let desiredOffset = frame.minY - currentPositionSnapshot.offset - collectionView.adjustedContentInset.top - settings.additionalInsets.top
626+
let desiredOffset = max(min(maxAllowed, frame.minY - currentPositionSnapshot.offset - collectionView.adjustedContentInset.top - settings.additionalInsets.top), -collectionView.adjustedContentInset.top)
626627
context.contentOffsetAdjustment.y = desiredOffset - collectionView.contentOffset.y
627628
case .bottom:
628-
let maxAllowed = max(-collectionView.adjustedContentInset.top, contentHeight - collectionView.frame.height + collectionView.adjustedContentInset.bottom)
629629
let desiredOffset = max(min(maxAllowed, frame.maxY + currentPositionSnapshot.offset - collectionView.bounds.height + collectionView.adjustedContentInset.bottom + settings.additionalInsets.bottom), -collectionView.adjustedContentInset.top)
630630
context.contentOffsetAdjustment.y = desiredOffset - collectionView.contentOffset.y
631631
}

ChatLayout/Classes/Core/Extensions/CGRect+Extension.swift

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ extension CGRect {
2323
CGPoint(x: origin.x + size.width, y: origin.y + size.height)
2424
}
2525

26+
var centerPoint: CGPoint {
27+
CGPoint(x: origin.x + size.width / 2, y: origin.y + size.height / 2)
28+
}
29+
2630
@inline(__always) mutating func offsettingBy(dx: CGFloat, dy: CGFloat) {
2731
origin.x += dx
2832
origin.y += dy

0 commit comments

Comments
 (0)