Thursday, October 10, 2019

Implementing Dark Mode in iOS 13

Tim Johnsen:

That being said, we didn’t use UIKit’s APIs alone since most developers in the company and our build systems are all still using Xcode 10, and introducing iOS 13 APIs would cause build breakages. We went with the approach of writing thin wrappers around UIKit APIs that are compatible with Xcode 10 and iOS 12.

Writing little wrappers is often the best engineering solution, but it seems like a waste that so many developers have to do essentially the same thing for the same APIs. Why can’t the tools handle this automatically?

We discovered towards the end of our dark mode adoption that our implementation of dynamic colors had equality implications because a new instance of UIColor was returned each time and the only thing that was comparable about each was the block passed in. In order to resolve this we modified our API slightly to create single instances of each of semantic colors so that they were comparable. Doing something like dispatch_once-ing your semantic colors or using asset catalog-based colors and +colorNamed: will produce comparable colors if your app is sensitive to color equality.

[…]

One clever testing trick this IGTraitCollection wrapper afforded us is something we’ve come to call “fake dark mode” — which is an internal setting that override IGTraitCollection to become dark even in iOS 12!

Comments RSS · Twitter

Leave a Comment