codeandtheory / YMatterType

An opinionated take on Design System Typography for iOS and tvOS.
Apache License 2.0
22 stars 8 forks source link

Add `@IBInspectable` `@IBDesignable` support to `TypographyLabel` #37

Closed mpospese closed 2 years ago

mpospese commented 2 years ago

Intro

As part of adding IB support to our Typography UI elements, it would be nice to (1) be able to see the control rendered in IB, (2) be able to set the typography

Discussion

Unfortunately, @IBInspectable only works with fixed types such as Int, CGFloat, UIColor, CGRect, etc. It cannot work for our struct Typography. However, most of the properties of Typography correspond to these types, so let's try to forward them. e.g.

@IBInspectable fontSize: CGFloat {
    get { typography.fontSize }
    set { typography = typography.fontSize(newValue) }
}

This is a bit exploratory, so want to try it only for the label for now. If it works and seems valuable, we can extend to button, text field, and text view.

Task

AC

Blocked By

mpospese commented 2 years ago

Due to longstanding bugs in Xcode (since 2020), IBDesignable does not work for view code contained in Swift Packages. Because YMatterType is of course a Swift Package, I fear that these components will never correctly render in Interface Builder. If a future version of Xcode ever fixes this (still broken in Xcode 14.1 rc2 as of late October 2022), then we can revisit this work.