MessageKit Version: latest
iOS Version(s): 11
Swift Version: 3
Devices/Simulators: all
Reproducible in ChatExample? (Yes/No):
When the view loads if doesnt scroll to the bottom, but does when the textfield is tapped, it also doesnt scroll to bottom when new message is posted
scroll to bottom on load as per using: scrollsToBottomOnFirstLayout = true in the viewdidload and scroll to bottom when send is tapped for a new message
it returns a nil value on guard lastSection > 0, numberOfItems(inSection: lastSection) > 0 else { return nil } from the func:
private var indexPathForLastItem: IndexPath? {
let lastSection = numberOfSections > 0 ? numberOfSections - 1 : 0
guard lastSection > 0, numberOfItems(inSection: lastSection) > 0 else { return nil }
return IndexPath(item: numberOfItems(inSection: lastSection) - 1, section: lastSection)
}
I'd like to add that the scrollToBottom doesn't happen when there are few messages(i.e, when the scroll doesn't appear) in the collection view and the keyboard when it appears hides the last few messages
@jackdem @iosNeophyte scrollsToBottomOnFirstLayout only works if you are not retrieving your messages asynchronously. It's called in the first call to viewDidLayoutSubviews, so if there are no messages in the collection view at this time, you won't scroll. You would have to call scrollToBottom() after you reloadData()
As for the other issue of not scrolling when new messages are sent, I'm aware of this one
Thanks that resolved the scrolling down. However on the view first load its not really animated well, its a jerky aggressive scroll down rather than smooth, can this be resolved?
Whats the ETA on a fix for new messages posting as its not great to not have this feature
@jackdem You can use scrollToBottom(animated: true) instead to have an animation. I'm working on fixing the scrolling for new messages as we speak. It's a weird one because it only breaks in certain situations depending on the contentSize, if the message is > 1 line, and it doesn't happen when stepping through code in a debugger
Thanks, i mean using true makes a kind of jerky scroll its not smooth.
Im using false which actually seems better and calling it on the api callback lets me push new messages up effectively enough to resolve my issues
I'm going to close this in favor of #302
I changed scrollToBottom() to scrollToBottom(animated: true) and it worked.
Most helpful comment
@jackdem You can use
scrollToBottom(animated: true)instead to have an animation. I'm working on fixing the scrolling for new messages as we speak. It's a weird one because it only breaks in certain situations depending on thecontentSize, if the message is > 1 line, and it doesn't happen when stepping through code in a debugger