Supernova-Studio / exporter-ios

Supernova iOS Swift UI exporter that allows conversion of design system data and elements into valid, production-ready Swift UI Code
MIT License
9 stars 12 forks source link

Drive Color generation from UIColor generation #3

Open leopic-sc opened 2 years ago

leopic-sc commented 2 years ago

Is your feature request related to a problem? Please describe. Most mature iOS applications use either fully or partially UIKit for their user interfaces. This means that a purely SwiftUI driven exporter is a nice addition, but has reduced day-to-day value.

Describe the solution you'd like Ideally an entire UIKit driven exporter would be provided by Supernova, but Colors can be a starting point.

Additional context It's important to keep in mind that SwiftUI Colors have an initializer that can take a UIKit UIColor.

Reusing the existing template to generate a UIColor:

import UIKit

extension UIColor {
    static let Token = UIColor.TokenColor()

    struct TokenColor {
        // Light mode
        let lightModeSurface = UIColor(red: 255 / 255, green: 255 / 255, blue: 255 / 255, alpha: 1)
    }
}

Once the color is declared as a UIColor, we can just reference it in SwiftUI:

import SwiftUI

extension Color {
    static let Token = Color.TokenColor()

    struct TokenColor {
        // Light mode
        let lightModeSurface = Color(UIColor.Token.lightModeSurface)
}

This would mean that each color would be generated for both Frameworks but still driven from the same token.

The downside of this approach would be newer SwiftUI only applications would have UIKit generated code that wouldn't be used.

NOTE: keep in mind that UIColors can be used to create Colors, but not the other way around.

Ydus commented 2 years ago

Hi @leopic-sc 🙂

Thanks for bringing this up! We can definitely update the exporter to generate UIKit colors as well. Could you write down some examples of how you'd like to see the other tokens exported in UIKit? That would help a lot!