Stylish v0.9.3 Release Notes

Release Date: 2018-11-04 // over 5 years ago
  • Compatibility Note:

    ๐Ÿš€ This release has breaking API changes for projects which have custom PropertyStylers. The Property Styler protocol has been updated to add a bundle parameter to the static apply function.

    Before: static func apply(value: PropertyType?, to target: TargetType)
    Now: static func apply(value: PropertyType?, to target: TargetType, using bundle: Bundle)

    ๐Ÿ’… Any existing custom PropertyStylers will need to update their apply function to include the additional parameter.

    ๐Ÿ†• NEW: Bundle Awareness

    โšก๏ธ More and more, the preferred pattern for defining UIImages and UIColors for use in an iOS project is via an asset catalog. Defining images and colors in an asset catalog allows Xcode and UIKit to optimize what is included in the final app binary, and in the case of colors specifically, asset catalogs allow variations of the same named color to be defined for P3 vs. sRGB gamuts, for dark mode vs. light mode, etc.

    When using colors and images defined in the asset catalog, the API follows the pattern:

    UIImage(named: String, in: Bundle?, compatibleWith: UITraitCollection?)
    UIColor(named: String, in: Bundle?, compatibleWith: UITraitCollection?)

    ๐Ÿ’… So in order for Stylish PropertyStylers to effectively leverage these APIs, they must have knowledge of which Bundle to load images, colors, or other resources from.

    ๐Ÿ’… For this reason, the Stylesheet protocol now has a new bundle property with a default implementation that loads the bundle that the Stylesheet itself is a member of. This bundle value is now passed down into all PropertyStylers at the moment they are invoked on a target view. This allows the PropertyStylers to pull any assets from the correct bundle at the moment they run.

    Future Evolution

    ๐Ÿ’… The big picture is that this enables Stylesheets to be distributed in their own framework bundle with all the assets they need to work. So a great Stylesheet that depends on specific colors with dark mode variations and specific image assets can now be placed in its own framework with a asset catalog, and distributed independently of any specific application. And when that Stylesheet is linked, imported and set in a host application, it will just work, and the styles will use the assets and colors from the bundle the Stylesheet came from. This also enables multiple "stylesheet bundles" to be linked into a single application and dynamically switched between without the host app having to independently include and name the various assets needed by those stylesheets.

    This helps finally define a pattern that allows Stylish to be used easily in important ways:

    • ๐Ÿ’… Stylesheet bundles can be authored and distributed as standalone projects that can be used in any app that uses Stylish
    • Companies or teams that want to create standard themes and reuse them across multiple apps can now do so!

    ๐Ÿ’… Upcoming versions of Stylish will include an updated example project to demonstrate this improved method of distributing and linking in Stylesheet bundles.