Skip to content

Commit

Permalink
Improve icon assets naming and access for Android (#72)
Browse files Browse the repository at this point in the history
* Export Android icons with the `ic_compound_` prefix

* Improve `icons.kt.template`:

- Add updated icon token references to `CompoundIcons.kt`.
- Make the code easier to measure by code coverage tools.
  • Loading branch information
jmartinesp authored Feb 9, 2024
1 parent f4fcd9f commit 8994ca0
Show file tree
Hide file tree
Showing 168 changed files with 832 additions and 500 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1,322 changes: 826 additions & 496 deletions assets/android/src/CompoundIcons.kt

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/formats/templates/compose/icons.kt.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ object <%= file.className %> {
if (prop.comment) {
comment = `/** ${prop.comment} */\n `
}
return comment + 'val ' + options.getIconName(prop.name) + ' @Composable get() = ImageVector.vectorResource(' + formatProperty(prop).split(' = ')[1] + ')'
return comment + '@Composable fun ' + options.getIconName(prop.name) + '(): ImageVector {\n' + options.indentLevel + options.indentLevel +
'return ImageVector.vectorResource(' + formatProperty(prop).split(' = ')[1] + ')\n' + options.indentLevel +
'}'
}).join('\n' + options.indentLevel ) %>

val all @Composable get() = persistentListOf(
val all @Composable get() = persistentListOf<ImageVector>(
<%= allProperties.map(function(prop) {
return options.getIconName(prop.name) + ','
return options.getIconName(prop.name) + '(),'
}).join('\n' + options.indentLevel + options.indentLevel ) %>
)

Expand Down
2 changes: 1 addition & 1 deletion src/transforms/kotlin/svgToDrawable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {

// Snake case and replace `icon` with `ic` as this is the convention on Android
// and on Material
const imageId = _.snakeCase(token.name.replace("icon", "ic"));
const imageId = _.snakeCase(token.name.replace("icon", "ic_compound_"));

let options = {
fillBlack: true, // Add black color to path element, defaults to false
Expand Down

0 comments on commit 8994ca0

Please sign in to comment.