-
Notifications
You must be signed in to change notification settings - Fork 38
Conversation
|
||
```swift | ||
extension ColorName { | ||
/// 0x339666ff (r: 20%, g: 58%, b: 40%, a: 100%) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think that a lot of people dealing with colors palettes provided by their designers (e.g. via a Sketch document or a sheet listing all colors of the app theme, etc) generally deal either with hex or with rgba(51, 150, 104, 255)
and less commonly with % for rgb values 😉
|
||
| Parameter Name | Default Value | Description | | ||
| -------------- | ------------- | ----------- | | ||
| `enumName` | `ColorName` | Allows you to change the name of the generated `enum` containing all colors. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a note (same in the documentations for other literals-swiftN
of course) about the special Color
name (maybe outside the table as it can be a paragraph of its own), e.g.
Note: if you use
--param enumName=Color
then the color constants will be generated as an extension of theUIColor
(iOS) /NSColor
(macOS) type directly without creating a separateenum
type for namespacing those color constants
But tbf I think it would be less surprising if the test was on testing UIColor
or NSColor
, not Color
.
Like adapting the template to:
{% set enumName %}{{param.enumName|default:"ColorName"}}{% endset %}
#if os(OSX)
import AppKit.NSColor
typealias Color = NSColor
{% if enumName != 'NSColor' %}enum {{enumName}} { }{% endif %}
#elseif os(iOS) || os(tvOS) || os(watchOS)
import UIKit.UIColor
typealias Color = UIColor
{% if enumName != 'UIColor' %}enum {{enumName}} { }{% endif %}
#endif
// swiftlint:disable file_length identifier_name line_length type_body_length
extension {{enumName}} {
…
}
And then explaining that in the doc that the exception is with --param enumName=UIColor
for those who wish to make those constants as an extension of UIColor
directly. Would feel more natural as a special name imho?
💡 Once #68 is merged it could be nice to apply a similar idea for colors on the xcassets templates, making the named colors being directly |
I'm not sure if it's a good idea to have asset template variations just for that case, especially because there are so many more possible set types in catalogs we don't support yet. It would be better to decide now what'd be most useful for the user. The thing we have to keep in mind is that named colors are iOS 11+ (macOS 10.13+), so I'm not even sure how that'd work? Place a whole bunch of |
Ah, right, having to |
6b8fdb4
to
d6ab661
Compare
## Usage example | ||
|
||
```swift | ||
// To reference a color, simpy reference it's static instance by name: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/it's/its/
## Usage example | ||
|
||
```swift | ||
// To reference a color, simpy reference it's static instance by name: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/it's/its/
test(template: "literals-swift3", | ||
contextNames: Contexts.all, | ||
directory: .colors, | ||
contextVariations: variations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also test the --param enumName=UIColor
case too, to check the enum isn't created there?
92793e2
to
67074d9
Compare
Partially inspired by #72 and an old discussion #55 (comment).