0

I am trying to figure how to show just the last messages like instagram and Facebook does when you click on a chat (in my case just one between 2 users).

After I observe all the messages, I then execute this which I think is standard

DispatchQueue.main.async(execute: {
     //scroll to the last index
     self.collectionView.reloadData()
     let indexPath = IndexPath(item: self.messages.count - 1, section: 0)
     self.collectionView?.scrollToItem(at: indexPath, at: .bottom, animated: false)
})

Unfortunately this will show scroll through the messages in a very glitchy way and does so each time I open a chat. I haven't been able to find a way to show the most recent messages online. Everyone seems to be using scrollToItem (animated doesn't matter because it looks choppy either way). How do I just show the most recent messages every time I click on a chat??

Aza
  • 63
  • 10
  • Animated does matter. It defines to either scroll to index instantaneously or with a slight animation by scrolling through other items. – Frankenstein Aug 15 '20 at 21:58
  • Ok but in my case animated false still shows a split second of it scrolling. So it's a still a problem for me. Is animated: false not supposed to show any signs of scrolling at all? – Aza Aug 15 '20 at 22:07
  • No, it doesn't mean it's not gonna show at all. It's still scrolling through them but in an instant. – Frankenstein Aug 15 '20 at 22:10
  • ok well that's why I said animated doesn't matter. Because it looks choppy either way. If someone knows an alternate to scrollingToIndex please let me know. – Aza Aug 15 '20 at 22:13

0 Answers0