CamoText
Concept
1. Why
Text is in every other component: a button's text, a dialog's message, a field's error. CamoText is where the theme's text style constants and the content color chosen by the surrounding container turn into real text. It also covers rich text (bold words, links inside a sentence), because real screens need "I agree to the Terms" and a plain string can't express that.
If CamoText("Save") inside a Solid button comes out in onPrimary without the caller passing a color, the content-color mechanism works, and every later component relies on it.
2. Shape
Span model. Rich text is a list of CamoSpans. Each span inherits the base style and color and overrides only what it sets. Platforms map spans to their own type:
- Flutter:
Text.rich(TextSpan(children: [...])), with aTapGestureRecognizerfor links. - Compose:
AnnotatedStringviabuildAnnotatedString { withStyle(SpanStyle(...)) }, withLinkAnnotation.Clickablefor links.
Material mapping preview:
- Plain text uses the given style.
- Links are drawn in
primarywith an underline. - Other skins may style links differently (a Cupertino skin might use
primarywith no underline).
See Material Skin.
3. API
Contract
fun CamoText(
text: String,
style: CamoTextStyle = Camouflage.typography.bodyMedium,
color: Color? = null, // null → Camouflage.contentColor
maxLines: Int = Unlimited,
overflow: TextOverflow = Clip, // Clip | Ellipsis
textAlign: TextAlign = Start, // Start | Center | End (start/end mirror in RTL)
)
fun CamoText.rich(
vararg spans: CamoSpan,
style: CamoTextStyle = Camouflage.typography.bodyMedium,
color: Color? = null,
maxLines: Int = Unlimited,
overflow: TextOverflow = Clip,
textAlign: TextAlign = Start,
)
data class CamoSpan(
val text: String,
val style: CamoTextStyle? = null, // null → inherit the base style; e.g. typography.headlineSmall for a big number
val fontWeight: FontWeight? = null, // null → inherit (applied on top of style)
val italic: Boolean? = null,
val color: Color? = null,
val underline: Boolean? = null,
val link: (() -> Unit)? = null, // non-null → an accessible link, styled by the skin
)
| Parameter | What it's for |
|---|---|
text / spans | the content. A plain string, or spans for mixed styling and links. |
style | a text style value: one of the 15 constants, optionally adjusted with copy (typography.titleMedium.copy(fontWeight = Bold)) |
color | a color value, usually from Camouflage.colors (Camouflage.colors.success) |
maxLines, overflow | truncation (top-bar title, list rows) |
textAlign | alignment inside the text's own box (a centered empty-state message) |
State → renderer: TextState(content: String or List<CamoSpan>, style, resolvedColor, maxLines, overflow, textAlign). Slots: none.
Tokens used
typography.*, as passedcolors.primaryfor links (the skin decides)- the content color when
coloris null
Accessibility
- Exposed as static text to screen readers.
- Each link span is a separate accessible link: focusable in order, announced as "link", and activated with Enter. Platforms: Compose
LinkAnnotationdoes this; Flutter needsSemanticsper link span (the Flutter note covers it). - Link targets are hard to hit when inline, so a skin may add vertical padding to link spans. The minimum target (48) can't always be met inline, and WCAG 2.5.8 exempts inline links.
- It must scale with the system font size, and respect the bold-text setting where the platform exposes one.
4. Build steps
- Define
CamoSpanand theTextStatecontent union (a plain string or spans). - Implement
CamoTextandCamoText.richin core: resolve the color, buildTextState, callCamouflage.skin.text.render. DebugSkintext renderer: plain text, and spans mapped to the platform rich-text type, with links underlined.- Sample:
- all 15 styles in a column, in light and dark;
- a
copy(fontWeight = Bold)example; - "I agree to the Terms and Privacy Policy" with two links;
- a success message using
color = Camouflage.colors.success.
- Tests:
- with no
color, text uses the content color (onSurfaceat the root,onPrimaryinside a Primary container); maxLines = 1+Ellipsistruncates;- each link is its own focusable link node and fires its callback;
- a span without overrides inherits the base style.
- with no
Done when
- All 15 styles render, and
copyadjusts one property. - Links in a sentence work by touch, keyboard and screen reader.
- At 200% font scale, text wraps (with
maxLinesunlimited).
5. Edge cases
| Case | Decided behavior |
|---|---|
| Font scale 200% | The text grows and wraps. The renderer never fixes the height. |
| RTL string, and mixed-direction text | The platform bidi algorithm. Start/End alignment mirrors. |
A span with its own style (settled 2026-09-27) | The span's style replaces the base style for that span; fontWeight, italic, color and underline apply on top. Only style values (the 15 roles, optionally copy-adjusted), never a bare font size, so sizes stay on the type scale and font scaling applies. The line takes the tallest line height in it, and all spans share one baseline. |
| Empty string | Renders nothing, and keeps its line height so layouts don't jump. |
| A link span inside a clickable parent (a clickable card) | Nested clickables are discouraged (see CamoCard). The link wins inside its own bounds. |
| Very long rich text (a legal page) | Works, but it's not a document renderer. Markdown/HTML rendering is out of scope. |
| A custom font missing a weight | The platform synthesizes bold. |
color with poor contrast on its surface | The app's responsibility. validate() checks only the theme's own pairs. |
Implementation
1. Why
CamoText is Camouflage's text primitive, built on Compose foundation's BasicText (not Material's Text, which reads MaterialTheme). Rich text maps to Compose's AnnotatedString, and links map to LinkAnnotation.Clickable, which Compose makes focusable and accessible for us.
2. Shape
3. API
@Composable
public fun CamoText(
text: String,
modifier: Modifier = Modifier,
style: TextStyle = Camouflage.typography.bodyMedium,
color: Color = Color.Unspecified, // Unspecified → Camouflage.contentColor
maxLines: Int = Int.MAX_VALUE,
overflow: TextOverflow = TextOverflow.Clip,
textAlign: TextAlign = TextAlign.Start,
)
@Composable
public fun CamoText( // the base CamoText.rich: an overload by type
spans: List<CamoSpan>,
modifier: Modifier = Modifier,
style: TextStyle = Camouflage.typography.bodyMedium,
color: Color = Color.Unspecified,
maxLines: Int = Int.MAX_VALUE,
overflow: TextOverflow = TextOverflow.Clip,
textAlign: TextAlign = TextAlign.Start,
)
@Immutable
public data class CamoSpan(
val text: String,
val style: TextStyle? = null, // → SpanStyle(style.toSpanStyle()), then weight/italic/color on top; line height via ParagraphStyle max
val fontWeight: FontWeight? = null,
val italic: Boolean? = null,
val color: Color = Color.Unspecified,
val underline: Boolean? = null,
val link: (() -> Unit)? = null,
)
Span → AnnotatedString (in core, so every skin gets correct links):
internal fun List<CamoSpan>.toAnnotated(linkStyle: TextLinkStyles): AnnotatedString = buildAnnotatedString {
for (span in this@toAnnotated) {
val spanStyle = SpanStyle(
fontWeight = span.fontWeight,
fontStyle = span.italic?.let { if (it) FontStyle.Italic else FontStyle.Normal },
color = span.color,
textDecoration = if (span.underline == true) TextDecoration.Underline else null,
)
if (span.link != null) {
withLink(LinkAnnotation.Clickable(tag = span.text, styles = linkStyle) { span.link.invoke() }) {
withStyle(spanStyle) { append(span.text) }
}
} else withStyle(spanStyle) { append(span.text) }
}
}
The link style comes from the skin: TextRenderer exposes fun linkStyles(theme): TextLinkStyles (Material: primary + underline, and a focused/hovered background).
Why an overload: Kotlin can't write CamoText.rich, and Compose itself overloads by type (Text(String) / Text(AnnotatedString)). One name is easier to discover and for codegen to target; a String and a List<CamoSpan> can't be confused.
Renderer: TextState(content: AnnotatedString, style: TextStyle, color: Color, maxLines, overflow, textAlign). A plain String is wrapped as AnnotatedString(text), so renderers handle one type.
4. Build steps
CamoSpan+toAnnotated().- Both
CamoTextoverloads: resolve the color (color.takeOrElse { Camouflage.contentColor }), buildTextState, callrequireSkin("CamoText").text.Render(...). DebugSkin.text:BasicTextwith the resolved style.commonTest(runComposeUiTest):- text under a provider has color
onSurface; - inside
ProvideContentStyle(Red, …)it's red; - a spans
CamoTextwith two links exposes two link nodes, andperformClickon the second fires only its callback; maxLines = 1givesTextLayoutResult.hasVisualOverflow.
- text under a provider has color
Done when
- The 15-style specimen renders in the sample on all four platforms.
- Links are reachable with Tab on desktop and with a screen reader on Android/iOS.
5. Edge cases
| Case | Decided behavior |
|---|---|
Base CamoText.rich → Kotlin CamoText(spans = …) | An overload. Flutter keeps CamoText.rich (a named constructor). |
color type | Color with Unspecified as "not set" (the Compose idiom) instead of Color?, which avoids boxing. |
| Links on web (canvas) | Clicks work. Screen-reader exposure is limited on the web target (ADR-18). |
| Text selection | Not enabled by default. Wrap in SelectionContainer at the app level. |
| Font scale | sp units follow LocalDensity.fontScale on every platform. |