Open source advent

The creation of KeyboardKit

From 1–24 December 2019, I published open source code every day. Most days, these efforts focused on hardware keyboard control in iOS apps, which came together as KeyboardKit. This article collects my daily updates.

1 Dec: Open advent calendar or open source? Here’s a a UIScrollView subclass that allows scrolling using a hardware keyboard. Supports arrows, option + arrows, command + arrows, space bar, page up/down, home/end.

2 Dec: I wanted to open source something else today, even if it’s small. Here’s a UITabBarController subclass that allows navigating between tabs using cmd+1, cmd+2 etc. on a hardware keyboard.

3 Dec: Today I’ve brought together KeyboardTableView, KeyboardScrollView and KeyboardTabBarController into a new open source framework to help apps support being controlled using a hardware keyboard. I’m calling it KeyboardKit.

4 Dec: Today for open source advent, I added support for paging scroll views in KeyboardKit. Also made the example app look way more fun.

5 Dec: Updated KeyboardTableView in KeyboardKit to support arrow key navigation with multiple sections. It also wraps around to the top/bottom.

6 Dec: Added support in KeyboardKit for basic app/window commands:

7 Dec: A UITextView subclass joins the KeyboardKit family, speeding up text manipulation with:

8 Dec: I noticed a string encoding error saving a particular article in @_readingapp. For some reason it can be interpreted as ASCII but not UTF-8 🤷‍♂️. Fixed it with a function that brute forces encodings to read a string from a file. Here it is:

9 Dec: It’s so easy in AppKit to set a keyEquivalent on an NSMenuItem. KeyboardNavigationController brings the same API to UIBarButtonItem in UIKit, so it only takes a few lines to have actions in the nav bar and toolbar accessible from a hardware keyboard.

10 Dec: More open source advent. Added key equivalents for system bar button items so you get automatic hardware keyboard support with no extra lines of code. cmd + S for Save cmd + R for Reply etc.

11 Dec: KeyboardKit’s UIScrollView subclass now uses a custom animator based on CADisplayLink. It’s smoother, faster, and interacts better with finger scrolling.

12 Dec: I added zooming support to KeyboardKit’s scroll view. Q: How many key commands for Zoom In and Zoom Out? A: If you want it to show a proper plus and minus sign and match Safari then it’s five!

13 Dec: Here’s what I use in @_readingapp to smooth over AppKit/UIKit API differences. This file shrinks each June 👍

Wanted to share this after seeing

14 Dec: More open source: I resurrected my nearly 3 year old PR adding a text size setting to GitUp since the project is accepting contributions now.

(My fork has this feature already and several other enhancements. Best Git app!

15 Dec: Still going with open source advent. Over half way through! I added the ability to dismiss any popover or sheet with the escape key (or cmd + .). Any UIKit app can get this by using the UIWindow subclass in KeyboardKit.

16 Dec: By refactoring KeyboardKit’s scroll view key handling to use composition rather than inheritance, it became trivial to add page up, page down, home and end for table view and text view. It’ll make other things easier later.

17 Dec: Open source advent: Added refreshing in scroll views (including table views) with cmd + R. Automatic if they’re hooked up with a UIRefreshControl. Easy with yesterday’s refactoring. I promise I’ll stop tweeting everything after 24th :)

18 Dec: Added something to KeyboardKit that many apps get wrong: now it doesn’t let key commands override text input. E.g. so cmd + left moves the cursor to the beginning of a line instead sending the event to some view underneath and losing user input like in Apple’s Calendar app.

19 Dec: Open source advent: Added support for iOS 11 to KeyboardKit.

20 Dec: Big one today: I added initial arrow key selection in UICollectionView. Of course it gets the other KeyboardKit goodness like ⌘R to refresh and Page Up etc. to scroll.

21 Dec: Added UITableViewController and UICollectionViewController subclasses in KeyboardKit for easier integration when using these instead of making the views directly. Also this:

22 Dec: First KeyboardKit pull request merged: thanks to @pedrommcarrasco the framework is now available on CocoaPods.

23 Dec: Nearly at the end of my open source advent. Today I improved KeyboardKit’s arrow key navigation in collection views:

24 Dec: It’s the end of my open source advent. I added using the delete key to delete items in a UITableView. It’s automatic if you’re using the older commitEditingStyle API. Now it’s time for a few days off!