From a02dcfd9dce4a9261c893ced22f94b0019e7ecfc Mon Sep 17 00:00:00 2001 From: Valerii Chevtaev Date: Mon, 13 Mar 2017 11:06:49 +0000 Subject: [PATCH] Return empty layout model is layout delegate is empty. --- .../Collaborators/ChatCollectionViewLayout.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Chatto/Source/ChatController/Collaborators/ChatCollectionViewLayout.swift b/Chatto/Source/ChatController/Collaborators/ChatCollectionViewLayout.swift index 64d3be417..e1c5834af 100644 --- a/Chatto/Source/ChatController/Collaborators/ChatCollectionViewLayout.swift +++ b/Chatto/Source/ChatController/Collaborators/ChatCollectionViewLayout.swift @@ -60,6 +60,15 @@ public struct ChatCollectionViewLayoutModel { calculatedForWidth: collectionViewWidth ) } + + public static func createEmptyModel() -> ChatCollectionViewLayoutModel { + return ChatCollectionViewLayoutModel( + contentSize: .zero, + layoutAttributes: [], + layoutAttributesBySectionAndItem: [], + calculatedForWidth: 0 + ) + } } open class ChatCollectionViewLayout: UICollectionViewLayout { @@ -77,7 +86,10 @@ open class ChatCollectionViewLayout: UICollectionViewLayout { open override func prepare() { super.prepare() guard self.layoutNeedsUpdate else { return } - guard let delegate = self.delegate else { return } + guard let delegate = self.delegate else { + self.layoutModel = ChatCollectionViewLayoutModel.createEmptyModel() + return + } var oldLayoutModel = self.layoutModel self.layoutModel = delegate.chatCollectionViewLayoutModel() self.layoutNeedsUpdate = false