GitHawkApp / GitHawk

The (second) best iOS app for GitHub.
http://githawk.com
MIT License
2.88k stars 384 forks source link

[design] Add icons to (UIAlert)actions #1282

Closed BasThomas closed 6 years ago

BasThomas commented 6 years ago

Since iOS 11.2 (I think?) the App Store has this action sheet with text + icons, and I think it looks really cool, adding some visual to an action.

Thing is, I think this API is private; it would be cool to take a look and see if we can build this as well!

Let me know what you think 😃

GitHawk Upload by BasThomas

Bug Report Dump (Auto-generated)
Version 1.17.0 (1513546049)
Device: iPad7,3 (iOS 11.2)
TestFlight: true
rnystrom commented 6 years ago

Thaaaats cool. I want this api lol.

Sent with GitHawk

rizwankce commented 6 years ago

Apollo (Reddit) client has the same alert actions(kind of) w/ icon being left aligned and actions title on the right.

christianselig commented 6 years ago

Yeah, I really wish there was a native API for this, it makes being able to choose an action at a glance so much faster, especially with a swath of actions.

I built this into my Apollo app (screenshot of an example sheet) and it wasn't overly hard to be honest, and after having built it I appreciate the level of customizability it gives you.

I'm hoping to open source it someday, but if I can share the small amount of wisdom I do possess hopefully it'll be helpful! My API essentially just looks like this:

let actionController = ActionController()

actionController.add(action: .upvote) { (action) in
    // Action block on tap
}

actionController.add(action: .downvote) { (action) in
    // Action block on tap
}

present(actionController, animated: true, completion: nil)

Where the corresponding actions can be any part of a large (hardcoded) enum, where each item in the enum has a default title and icon (which can be overridden with alternative versions of the above adding methods).

It makes calling it really simple and concise, but admittedly doesn't lend itself to wide customization super well; I just hardcode in new items as needed. Though it wouldn't be hard to make it extensible.

The UI itself is just a custom view controller, with a UITableView (constructed pretty simply from a custom cell based on the above enum's icon and title) on top of a UIButton, with a custom UIViewControllerAnimatedTransitioning animator obviously. It's really quite simple, only a few hundred lines of code, and that's including the ability to specify text actions (icon-less alternatives more similar to UIAlertController) and a bunch of other stuff.

I'm not sure the above info is of any help to you fine folk, but I've rewritten it a few times over the years due to annoyances in the API and the above is what I've come to really like, so hopefully it was worth the time it took to read at least. :)

BasThomas commented 6 years ago

That’s awesome, thanks for the information @christianselig.

Sent with GitHawk

BasThomas commented 6 years ago

This is there now

BasThomas commented 6 years ago

FYI @christianselig we're using this library that I open sourced.