Skip to main content

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 a TapGestureRecognizer for links.
  • Compose: AnnotatedString via buildAnnotatedString { withStyle(SpanStyle(...)) }, with LinkAnnotation.Clickable for links.

Material mapping preview:

  • Plain text uses the given style.
  • Links are drawn in primary with an underline.
  • Other skins may style links differently (a Cupertino skin might use primary with 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
)
ParameterWhat it's for
text / spansthe content. A plain string, or spans for mixed styling and links.
stylea text style value: one of the 15 constants, optionally adjusted with copy (typography.titleMedium.copy(fontWeight = Bold))
colora color value, usually from Camouflage.colors (Camouflage.colors.success)
maxLines, overflowtruncation (top-bar title, list rows)
textAlignalignment 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 passed
  • colors.primary for links (the skin decides)
  • the content color when color is 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 LinkAnnotation does this; Flutter needs Semantics per 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​

  1. Define CamoSpan and the TextState content union (a plain string or spans).
  2. Implement CamoText and CamoText.rich in core: resolve the color, build TextState, call Camouflage.skin.text.render.
  3. DebugSkin text renderer: plain text, and spans mapped to the platform rich-text type, with links underlined.
  4. 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.
  5. Tests:
    • with no color, text uses the content color (onSurface at the root, onPrimary inside a Primary container);
    • maxLines = 1 + Ellipsis truncates;
    • each link is its own focusable link node and fires its callback;
    • a span without overrides inherits the base style.

Done when

  • All 15 styles render, and copy adjusts one property.
  • Links in a sentence work by touch, keyboard and screen reader.
  • At 200% font scale, text wraps (with maxLines unlimited).

5. Edge cases​

CaseDecided behavior
Font scale 200%The text grows and wraps. The renderer never fixes the height.
RTL string, and mixed-direction textThe 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 stringRenders 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 weightThe platform synthesizes bold.
color with poor contrast on its surfaceThe 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​

  1. CamoSpan + toAnnotated().
  2. Both CamoText overloads: resolve the color (color.takeOrElse { Camouflage.contentColor }), build TextState, call requireSkin("CamoText").text.Render(...).
  3. DebugSkin.text: BasicText with the resolved style.
  4. commonTest (runComposeUiTest):
    • text under a provider has color onSurface;
    • inside ProvideContentStyle(Red, …) it's red;
    • a spans CamoText with two links exposes two link nodes, and performClick on the second fires only its callback;
    • maxLines = 1 gives TextLayoutResult.hasVisualOverflow.

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​

CaseDecided behavior
Base CamoText.rich → Kotlin CamoText(spans = …)An overload. Flutter keeps CamoText.rich (a named constructor).
color typeColor 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 selectionNot enabled by default. Wrap in SelectionContainer at the app level.
Font scalesp units follow LocalDensity.fontScale on every platform.