File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,21 @@ open class MessagesCollectionView: UICollectionView {
8585
8686 scrollToItem ( at: indexPath, at: pos, animated: animated)
8787 }
88+
89+ public func scrollToBottom( animated: Bool = true ) {
90+ guard let indexPath = indexPathForLastItem else { return }
91+
92+ // scroll to the item without animation to get the desired offset
93+ scrollToItem ( at: indexPath, at: . bottom, animated: false )
94+ let targetOffset = contentOffset
95+
96+ // calculate the adjusted offset, considering the bottom section inset
97+ let sectionInsetBottom = ( collectionViewLayout as? UICollectionViewFlowLayout ) ? . sectionInset. bottom ?? 0
98+ let adjustedOffset = CGPoint ( x: targetOffset. x, y: targetOffset. y + sectionInsetBottom)
99+
100+ // set content offset to the adjusted offset
101+ setContentOffset ( adjustedOffset, animated: animated)
102+ }
88103
89104 public func reloadDataAndKeepOffset( ) {
90105 // stop scrolling
You can’t perform that action at this time.
0 commit comments