Skip to content

Commit

Permalink
Filter icons for render mode (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey1312 authored Sep 21, 2021
1 parent 87a433b commit 546212f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
11 changes: 10 additions & 1 deletion CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,17 @@ ios:
swiftUIImageSwift: "./Source/Image+extension_icons.swift"
# [optional] Absolute or relative path to swift file where to generate extension for UIImage for accessing icons from the code (e.g. UIImage.ic24ArrowRight)
imageSwift: "./Example/Source/UIImage+extension_icons.swift"
# Asset render mode: "template", "orignal" or "default". Default value is "template".
# Asset render mode: "template", "original" or "default". Default value is "template".
renderMode: default
# Configure the suffix for filtering Icons and to denote a asset render mode: "default".
# It will work when renderMode value is "template". Defaults to nil.
renderModeDefaultSuffix: '_default'
# Configure the suffix for filtering Icons and to denote a asset render mode: "original".
# It will work when renderMode value is "template". Defaults to nil.
renderModeOriginalSuffix: '_original'
# Configure the suffix for filtering Icons and to denote a asset render mode: "template".
# It will work when renderMode value isn't "template". Defaults to nil.
renderModeTemplateSuffix: '_template'

# [optional] Parameters for exporting images
images:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ If a color, icon or image is unique for iOS or Android platform, it should conta

For `figma-export colors`

By default, if you support dark mode your figma project must contains two files. One should contains a dark color palette, and the another light color palette. If you would like to specify light and dark colors in the same file, you can do so with the `useSingleFile` configuration option. You can then denote dark mode colors by adding a suffix like `_dark`. The suffix is also configurable. See [config](Config.md) for more information in the colors section.
By default, if you support dark mode your figma project must contains two files. One should contains a dark color palette, and the another light color palette. If you would like to specify light and dark colors in the same file, you can do so with the `useSingleFile` configuration option. You can then denote dark mode colors by adding a suffix like `_dark`. The suffix is also configurable. See [CONFIG.md](CONFIG.md) for more information in the colors section.

The light color palette may contain more colors than the dark color palette. If a light-only color is present, it will be considered as universal color for the iOS color palette. Names of the dark colors must match the light colors.

Expand All @@ -379,14 +379,14 @@ File | Styles

For `figma-export icons`

By default your Figma file should contains a frame with `Icons` name which contains components for each icon. You may change a frame name in a [config](Config.md) file by setting `common.icons.figmaFrameName` property.
If you support dark mode and want separate icons for dark mode, Figma project must contains two files. One should contains a dark icons, and another light icons. If you would like to have light and dark icons in the same file, you can do so with the `useSingleFile` configuration option. You can then denote dark mode icons by adding a suffix like `_dark`. The suffix is also configurable. See [config](Config.md) for more information in the icons section.
By default your Figma file should contains a frame with `Icons` name which contains components for each icon. You may change a frame name in a [CONFIG.md](CONFIG.md) file by setting `common.icons.figmaFrameName` property.
If you support dark mode and want separate icons for dark mode, Figma project must contains two files. One should contains a dark icons, and another light icons. If you would like to have light and dark icons in the same file, you can do so with the `useSingleFile` configuration option. You can then denote dark mode icons by adding a suffix like `_dark`. The suffix is also configurable. See [CONFIG.md](CONFIG.md) for more information in the icons section.

For `figma-export images`

Your Figma file should contains a frame with `Illustrations` name which contains components for each illustration. You may change a frame name in a [config](Config.md) file by setting `common.images.figmaFrameName` property.
Your Figma file should contains a frame with `Illustrations` name which contains components for each illustration. You may change a frame name in a [CONFIG.md](CONFIG.md) file by setting `common.images.figmaFrameName` property.

If you support dark mode you must have two Figma files. The rules for these two files follow the same rules as described above for colors. But If you would like to specify light and dark illustrations in the same file, you can do so with the `useSingleFile` configuration option. You can then denote dark mode illustrations by adding a suffix like `_dark`. The suffix is also configurable. See [config](Config.md) for more information in the illustrations section.
If you support dark mode you must have two Figma files. The rules for these two files follow the same rules as described above for colors. But If you would like to specify light and dark illustrations in the same file, you can do so with the `useSingleFile` configuration option. You can then denote dark mode illustrations by adding a suffix like `_dark`. The suffix is also configurable. See [CONFIG.md](CONFIG.md) for more information in the illustrations section.

If you want to specify image variants for different devices (iPhone, iPad, Mac etc.), add an extra `~` mark with idiom name. For example add `~ipad` postfix:

Expand Down
3 changes: 3 additions & 0 deletions Sources/FigmaExport/Input/Params.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ struct Params: Decodable {
let swiftUIImageSwift: URL?

let renderMode: XcodeRenderMode?
let renderModeDefaultSuffix: String?
let renderModeOriginalSuffix: String?
let renderModeTemplateSuffix: String?
}

struct Images: Decodable {
Expand Down
5 changes: 4 additions & 1 deletion Sources/FigmaExport/Subcommands/ExportIcons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ extension FigmaExportCommand {
preservesVectorRepresentation: iconsParams.preservesVectorRepresentation,
uiKitImageExtensionURL: iconsParams.imageSwift,
swiftUIImageExtensionURL: iconsParams.swiftUIImageSwift,
renderMode: iconsParams.renderMode)
renderMode: iconsParams.renderMode,
renderModeDefaultSuffix: iconsParams.renderModeDefaultSuffix,
renderModeOriginalSuffix: iconsParams.renderModeOriginalSuffix,
renderModeTemplateSuffix: iconsParams.renderModeTemplateSuffix)

let exporter = XcodeIconsExporter(output: output)
let localAndRemoteFiles = try exporter.export(icons: icons.get(), append: filter != nil)
Expand Down
11 changes: 10 additions & 1 deletion Sources/XcodeExport/Model/XcodeImagesOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public struct XcodeImagesOutput {
let addObjcAttribute: Bool
let preservesVectorRepresentation: [String]?
let renderMode: XcodeRenderMode?
let renderModeDefaultSuffix: String?
let renderModeOriginalSuffix: String?
let renderModeTemplateSuffix: String?

let uiKitImageExtensionURL: URL?
let swiftUIImageExtensionURL: URL?
Expand All @@ -27,7 +30,10 @@ public struct XcodeImagesOutput {
preservesVectorRepresentation: [String]? = nil,
uiKitImageExtensionURL: URL? = nil,
swiftUIImageExtensionURL: URL? = nil,
renderMode: XcodeRenderMode? = nil) {
renderMode: XcodeRenderMode? = nil,
renderModeDefaultSuffix: String? = nil,
renderModeOriginalSuffix: String? = nil,
renderModeTemplateSuffix: String? = nil) {

self.assetsFolderURL = assetsFolderURL
self.assetsInMainBundle = assetsInMainBundle
Expand All @@ -37,5 +43,8 @@ public struct XcodeImagesOutput {
self.uiKitImageExtensionURL = uiKitImageExtensionURL
self.swiftUIImageExtensionURL = swiftUIImageExtensionURL
self.renderMode = renderMode
self.renderModeDefaultSuffix = renderModeDefaultSuffix
self.renderModeOriginalSuffix = renderModeOriginalSuffix
self.renderModeTemplateSuffix = renderModeTemplateSuffix
}
}
13 changes: 13 additions & 0 deletions Sources/XcodeExport/XcodeIconsExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@ final public class XcodeIconsExporter: XcodeImagesExporterBase {
// Generate assets
let assetsFolderURL = output.assetsFolderURL
let preservesVectorRepresentation = output.preservesVectorRepresentation
// Filtering at suffixes
let renderMode = output.renderMode ?? .template
let defaultSuffix = renderMode == .template ? output.renderModeDefaultSuffix : nil
let originalSuffix = renderMode == .template ? output.renderModeOriginalSuffix : nil
let templateSuffix = renderMode != .template ? output.renderModeTemplateSuffix : nil

let imageAssetsFiles = try icons.flatMap { imagePack -> [FileContents] in
let preservesVector = preservesVectorRepresentation?.first(where: { $0 == imagePack.light.name }) != nil

if let defaultSuffix = defaultSuffix, imagePack.light.name.hasSuffix(defaultSuffix) {
return try imagePack.makeFileContents(to: assetsFolderURL, preservesVector: preservesVector, renderMode: .default)
} else if let originalSuffix = originalSuffix, imagePack.light.name.hasSuffix(originalSuffix) {
return try imagePack.makeFileContents(to: assetsFolderURL, preservesVector: preservesVector, renderMode: .original)
} else if let templateSuffix = templateSuffix, imagePack.light.name.hasSuffix(templateSuffix) {
return try imagePack.makeFileContents(to: assetsFolderURL, preservesVector: preservesVector, renderMode: .template)
}

return try imagePack.makeFileContents(to: assetsFolderURL, preservesVector: preservesVector, renderMode: renderMode)
}

Expand Down

0 comments on commit 546212f

Please sign in to comment.