From a68e659303845ec09ce845876102027871a1f4b8 Mon Sep 17 00:00:00 2001 From: Wisors Date: Fri, 25 Aug 2023 17:53:33 +0100 Subject: [PATCH] Fix float precision bug during offset calculation During the final layout pass, there was a precision mismatch causing significant additional offset to be added to contentOffset. --- Chatto/sources/ChatController/BaseChatViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Chatto/sources/ChatController/BaseChatViewController.swift b/Chatto/sources/ChatController/BaseChatViewController.swift index aa99e92c..85db71d8 100644 --- a/Chatto/sources/ChatController/BaseChatViewController.swift +++ b/Chatto/sources/ChatController/BaseChatViewController.swift @@ -281,7 +281,8 @@ public final class BaseChatViewController: UIViewController { let diff = lastUsedBounds.height - collectionView.bounds.height // When collectionView is scrolled to bottom and height increases, // collectionView adjusts its contentOffset automatically - let isScrolledToBottom = contentSize.height <= collectionView.bounds.maxY - collectionView.contentInset.bottom + let currentBottomPosition = collectionView.bounds.maxY - collectionView.contentInset.bottom + let isScrolledToBottom = contentSize.height - currentBottomPosition <= CGFloat.bma_epsilon return isScrolledToBottom ? max(0, diff) : diff }() self.previousBoundsUsedForInsetsAdjustment = collectionView.bounds