MBL-2658: Move design system code into new package named KDS#2598
Conversation
| ) | ||
| ], | ||
| swiftLanguageModes: [ | ||
| .v5 |
There was a problem hiding this comment.
Specifically calling out this package as Swift 5.0 and iOS 16.0.
There was a problem hiding this comment.
This seems inconsistent with the swift-tools-version: 6.0 at the top of the file (commented out). Can you explain why they should both be here or delete one of them?
There was a problem hiding this comment.
Just kidding, that breaks on CircleCI! Somewhat confusing why there are two definitions in this file, but looks like it's necessary.
There was a problem hiding this comment.
Weird! Thanks for trying though
| } | ||
|
|
||
| extension UIColor { | ||
| public extension UIColor { |
There was a problem hiding this comment.
I went down a really deep rabbit hole of figuring out which methods (specifically around color generation) should be public, and which should not be.
It started when I made UIColor.hex internal to the KDS package. This was actually really nifty, because it automatically flagged the handful of places in the code where we're manually creating colors off of the design system! But then I went pretty deep trying to figure out how to handle these one-off color cases...and eventually I came around to just making the method public again.
I wanted to highlight this because it is a very powerful tool for enforcing code conventions - you can be really intentional about only exposing a small surface area from your package/library, in a way that we typically don't bother to do.
| } | ||
|
|
||
| var error: Unmanaged<CFError>? | ||
| CTFontManagerRegisterFontsForURL(fontURL as CFURL, .process, &error) |
There was a problem hiding this comment.
Spiffy trick I found for registering fonts. This meant we can remove the Fonts section from Info.plist.
|
|
||
| var error: Unmanaged<CFError>? | ||
| CTFontManagerRegisterFontsForURL(fontURL as CFURL, .process, &error) | ||
| assert(error == nil, "Error registering font: \(String(describing: error))") |
There was a problem hiding this comment.
I went down another rabbithole making sure asserts work as we expect - they do, in fact, run in debug builds, but are stripped from release builds.
It would be good to verify if this is because SPM inherits build flags from the target building the SPM module (in this case, Library), or if SPM automatically adds the flag to strip assertions.
You can add custom swift build flags to an SPM module, so it's not totally clear to me how the inheritance of flags works.
| UIImageView.appearance(whenContainedInInstancesOf: [UITabBar.self]) | ||
| .accessibilityIgnoresInvertColors = true | ||
|
|
||
| InterFont.registerFont() |
There was a problem hiding this comment.
I believe we can now add this to Kickstarter-Framework-Tests and get our screenshot tests all building with Interfont.
| import FBSDKCoreKit | ||
| import Firebase | ||
| import Foundation | ||
| import KDS |
There was a problem hiding this comment.
Downside of modularization: 300 files that just add import KDS.
| |> UITextField.lens.returnKeyType .~ .done | ||
| } | ||
|
|
||
| private let savePasswordButtonStyle: ButtonStyle = { button in |
There was a problem hiding this comment.
Unused, deleted because it required mixLighter which I made internal to KDS.
| <false/> | ||
| <key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS</key> | ||
| <false/> | ||
| <key>UIAppFonts</key> |
There was a problem hiding this comment.
See note above about fonts. Perhaps we should leave this line, though?
| ReferencedContainer = "container:Kickstarter.xcodeproj"> | ||
| </BuildableReference> | ||
| </TestableReference> | ||
| <TestableReference |
There was a problem hiding this comment.
This is one weird bit of SPM I can't quite figure out. I can add the KDS scheme, and we have a target KDSTests, but I can't just run KDSTests. Instead, I had to add them to another schema, in this case Library-iOS. I think this is because Xcode assumes an SPM module is an external dependency, and why would you want to test an external dependency all the time?
I'm not sure if there's a better workaround. Maybe using "Test Plans"? Thoughts welcome.
There was a problem hiding this comment.
OK, I did figure this out. I had to add a schema to KDS, not to Kickstarter. You can now run the KDS tests from the Kickstarter project using CMD+U.
I still left this added to the Library schema, because I don't want to build a whole new CircleCI job just for these tests.
| import UIKit | ||
|
|
||
| // This extension contains custom semantic colors that are not part of the official Figma design set. | ||
| // This extension contains custom semantic colors for PLOT that are not part of the official Figma design set. |
There was a problem hiding this comment.
These all are related to PLOT, so I rescoped them and left them in Library instead of KDS.
Generated by 🚫 Danger |
ifosli
left a comment
There was a problem hiding this comment.
Looks good! I have no suggestions for how to make things better (outside of the swift version comment) but I appreciate all your comments, as always!
| ) | ||
| ], | ||
| swiftLanguageModes: [ | ||
| .v5 |
There was a problem hiding this comment.
This seems inconsistent with the swift-tools-version: 6.0 at the top of the file (commented out). Can you explain why they should both be here or delete one of them?
09c105b to
e86edc9
Compare
| ReferencedContainer = "container:Kickstarter.xcodeproj"> | ||
| </BuildableReference> | ||
| </MacroExpansion> | ||
| <EnvironmentVariables> |
There was a problem hiding this comment.
When you call Bundle.module, it looks for bundles inside the framework (like $(BUILT_PRODUCTS_DIR)/Library.framework/KDS_KDS.bundle). However, when you're building the framework alone (i.e. for tests), the bundle isn't copied there. By setting this environment variable in Debug, we can tell the compiler to look for the bundle in $(BUILT_PRODUCT_DIRS)/KDS_KDS.bundle instead.
This is necessary to keep our tests from crashing when you call Bundle.module.

71724bc to
7c92cfa
Compare
ebc26ee to
0041ef7
Compare
7d00e20 to
75b297b
Compare
| ) | ||
| ], | ||
| swiftLanguageModes: [ | ||
| .v5 |
There was a problem hiding this comment.
Weird! Thanks for trying though
75b297b to
da4ddf4
Compare
📲 What
Move our all our new design system code into a local Swift package, named KDS.
🤔 Why
🛠 How
I learned some interesting things throughout this process - these are called out specifically in code comments.
👀 See