Messagekit: Not scrolling to bottom on first load / when new message is sent?

Created on 7 Nov 2017  路  7Comments  路  Source: MessageKit/MessageKit

General Information

  • MessageKit Version: latest

  • iOS Version(s): 11

  • Swift Version: 3

  • Devices/Simulators: all

  • Reproducible in ChatExample? (Yes/No):

What happened?

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

What did you expect to happen?

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)
    }
confirmed bug

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 the contentSize, if the message is > 1 line, and it doesn't happen when stepping through code in a debugger

All 7 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nitrag picture nitrag  路  3Comments

bilaalrashid picture bilaalrashid  路  3Comments

TheDarkCode picture TheDarkCode  路  3Comments

mlequeux picture mlequeux  路  3Comments

robertoferraz picture robertoferraz  路  3Comments