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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

transitioning into the chat interface from the conversationList page is slow

520xiaopohai opened this issue · comments

Hello developer,

ChatLayout elegantly implements the layout of complex interfaces and offers smooth sliding. However, I've noticed that transitioning into the chat interface from the conversationList page is slow, even though the time taken to fetch data from the database is minimal.

Upon testing, I found that commenting out the line // KeyboardListener.shared.add(delegate: self) speeds up the display of the chat list. Alternatively, data displays quickly when pushing the conversationList controller with self.navigationController?.pushViewController(chatViewController, animated: false). But presenting the interface without animation feels awkward.

I've reviewed other issues such as:

#51
#40
Could you provide some optimization guidance?

Thank you.

RPReplay_Final1698737645.MP4

ChatViewController.swift.zip

@520xiaopohai Hi, thank you for the question.

Unfortunately I have nothing to add except what I already said here #51 The issue you are expecting is related to fact that you are populating the initial messages asynchronously. So it is absolutely normal behaviour what you see on the vide provided. There is an pushing animation curve and later the input view presentation curve. You must populate messages synchronously before you start the pushing animation. I have nothing to add here except you need to follow everything said here #51 (comment) There is a gif provided showing that if you follow the instruction - everything is fine.

Unfortunately, I dont have time to write an example code.

@520xiaopohai
I checked the code you provided
Screenshot 2023-10-31 at 14 02 41

Everything said above is valid. loadInitialMessages is asynchronous function. it must be like:

let sections = self.chatController.getInitialMessages()
...

There must be no asynchronous calls. It must happen within one runloop.

"good news Currently, I've modified the loadInitialMessages method to synchronously return the sections' values. It feels faster than the previous interface. As I'm fetching data from a Firebase database, it's challenging to handle the results synchronously. I tried using semaphores, but occasionally the UI would freeze. To circumvent this, I now pass in the initial data externally. However, I believe this is unrelated to another issue I'm experiencing: when transitioning from the conversationList to the ChatViewController, there is a noticeable jitter in the conversationList. Could you advise on what might need adjustment to address this jitter?"

I push the viewController like this
ChatViewControllerBuilder().build(chatWith: conversation.conversation.userIDs.last ?? "", conversation: conversation.conversation, chatTitle: conversation.user?.name ?? "") { chatvc in if let msgViewController = chatvc { self.navigationController?.pushViewController(msgViewController, animated: true) } }

I'm genuinely impressed with this framework, and it's been incredibly useful. I'd hate to abandon its use due to this minor flaw. I sincerely hope you can help address this issue. Thank you once again for your assistance and your outstanding work

the jitter is like this , a lillte shake in the video
https://github.com/ekazaev/ChatLayout/assets/10045191/f782bab8-2697-4d52-ad8c-3ee4fd6e4d21
未命名文件夹.zip

SCR-20231101-ksmx
and the instruments is like this

@520xiaopohai It is hard for me to say what is the reason for jittering on your video. Youll have to find out it yourself. It feels like you somehow manage to affect UINavigationController push animation. But you got the idea right. In the archive you provided you forgot to put the view controller itself btw.
Returning to the instruments screenshot - you can see that what takes time is layoutSubviews of the collection view. the subviews of the UICollectionView are UICollectionViewCells. It has nothing to do with the ChatLayout method restoreContentOffset. So to improve the situation here you need to optimise the cell structure. One more thing I can suggest here - make sure that you are using instruments in release build on the real device. Container views provided with the library use swift generics and they are not performing well in Debug builds.
I can only assure you that this library is used in the various apps in production and if everything is implemented correctly - there are no noticeable performance issues related to the library itself.

thank you~ I will try to make it

@520xiaopohai If you send me the view controllers code I can have a look and may be I can point you out what is the reason of jittering.

chatFiles.zip
Ekazaev, your enthusiasm is truly commendable. I would also be delighted to receive your assistance. My session controller is implemented using ConversationViewController, and the chat window is created with ChatViewControllerBuilder().build(chatWith: chatId, conversation: conversation.conversation, chatTitle: conversation.user?.name ?? "") { chatvc in if let msgViewController = chatvc { self.navigationController?.pushViewController(msgViewController, animated: true) } }

@520xiaopohai Sorry for the delay I was busy. I do not see anything suspicious in your view controller code so I cant really point you out to the problem without being able to run this code.

It's okay, I don't have time to make a runnable demo. I will follow up on this issue when I have time. If it can be simplified into a runnable demo, I will open this issue again. Thank you.