Skip to content

Cannot parse custom colors whose .colorset uses Hex values #146

Description

@marcprux

Skip's named color handling parses the .colorset resource, but only handles when the "Input Method" is "Floating Point". For example, this setting:

Image

Will create this Sources/Showcase/Resources/Module.xcassets/CustomRed.colorset/Contents.json file:

{
  "colors" : [
    {
      "color" : {
        "color-space" : "srgb",
        "components" : {
          "alpha" : "1.000",
          "blue" : "0.733",
          "green" : "0.067",
          "red" : "0.580"
        }
      },
      "idiom" : "universal"
    },
    {
      "appearances" : [
        {
          "appearance" : "luminosity",
          "value" : "dark"
        }
      ],
      "color" : {
        "color-space" : "srgb",
        "components" : {
          "alpha" : "1.000",
          "blue" : "0.474",
          "green" : "0.493",
          "red" : "1.000"
        }
      },
      "idiom" : "universal"
    }
  ],
  "info" : {
    "author" : "xcode",
    "version" : 1
  }
}

But if you switch the "Input Method" to "8-bit hexadecimal":

Image

It will create the following contents with hex encoding:

{
  "colors" : [
    {
      "color" : {
        "color-space" : "srgb",
        "components" : {
          "alpha" : "1.000",
          "blue" : "0xBB",
          "green" : "0x11",
          "red" : "0x94"
        }
      },
      "idiom" : "universal"
    },
    {
      "appearances" : [
        {
          "appearance" : "luminosity",
          "value" : "dark"
        }
      ],
      "color" : {
        "color-space" : "srgb",
        "components" : {
          "alpha" : "1.000",
          "blue" : "0.474",
          "green" : "0.493",
          "red" : "1.000"
        }
      },
      "idiom" : "universal"
    }
  ],
  "info" : {
    "author" : "xcode",
    "version" : 1
  }
}

Skip's color parsing does not handle this:

struct ColorComponents : Decodable {
let red: String?
let green: String?
let blue: String?
let alpha: String?
var color: Color {
let redValue = Double(red ?? "") ?? 0.0
let greenValue = Double(green ?? "") ?? 0.0
let blueValue = Double(blue ?? "") ?? 0.0
let alphaValue = Double(alpha ?? "") ?? 1.0
return Color(red: redValue, green: greenValue, blue: blueValue, opacity: alphaValue)
}
}

This results in the color just appearing black. We should handle all the Input Method variants that can be represented in the .colorset file.

This was reported in the Slack at: https://skiptools.slack.com/archives/C078X69G8F2/p1741638916826529?thread_ts=1741636875.710679&cid=C078X69G8F2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions