CamoIcon
Concept
1. Why
Icons are passed into buttons, icon buttons, text fields and top bars as widgets. The usual pattern is an app-level icon widget per asset (AppIcon.search()), and the containing component decides how big and what color the icon is. CamoIcon makes that work: it draws an icon asset and, when the caller doesn't say otherwise, takes its size and color from the ambient icon style the surrounding component set. Pass AppIcon.save() into a Solid button and it comes out onPrimary at the button's icon size, with no parameters.
It also forces a decision on every standalone icon: is it meaningful (needs a label) or decorative (hidden from screen readers)?
2. Shape
Resolution order (for size and tint separately):
- the
CamoIconparameter, if given; - the ambient
IconStylefrom the nearest component that set one; - the provider's root style, from the
iconcomponent theme (Material default: size 24, coloronSurface).
App-level icon widgets are the recommended way to use icons. Define one per asset, either by wrapping CamoIcon or by reading the ambient style yourself:
// pseudocode: one entry per asset in your project
AppIcon.search(size = null, color = null) = CamoIcon(IconSource(asset = "icons/search"), size = size, tint = color)
AppIcon.back(...) = CamoIcon(IconSource(asset = "icons/back", autoMirror = true), ...)
Material mapping preview: it draws the vector at the resolved size and tint. See Material Skin.
3. API
Contract
fun CamoIcon(
source: IconSource, // the asset
contentDescription: String? = null, // null = decorative
size: Dp? = null, // null → ambient IconStyle.size
tint: Color? = null, // null → ambient IconStyle.color
)
data class IconSource(
val asset: PlatformAsset, // vector/drawable/SVG/IconData, per platform
val autoMirror: Boolean = false, // flip in RTL (back arrow, chevron)
val original: Boolean = false, // multicolor asset: never tint
)
data class IconStyle(val size: Dp, val color: Color) // ambient, set by renderers
| Name | What it's for |
|---|---|
CamoIcon | draws one icon asset, following the ambient style |
IconSource | a thin wrapper over the platform asset type, plus mirroring and no-tint flags |
IconStyle | what a containing renderer sets around its icon widgets |
Camouflage.iconStyle | read the current ambient style (for custom icon widgets that don't wrap CamoIcon) |
tint takes a resolved Color, not a role, so an app icon widget can forward its own color parameter unchanged. Use Camouflage.colors.x to stay on theme.
State → renderer: IconState(source, resolvedSize, resolvedColor, contentDescription). Slots: none.
Tokens used
IconStylefrom the context, which the renderers derive fromcolorsroles and their own size rules.
Component theme
theme.components.icon: IconTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.
| Field | Type | Material default | What it's for |
|---|---|---|---|
size | Dp | 24 | default icon size outside any component (the provider's root icon style) |
color | Color | colors.onSurface | default icon color outside any component |
Accessibility
- Non-null
contentDescription: exposed as an image with that label. - Null: excluded from the semantics tree. This is the right choice for every icon passed into a component, because the component carries the label (a button's
text, an icon button'scontentDescription).
4. Build steps
- Define
IconSource,IconStyle, and the ambient icon-style key with the provider default (24,onSurface). - Implement
CamoIconin core: resolve size and tint with the order above, apply semantics, callskin.icon.render. DebugSkinicon renderer: draw the asset at the resolved size and tint.- Sample:
- an
AppIconset of three assets; - one used standalone with a label;
- one placed inside a
CamoSurfacewhere the test sets an ambient style of 32 inprimary; - one multicolor logo with
original = true.
- an
- Tests:
- with no parameters, the icon follows the ambient style;
- parameters override the ambient style;
- a decorative icon has no semantics node;
originalignores the tint;autoMirrorflips it in RTL only.
Done when
- An app icon widget passed into a container picks up the container's size and color with no parameters.
- A screen reader reads labelled standalone icons and skips decorative ones.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Directional icons in RTL | IconSource(autoMirror = true). The default is false, because most icons (search, settings) must not flip. |
| Font scale 200% | Icons don't scale with text (platform convention). Components grow around their text, not their icons. |
| An app icon widget that ignores the ambient style (hard-coded color) | It draws what it says. That's the app's choice, but it won't follow skins or themes. The recommended wrapper pattern avoids it. |
A platform-native icon widget (Flutter Icon, Compose Icon) passed instead of CamoIcon | The renderer also sets the platform's own ambient icon theme where one exists (Flutter IconTheme), so native icons follow too. Compose's Icon reads LocalContentColor, which the Kotlin renderer also sets. See the platform notes. |
| Missing or broken asset | Platform behavior (an empty box of size). No crash. |
| A multicolor icon | original = true, never tinted. |
Implementation
1. Why
CamoIcon draws an icon asset at the size and color the surrounding component set, through LocalCamoIconStyle. In Kotlin the assets usually come from Compose Multiplatform Resources (Res.drawable.ic_search, common to every target) or ImageVectors. The app wraps each one in its own AppIcon composable.
2. Shape
3. API
@Immutable
public sealed interface IconSource {
public val autoMirror: Boolean
public val original: Boolean
public data class Vector(val image: ImageVector, override val autoMirror: Boolean = image.autoMirror,
override val original: Boolean = false) : IconSource
public data class Resource(val drawable: DrawableResource, override val autoMirror: Boolean = false,
override val original: Boolean = false) : IconSource
public data class Paint(val painter: Painter, override val autoMirror: Boolean = false,
override val original: Boolean = false) : IconSource
}
@Immutable public data class IconStyle(val size: Dp, val color: Color) // ambient; also the resolved icon theme
@Immutable public data class IconTheme(val size: Dp? = null, val color: Color? = null) {
// IconStyle.merge(IconTheme?) keeps non-null overrides
}
@Composable
public fun CamoIcon(
source: IconSource,
contentDescription: String?,
modifier: Modifier = Modifier,
size: Dp = Dp.Unspecified, // Unspecified → Camouflage.iconStyle.size
tint: Color = Color.Unspecified, // Unspecified → Camouflage.iconStyle.color
)
The AppIcon pattern (app side):
public object AppIcon {
@Composable fun Search(modifier: Modifier = Modifier, size: Dp = Dp.Unspecified, tint: Color = Color.Unspecified) =
CamoIcon(IconSource.Resource(Res.drawable.ic_search), contentDescription = null, modifier, size, tint)
@Composable fun Back(modifier: Modifier = Modifier) =
CamoIcon(IconSource.Resource(Res.drawable.ic_back, autoMirror = true), contentDescription = null, modifier)
}
// used as a slot: CamoButton(text = "Search", onClick = …, prefixIcon = { AppIcon.Search() })
contentDescription = null is the right default for icons passed into components, because the component carries the label.
Renderer (DebugSkin and Material are the same): core ships this as IconImage(state, modifier), so most icon renderers are one line.
val painter = when (s) { is Vector -> rememberVectorPainter(s.image); is Resource -> painterResource(s.drawable); is Paint -> s.painter }
val mirror = s.autoMirror && LocalLayoutDirection.current == LayoutDirection.Rtl
Image(painter, contentDescription = state.contentDescription,
modifier = modifier.size(state.size).graphicsLayer { if (mirror) scaleX = -1f },
colorFilter = if (s.original) null else ColorFilter.tint(state.color))
Compose's own Icon: renderers also provide LocalContentColor where available. But LocalContentColor belongs to material/material3, which core doesn't depend on, so a Material Icon placed in a slot keeps its own default color. Use CamoIcon-based AppIcons inside Camouflage components.
4. Build steps
IconSource,IconStyle,IconTheme+merge.CamoIcon: resolve size and tint fromLocalCamoIconStyle, setcontentDescriptionsemantics (orinvisibleToUser()when null), callskin.icon.Render.- The
IconRendererwithdefaults(theme) = IconStyle(24.dp, theme.colors.onSurface). - The sample
AppIconobject with 5 icons from Compose Resources. commonTest: an icon with no params insideProvideContentStyle(…, IconStyle(32.dp, Red))measures 32 dp; a decorative icon has no semantics node;autoMirrorflips only in RTL.
Done when
-
AppIcon.X()passed into a container takes the container's size and color with no parameters, on all four platforms.
5. Edge cases
| Case | Decided behavior |
|---|---|
Material Icon inside a Camouflage slot | Doesn't follow the icon style, because core has no Material dependency (see above). Documented. Use CamoIcon. |
| SVG assets | Compose Resources support Android vector XML on all targets. Convert SVGs to vector XML at import (Android Studio / Valkyrie plugin). |
ImageVector.autoMirror already set | IconSource.Vector defaults autoMirror to the vector's own flag. |
| Tint on a multicolor logo | original = true → no ColorFilter. |