Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for sections header/footer #9

Closed
DenisLaboureyras opened this issue Dec 17, 2015 · 11 comments
Closed

Support for sections header/footer #9

DenisLaboureyras opened this issue Dec 17, 2015 · 11 comments

Comments

@DenisLaboureyras
Copy link

Hi,

Thanks for your work, your framework seems awesome! And very promising!

I'm currently trying to integrate it in my project, and I have a few questions. The most important for me is do you support sections header? I want to split my messages by day, providing a nice header.
I think you can do it artificially with a new type of message, but it won't stick like headers do.
I think you can achieve that with viewForSupplementaryElementOfKind but I didn't find this kind of code in Chatto.

If you don't plan to support it, I will try to help you implementing it :)

Kind regards,
Denis

@diegosanchezr
Copy link
Contributor

Hi Denis,

We don't have plans for this feature. This is a very specific UI requirement for your case, but this is why we have ChattoAdditions. Our idea is to have a very light and stable core framework (Chatto) and then have a family of pluggable components in ChattoAdditions so that many different UIs can be implemented. On that basis looks like adding support for viewForSupplementaryElementOfKind would require too many changes in Chatto, potentially affecting several interfaces (DataSource, Decorator, Presenter, ChatItem...).

Therefore, the most pragmatic way to implement sticky headers in our framework is to use regular cells. You would need to create a separated CollectionViewLayout in ChattoAdditions and use it in your custom ChatViewController subclass. You would implement your sticky layout there. To achieve that I'd start by making ChatViewController.decoratedChatItems's getter public and use that array to calculate the layout. The ChatViewController will be still creating the layoutModel for the default layout. That can be seen as a waste of work, but it will warm the sizes cache so you will still be very fast calculating the layout in the main thread. Once you get there then we can refactor ChatViewController to allow generic CollectionViewLayout preparation in the background.

Hope this helps and we can see a nice PR soon :)

Cheers,
Diego

@DenisLaboureyras
Copy link
Author

Hello Diego,

Thanks for your answer !
I've tried to integrate support for viewForSupplementaryElementOfKind and sections to Chatto yesterday before your message, and as you said I had to change a lot of things in your framework to make it work... I was stuck with the collections changes, but the rest of the code was not so difficult to adapt.

Anyway your idea to use regular cells seems really nice, and more simple than the first one. And it will not break things in your framework. But I feel it's more kind of a hack than a native solution, as Apple suggests to use sections and headers to resolve these kind of things.
I think I will dig the 2 solutions in parallel and choose the one which best fits my needs. At least it will give me a better comprehension of your framework !

I'm going on holidays tomorrow so I don't know when I will be able to finish this. But I keep you posted.

Cheers,
Denis

@baoankhang
Copy link

Hi,
Sorry about question not relate this issue. What about group message ( multi user chat in conversation ) feature ?

@DenisLaboureyras
Copy link
Author

Hello Diego,

I was on holidays so didn't have time to work on it, but I came back yesterday and I finish a first version with section header support.
You can find my code here : https://github.com/DenisLaboureyras/Chatto

I've added support for supplementaryView and sections (I know it's not your favorite solution but it was the most simple for my skills).

Good stuffs:

  • My code does not impact very much the ChattoAdditions (I only add new items for header), and the app (You only need to encapsulate your datasource in sections and add sections decorators)
  • the sticky header is working well, I added a fourth example in the demo app :)
  • I've integrated the framework in my app today, it was pretty easy and it's working like a charm.

Bad stuffs:

  • I had to change a lot in the core of Chatto to support SupplementaryViews and sections...
  • It only support one kind of SupplementaryView for the moment (but it should not be difficult to add)
  • I duplicated some of your code to use the same logic for creating the header cells, with presenters and decorators, so it needs a great refactoring...
  • the sticky effect is coded in the collectionview layout, maybe it would be better to externalize it or to add a bool to activate/deactivate this effect.
  • I've still have a nasty bug to determine the height of the header cells (At first, I don't know why there is no sections when the method presenterForIndexSection is called, so it picked the Dummypresenter instead of mine. Then the collectionview is refreshed, everything works fine and my presenter is used, but the height of the dummy presenter is kept...).

I think I modified your framework too much and you won't use my work, but maybe it could inspire you for other issues :)

I will still work on my fork in the next days/week to improve it. I will try to refactor the code, get rid of the bug, and add support for sound messages (another topic :)).
Thanks again for your awesome framework!

@diegosanchezr
Copy link
Contributor

Yeah... it looks more or less as I imagined. In my opinion decoration and supplementary views are given by Apple to help us separate responsibilities out of the raw array of data, and have a cleaner code. In my experience, they come as well with some limitations (there's no equivalent to cellForItemAtIndexPath: for supplementary views and it's tricky to refresh them within performBatchUpdates). In Chatto, all this separation of concerns is intended to be done within the Decorator object and the DecorationAttributes. Also, having just one section makes it faster and simpler the calculation of changes for the collection view.

Anyway, I'm very happy you were able to get your hands dirty and modify the code, hope you found it clean enough; and thank you for sharing your work!

@weyert
Copy link

weyert commented Feb 24, 2016

Any news on this? What's the state of this?

@zwang
Copy link
Contributor

zwang commented Mar 13, 2016

@DenisLaboureyras @diegosanchezr I added some demo code of how to add fake header/footer via extra DecoratedChatItem. You can see the code in #58

@weyert
Copy link

weyert commented Mar 13, 2016

@zwang I noticed, you have avatar's in your pull request. Any chance you would be able to share this?

@zwang
Copy link
Contributor

zwang commented Mar 13, 2016

@weyert avatar feature has already been merged to latest dev branch. Check it out. :)

@weyert
Copy link

weyert commented Mar 13, 2016

@zwang Sweet! I will wait until Badoo pushed it to the master-branch so it works easily with Cocoapod.

@diegosanchezr
Copy link
Contributor

@weyert I recommend you to switch to dev branch, as master may not be updated in a while. You can also specify a specific commit in your Podfile

@wiruzx wiruzx closed this as completed May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants