Messagekit: Sticky header for dates

Created on 18 Sep 2018  路  13Comments  路  Source: MessageKit/MessageKit

Hello,

I use this library, it's an amazing one congrats

I want to know if it's possible to add a sticky headers for dates like slack on a web browser ?
I also want to know if I can custom completly the design ?

Thanks for you help,
Have a good day

question stale

All 13 comments

+1

Hello,

if i call this

let layout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout
layout?.sectionHeadersPinToVisibleBounds = true

it will first displayed but not as sticky and on scrolling up it will after few items crash

@hoeness2 Thanks for your help I'll try

Got it working
You need to make some change in the source code of MessageKit.

  1. You need to edit MessagesCollectionViewFlowLayout.swift and comment out the function "shouldInvalidateLayout" this function blocks the sticky header to be working.
  2. You need to convert your CollectionSource data in section holds messages for same day not section holds one message by default.

To see a working example i have uploaded the edited MessageKit example project to dropbox for you so you can download and see the changes that i have made.

It has the exactly whatsapp message group sorting algorithm that i have researched over weeks.

Cheers

https://www.dropbox.com/s/c7g6cx18rqk4vi9/MessageKit-master.zip?dl=0

@hoeness2 please can you point out where you made the changes?

Which changes do you mean ?
Do you mean Messagekit changes or for the Example project changes ?

@hoeness2 i'm talking about the MessagesCollectionViewFlowLayout.swift changes

You need to comment out the function shouldInvalidateLayout completely and that鈥檚 it. They are no more changes made in the MessageKit module.

Thanks, it worked fine. Thanks for the source code you shared as well, it helped me implement the grouping of messages

This issue has been marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This issue has been auto-closed because there hasn't been any activity for at least 21 days. However, we really appreciate your contribution, so thank you for that! 馃檹 Also, feel free to open a new issue if you still experience this problem 馃憤.

This solution used to work, but now it seems like it is impossible to have sticky section headers anymore (using MessageKit 3.0.0)
Is there a new way to stick section headers like WhatsApp does ?
As it stands, sectionHeadersPinToVisibleBounds = true seems to be "confusing" the collectionView :
the header that is visible when the collection view first appears will be displayed close to the top bound. But then when the user scrolls, all the headers will scroll like all the other cells. And that initial top header will scroll but remains misplaced.

simulatorrecording

@hoeness2 Can you update the link of the sample project?

Was this page helpful?
0 / 5 - 0 ratings