Live data from Hacker News

SlackTextViewController: A new growing text input for iOS

github.com

21–30 of 35 posts

Re: SlackTextViewController: A new growing text input for iOS

#21

> Inverted mode for displaying cells upside-down (using CATransform) -- a necessary hack for some messaging apps (including ours) Care to elaborate? Sounds intriguingly crufty.

UITableView lays out cells from the top. If there aren't enough cells to fill the screen, there will be an empty area in the bottom part of the table view, between the last cell and the bottom of the table view (as you would expect).

Unfortunately, there isn't a standard way to invert a UITableView, and have cells laid out from the bottom.

So, the easiest solution for us was to set the table's transform to CGAffineTransformMake(1, 0, 0, -1, 0, 0) (flip the whole table upside down) and then give the cells the same transform (to cancel out the table view's transform).

A bit hacky, and causes indexPaths to be inverted as well (0,0 is now at the bottom), but worked for us.

Seen a few other people take this approach as well: https://twitter.com/tapbot_paul/status/461161920402563072

Re: SlackTextViewController: A new growing text input for iOS

#22
post #13
post #10

As someone that doesn't do iOS development it boggles my mind that you guys have to build this feature into your apps.

I'm with you. I don't do iOS development at all, but I will literally sit there and go through the entire code of every iOS control submission to Hacker News just to see how they accomplish what they do. I cannot believe how much code it takes to do something I feel you can accomplish easily in javascript. Kudos to all the iOS developers out there. I don't know how you guys manage to do it, but I'm sure glad you do a…

That's not really a fair comparison. JavaScript backs onto a browser that already implements a vast amount of rendering.

If we had a similar iOS control, we could do it really simply too.

Re: SlackTextViewController: A new growing text input for iOS

#24

Will this work for just the input component with a separate table view controller? That'd make it much more useful for non-messaging apps also.

By subclassing SlackTextViewController, you'll get a tableView or collectionView, and a toolbar at the bottom containing the growing text input. That's basically it. You may decide later to override some methods for disabling or enabling more features.

Re: SlackTextViewController: A new growing text input for iOS

#25
cool. I was just shopping for a new growing text view since HPGrowingTextView seemed like it was not maintained and buggy on IOS 8.

I settled on https://github.com/oseparovic/MessageComposerView.

It's nice, simple, and does the trick. However, I will definitely checkout SlackTExtViewController.

For people not in IOS development: yes this is crazy that it is not built in. But our tool chain is better :)

Re: SlackTextViewController: A new growing text input for iOS

#26
post #21

> Inverted mode for displaying cells upside-down (using CATransform) -- a necessary hack for some messaging apps (including ours) Care to elaborate? Sounds intriguingly crufty.

UITableView lays out cells from the top. If there aren't enough cells to fill the screen, there will be an empty area in the bottom part of the table view, between the last cell and the bottom of the table view (as you would expect). Unfortunately, there isn't a standard way to invert a UITableView, and have cells laid out from the bottom. So, the easiest solution for us was to set the table's transform to CGAffineTr…

That's a pretty interesting approach. Wouldn't it be cleaner to use a UICollectionView with a custom layout?

Re: SlackTextViewController: A new growing text input for iOS

#27
post #21

Earlier quoted context omitted.

UITableView lays out cells from the top. If there aren't enough cells to fill the screen, there will be an empty area in the bottom part of the table view, between the last cell and the bottom of the table view (as you would expect). Unfortunately, there isn't a standard way to invert a UITableView, and have cells laid out from the bottom. So, the easiest solution for us was to set the table's transform to CGAffineTr…

That's a pretty interesting approach. Wouldn't it be cleaner to use a UICollectionView with a custom layout?

Most definitely! UICollectionViewLayout should be the right answer, but the thing is: the Slack iOS app was already built using UITableView, drawing many many custom cells. We'll probably port someday to UICollectionView ;)

Re: SlackTextViewController: A new growing text input for iOS

#28
post #27

Earlier quoted context omitted.

That's a pretty interesting approach. Wouldn't it be cleaner to use a UICollectionView with a custom layout?

Most definitely! UICollectionViewLayout should be the right answer, but the thing is: the Slack iOS app was already built using UITableView, drawing many many custom cells. We'll probably port someday to UICollectionView ;)

I've started experimenting not making cells but UIViews and just add them on top of cells. I haven't gone with that fully yet but I've planned to try it out.

The downside is you lose out on many of the out of the box stuff, like cell background highlights that you know have to define yourself.

The upside is that you can now reuse the UIView everywhere, including non-subclasses of ScrollView.

Re: SlackTextViewController: A new growing text input for iOS

#29
post #27

Earlier quoted context omitted.

That's a pretty interesting approach. Wouldn't it be cleaner to use a UICollectionView with a custom layout?

Most definitely! UICollectionViewLayout should be the right answer, but the thing is: the Slack iOS app was already built using UITableView, drawing many many custom cells. We'll probably port someday to UICollectionView ;)

We do the same thing, custom views, mostly drawn in -drawRect:, reused in different cells. It's actually a very nice technique but like you said, the are some sacrifices to take. Still, these cells depend of a tableViewcCell which has unique properties and special APIs that collectionViewCells don't. I think the most trikcy part here is to be able to build a custom UICollectionViewLayout allowing to display cells from the bottom. Haven't found any third-party doing it well enough yet. Do you know of any?

Re: SlackTextViewController: A new growing text input for iOS

#30
post #28
post #27

Earlier quoted context omitted.

Most definitely! UICollectionViewLayout should be the right answer, but the thing is: the Slack iOS app was already built using UITableView, drawing many many custom cells. We'll probably port someday to UICollectionView ;)

I've started experimenting not making cells but UIViews and just add them on top of cells. I haven't gone with that fully yet but I've planned to try it out. The downside is you lose out on many of the out of the box stuff, like cell background highlights that you know have to define yourself. The upside is that you can now reuse the UIView everywhere, including non-subclasses of ScrollView.

You should add your view to the cell's contentView instead of directly on the cell, which allows you to keep the default behaviors and also reuse the view.
Post reply on HN