Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Asset Catalog - Named Colors #68

Merged
merged 17 commits into from
Aug 20, 2017
Merged

Asset Catalog - Named Colors #68

merged 17 commits into from
Aug 20, 2017

Conversation

djbe
Copy link
Member

@djbe djbe commented Aug 13, 2017

SwiftGenKit PR: SwiftGen/SwiftGenKit#51

@djbe djbe changed the title Asset Catalog Colors Asset Catalog - Named Colors Aug 13, 2017
@djbe
Copy link
Member Author

djbe commented Aug 13, 2017

Should we add migration guide entries for the deprecated changes?

@@ -21,6 +21,8 @@ You can customize some elements of this template by overriding the following par
| Parameter Name | Default Value | Description |
| -------------- | ------------- | ----------- |
| `enumName` | `Asset` | Allows you to change the name of the generated `enum` containing all assets. |
| `colorTypeName` | `ImageAsset` | Allows you to change the name of the generated color container type. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colorTypeName defaults to… ImageAsset? Shouldn't it be s/ImageAsset/ColorAsset/?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -20,6 +20,8 @@ You can customize some elements of this template by overriding the following par
| Parameter Name | Default Value | Description |
| -------------- | ------------- | ----------- |
| `enumName` | `Asset` | Allows you to change the name of the generated `enum` containing all assets. |
| `colorTypeName` | `ImageAsset` | Allows you to change the name of the generated color container type. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same typo probably here

@@ -20,6 +20,8 @@ You can customize some elements of this template by overriding the following par
| Parameter Name | Default Value | Description |
| -------------- | ------------- | ----------- |
| `enumName` | `Asset` | Allows you to change the name of the generated `enum` containing all assets. |
| `colorTypeName` | `ImageAsset` | Allows you to change the name of the generated color container type. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

typealias XCTAssetsType = XCTImageAsset

struct XCTImageAsset {
fileprivate var value: String
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename that property to name — even if it's fileprivate and doesn't really matter, just for consistency reasons.
Same for the XCTColorAsset of course, and same for all templates

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing as we decided to keep value for the context, should I still rename this one?

}

struct XCTColorAsset {
fileprivate var value: String
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way if we rename value to name to be more consistent, we could imagine later add properties conveying the color components as found in the JSON of the asset catalog (probably useless so maybe no need to add them for now, but we could add some variables for them in the context for people wanting to use that Parser to generate other outputs like HTML color palettes from the parsed asset catalog or whatnot…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we can't get color components at generation time, because colors can be different on a per-device basis (and other criteria).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Meaning one color entry in the Asset Catalog can have multiple values, because Normal vs. P3 or because they can have different actual colors for different trait collections etc, is that it?
Damn.

Copy link
Member Author

@djbe djbe Aug 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, devices, memory, yadda yadda. Whatever you can use now for images also applies to colors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the asset catalog a bit of a black box in this case. You give it a name, and it gives stuff back depending on some rules. 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allright, maybe not memory criteria, but devices + srgb and p3:
screen shot 2017-08-16 at 01 26 26

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙀
Makes sense, but still… 😄
Ok, no color components in the generated context then ;)

@djbe djbe added this to the 2.1.0 milestone Aug 17, 2017
@djbe djbe removed the status: WIP label Aug 17, 2017
Copy link
Collaborator

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would indeed not cost much to add an entry in the Migration Guide, even if it's only for depreciation.

Also I think we should add an Asset Catalog fixture containing both images and colors in the same catalog.
If I'm not mistaking for now the tests only check the cases of a only-images catalog and of an only-colors catalog, it's important to check that having an heterogeneous catalog won't lead to compile errors (like we could have had if we didn't split allValues in two separate properties for example)

@@ -21,6 +21,8 @@ You can customize some elements of this template by overriding the following par
| Parameter Name | Default Value | Description |
| -------------- | ------------- | ----------- |
| `enumName` | `Asset` | Allows you to change the name of the generated `enum` containing all assets. |
| `colorTypeName` | `ColorAsset` | Allows you to change the name of the generated color container type. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"of the struct type representing a color"?

(I find the current wording a bit confusing wrt the difference between enumName and [color|image]TypeName otherwise)

@@ -21,6 +21,8 @@ You can customize some elements of this template by overriding the following par
| Parameter Name | Default Value | Description |
| -------------- | ------------- | ----------- |
| `enumName` | `Asset` | Allows you to change the name of the generated `enum` containing all assets. |
| `colorTypeName` | `ColorAsset` | Allows you to change the name of the struct type representing a color. |
| `imageTypeName` | `ImageAsset` | Allows you to change the name of the struct type representing an image. |
| `noAllValues` | N/A | Setting this parameter will disable generation of the `allValues` constant. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be breaking I know, but I wonder if a sensible default wouldn't instead be to not generate allColors/allImages (as that could generate a really huge array, and in most cases for nothing as I personally never saw the need for having such an array of all your images in your whole app anyway), and thus turning that parameter to allValues instead with the inverse meaning? Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, it's definitely handy when you need it, and it shouldn't matter how big the generated file is. Constants as these are only allocated when accessed, so that shouldn't be an issue either.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants