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. gist.github.com/douglashill/5e843adf1451f67d75d631b3bff45a96

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. gist.github.com/douglashill/e9e2876f755271ff3ac323c3f02da092

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. github.com/douglashill/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. github.com/douglashill/KeyboardKit

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:

github.com/douglashill/KeyboardKit/blob/master/KeyboardKit/KeyboardTextView.swift

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: gist.github.com/douglashill/0e693ccc94c292171cfe48770d23a4a0

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. github.com/douglashill/KeyboardKit/blob/master/KeyboardKit/KeyboardNavigationController.swift

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. github.com/douglashill/KeyboardKit/blob/master/KeyboardKit/KeyboardBarButtonItem.swift

11 Dec: KeyboardKit’s UIScrollView subclass now uses a custom animator based on CADisplayLink. It’s smoother, faster, and interacts better with finger scrolling. github.com/douglashill/KeyboardKit/blob/master/KeyboardKit/PointAnimator.swift

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 👍 gist.github.com/douglashill/884e0eacb42c5a3b7b359ac888cffaa2

Wanted to share this after seeing twitter.com/steipete/status/1205556227071184896

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. github.com/git-up/GitUp/pull/620

(My fork has this feature already and several other enhancements. Best Git app! github.com/douglashill/GitUp/releases)

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. github.com/douglashill/KeyboardKit/blob/master/KeyboardKit/KeyboardWindow.swift

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. github.com/douglashill/KeyboardKit/commit/2a76fd78259657e3b76f304f18ea3f1472bdc059

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 :) github.com/douglashill/KeyboardKit/commit/cf4cbd860ab14efd27b00ca307c613342d76d399

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: twitter.com/daringfireball/status/1208122840265973760

22 Dec: First KeyboardKit pull request merged: thanks to @pedrommcarrasco the framework is now available on CocoaPods. cocoapods.org/pods/Keyboard-Kit

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! github.com/douglashill/KeyboardKit/commit/f13088f8c5339e521b727f77e571a143217a5a80