slackhq / SlackTextViewController

⛔️**DEPRECATED** ⛔️ A drop-in UIViewController subclass with a growing text input view and other useful messaging features
https://slack.com/
MIT License
8.32k stars 1.08k forks source link

Accept custom subclasses of UICollectionView #567

Closed NinoScript closed 7 years ago

NinoScript commented 7 years ago

Description

I think it should be possible to inject our own UICollectionView instance, instead of just passing in a UICollectionViewLayout.

This makes it possible to use SlackTextViewController alongside other libraries like IGListKit

How to add this feature

In my case, I just added a new initializer: - (instancetype)initWithCollectionView:(UICollectionView *)collectionView

that does the same as: - (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout

but instead of making it's own collection view like the existing initializer does: _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];

it uses the one passed in: _collectionView = collectionView;

and also it doesn't set the collectionView's delegate and dataSource.

I then injected in my IGListCollectionView instance, and voilà, both libraries seem to be working together perfectly. ;)

NinoScript commented 7 years ago

As discussed with @dzenbot via slack, the tableView, collectionView and scrollView properties are just used to hold a strong reference and nothing more, so I can use - (instancetype)initWithScrollView:(UIScrollView *)scrollView and keep my own reference to the collectionView or override the getter for collectionView to return the one stored in scrollView.

It's kind of a hacky solution, but it is a solution.

SlackTextController :heart: IGListKit

rnystrom commented 7 years ago

If it makes it any easier, we're probably going to remove the IGListCollectionView requirement on IGListKit Instagram/IGListKit#409 soon.

dzenbot commented 7 years ago

Closing this for now, since @NinoScript found a workaround 💪