Honza Hudák (@ImHudys) header
Honza Hudák (@ImHudys) profile picture
Czech Republic
Joined January 2012
Photo by Honza Hudák (@ImHudys)
When I started building chat for our first companion app, I went with SwiftUI for the sake of development speed. But if chat is the core experience of the app, it MUST FEEL RIGHT! There are table stakes you need to meet... can you do that with SwiftUI? I immediately realized that List wasn’t the way to go for the feel and features I wanted (+ the keyboard handling was the worst). Using LazyVStack with ScrollView helped, but the content started flickering... 🥲 So, I switched to UITableView, which made a huge difference! The performance was much better and it easily unlocked a bunch of cool features like: • fine-grained scroll position tracking • handling of scroll view dragging All while still using SwiftUI views for the message content (via cell configuration 🔄 UIHostingConfiguration). I could notice some odd issues with cell insertion and keyboard inset behavior. Next steps? I moved to UICollectionView. Going all-in with Diffable Data Source and Compositional Layout. That helped a lot, again 🔥 Until... I wanted to replace a native Text with wrapped UITextView within the cell so that I can use a markdown (via NSAttributedString) and allow text selection. Streaming a response text resulted in weird cell sizing and crazy jumpiness 🕺🪩 I didn't know how to fix it. I didn't want to replace every cell view with a full UIKit implementation. So this week I tried a different approach and changed the cell setup. Instead of passing UIHostingConfiguration into contentConfiguration, I started using good ol' UICollectionViewCell with UIHostingController. And wow, it just WORKS! ✅ This way, I can use SwiftUI views for the majority of message cell components, but with much better performance. Next goal? Make it even smoother... 👀
16
14
7
490
64,816