ChatLayout icon indicating copy to clipboard operation
ChatLayout copied to clipboard

Automatic resize cell without reload items or reload data.

Open hhoangna opened this issue 7 months ago • 3 comments

First of all, thank you @ekazaev for this amazing repository. I’ve been using it for a Chat project for over 2 years, and it’s still running smoothly. Today, I’m facing a new challenge: building an AI-powered conversation similar to ChatGPT. I’m having difficulty implementing real-time streaming of responses. I'm currently using a UITextView to display the content. Additionally, I need to change the height of the chat cell dynamically without reloading items or calling reloadData, as doing so breaks the streaming behavior. Could you please give me an idea on how to solve this issue with ChatLayout?

hhoangna avatar Jun 03 '25 16:06 hhoangna

@hhoangna Thank you for the nice words and you are welcome. I suggest you to try invalidateLayout in the cell - ChatLayout has a support for it. You can find some code in the example.

Meanwhile I personally use reconfigureItem for the similar case - it allows to process animations in a mode controlled manner. It still will be the same cell and same view so whatever updates you are doing should not break streaming behaviour.

You can see the example here:

https://github.com/user-attachments/assets/b1fbefe1-4d47-4bf8-a186-d7fd05b2125e

It is the effect you want to achieve when changing size while it is still the same UITextView and same cell.

NB: Keep in mind that reconfigureItem requires an extra implementation step due to it is not exposed to the custom UICollectionViewLayout api (classic Apple). But example app should also cover it.

ekazaev avatar Jun 04 '25 14:06 ekazaev

@ekazaev
I can't find any code about reconfigureItem in Example. Can you give me a Sample Source code like your demo video?

hhoangna avatar Jun 06 '25 04:06 hhoangna

@hhoangna let enableReconfigure = false in ChatViewController.swift enable this flag and check DifferenceKit+Extension.swift

ekazaev avatar Jun 10 '25 14:06 ekazaev