ekazaev / ChatLayout

ChatLayout is an alternative solution to MessageKit. It uses custom UICollectionViewLayout to provide you full control over the presentation as well as all the tools available in UICollectionView. It supports dynamic cells and supplementary view sizes.
MIT License
896 stars 67 forks source link

Enabling UICollectionView prefetch #73

Closed heoblitz closed 6 months ago

heoblitz commented 6 months ago

Hello @ekazaev Firstly, thank you for creating this nice open-source project.

I noticed that isPrefetchingEnabled for the collection view is being blocked in debug mode.

However, it seems that the bug reported at https://openradar.appspot.com/40926834 is not reproducible in the Example app, iOS 17.4.1, and iOS 15.1 environments.

When setting isPrefetchingEnabled to true in the Example app

Attempting to reproduce the reported bug in the Example app

Therefore, I thought it would be beneficial to either remove the preconditionFailure or add isPrefetchingEnabled to CollectionViewChatLayout so that developers can control it, in order to utilize the performance optimization of prefetching.

isPrefetchingEnabled = false

open override func prepare() {
    super.prepare()

    #if DEBUG
    if !isPrefetchingEnabled && collectionView.isPrefetchingEnabled {
         preconditionFailure("UICollectionView with prefetching enabled is not supported due to https://openradar.appspot.com/40926834 bug.")
    }
    #endif
}

If the above direction is okay, I'll try to raise the PR. If there's anything I'm missing, please let me know, thanks.

ekazaev commented 6 months ago

@heoblitz Hi, thank you for the issue. Yeah, I just added that becasue I got few requests in the past when people used the ChatLayout from scratch and got interface jumpy. Feel free to create a PR and remove that check. Or wait a bit ill update the library myself. It seems they actually fixed it.

heoblitz commented 6 months ago

Thank you for checking, @ekazaev I've submitted a simple PR.