Repository navigation
Add message typography and inline link styling theme keys - #210
Conversation
Adds four theme keys so brands can tune message text for readability and WCAG contrast compliance: - --message-font-size -> typography.fontSize; applied via ConciergeStyles.withThemeTypography (previously only lineHeight was) - --message-font-weight -> typography.fontWeight; same path - --message-concierge-link-font-weight -> typography.linkFontWeight; honored by renderLink/renderBoldLink/renderItalicLink - --message-concierge-link-underline -> typography.linkUnderline; TextDecoration.Underline was hardcoded in all three link renderers, now theme-controlled All keys default to prior behavior (Material defaults, inherit weight, underlined) so existing themes are unaffected. - Tests: 2 new ThemeParserTest cases (explicit values + missing-key defaults); 112/112 passing - Docs: style-guide.md property and implementation tables
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
| TokenType.LINK -> renderLink(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref) | ||
| TokenType.BOLD_LINK -> renderBoldLink(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref, linkFontWeight, linkUnderline) | ||
| TokenType.ITALIC_LINK -> renderItalicLink(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref, linkFontWeight, linkUnderline) | ||
| TokenType.LINK -> renderLink(token, builder, colorScheme, baseTextStyle, linkColor, linkHintByHref, linkFontWeight, linkUnderline) |
There was a problem hiding this comment.
[HIGH] linkFontWeight/linkUnderline are passed to the top-level link renderers but get lost on the nested path. renderList and renderBlockquote (lines 153–154) don't take them, and renderNestedMarkdown calls renderToken again at line 521 without them, so the defaults (null / true) come back. For example, > [Store](https://store.example.com) with --message-concierge-link-underline: "false" and a custom link weight still shows an underlined, weight-400 link. iOS passes linkUnderline through its nested renderers. Could you pass both values through renderList → renderNestedMarkdown → renderToken and renderBlockquote → renderNestedMarkdown → renderToken, and add a renderer test for a link inside a blockquote and a list?
| // fontFamily = typography.fontFamily?.let { FontFamily(...) }, | ||
| lineHeight = typography.lineHeight?.let { (this.fontSize.value * it).sp } ?: this.lineHeight | ||
| fontSize = typography.fontSize?.sp ?: this.fontSize, | ||
| fontWeight = typography.fontWeight?.let { FontWeight(it) } ?: this.fontWeight, |
There was a problem hiding this comment.
[HIGH] parseFontWeight accepts any whole number, but Compose's FontWeight(Int) throws IllegalArgumentException outside 1–1000. A theme value like "0" or "1001" would then crash every message bubble, since this style is used by messageBubbleStyle. The disclaimer style already guards against this with FontWeight(w.coerceIn(100, 900)) (around line 961). Could you do the same here, or better, reject out-of-range values in CSSKeyMapper so the token never holds an invalid weight?
| val darkTheme = isSystemInDarkTheme() | ||
| val linkColor = ConciergeTheme.colors.messageConciergeLink ?: ConciergeTheme.colors.onSurface | ||
| val typography = ConciergeTheme.tokens?.typography | ||
| val linkFontWeight = typography?.linkFontWeight?.let { FontWeight(it) } |
There was a problem hiding this comment.
[HIGH] Same range problem as ConciergeStyles.kt:103. This runs for every bot message, even ones with no links, so an out-of-range --message-concierge-link-font-weight crashes plain assistant text too.
| ) | ||
| }, | ||
| "message-concierge-link-font-weight" to { cssValue, theme -> | ||
| val linkFontWeight = CSSValueConverter.parseFontWeight(cssValue) |
There was a problem hiding this comment.
[LOW] parseFontWeight turns an unreadable value (e.g. "heavy") into 400 instead of null. For link weight, that 400 then overrides FontWeight.Bold on **[text](url)** links. parseFontWeightOrNull plus a 1–1000 range check here (and for message-font-weight above) would fall back to the default look and also fix the crash.
| textDecoration = TextDecoration.Underline, | ||
| fontWeight = FontWeight.Bold | ||
| textDecoration = if (linkUnderline) TextDecoration.Underline else null, | ||
| fontWeight = linkFontWeight ?: FontWeight.Bold |
There was a problem hiding this comment.
[LOW] With linkFontWeight ?: FontWeight.Bold, a 500 or 600 link weight makes markdown-bold links lighter than the author's bold. Would taking the heavier of the two (maxOf(linkFontWeight ?: FontWeight.Bold, FontWeight.Bold)) be closer to what's intended? Either way, it would be good to match iOS here.
| // Note: Font family would require loading custom fonts, which is not implemented yet | ||
| // fontFamily = typography.fontFamily?.let { FontFamily(...) }, | ||
| lineHeight = typography.lineHeight?.let { (this.fontSize.value * it).sp } ?: this.lineHeight | ||
| fontSize = typography.fontSize?.sp ?: this.fontSize, |
There was a problem hiding this comment.
[LOW] parsePxValue accepts "0" and negative values, which would hide or break message text. Should this only accept values above 0 (in the mapper or here)?
| val lineHeight: Double? = null | ||
| val lineHeight: Double? = null, | ||
| /** Message body font size in sp. When null, the Material default for the text style is used. */ | ||
| val fontSize: Double? = null, |
There was a problem hiding this comment.
[LOW] ConciergeTypography is a public data class, so adding fields changes its JVM constructor and copy signatures. Apps already compiled against the old (String, Double) constructor would hit NoSuchMethodError until they recompile. This repo already changes public theme classes this way, so it's probably fine, but worth a line in the release notes rather than calling it fully backward compatible.
- Preserve link weight and underline settings through lists, blockquotes, and nested Markdown. - Validate JSON and programmatic message sizes and font weights, logging warnings and retaining defaults for invalid values. - Keep Markdown-bold links at least bold and preserve italics. - Distinguish absolute pixel line heights from unitless multipliers. - Apply body line height without overriding headings or fenced code. - Supply the resolved base font size to paragraph and list responses for consistent accessibility font scaling. - Add renderer, validation, production UI, streaming, and caching regression tests. - Document theme behavior, accessibility guidance, and the public typography data class's binary compatibility impact. Validation: - 389 focused unit tests passed. - 138 UI and integration tests passed across two runs. - Accessibility scaling matrix: 96 combinations passed. - Kotlin formatting and diff checks passed. Full Java lint and coverage verification remain limited by existing JDK/tooling incompatibilities.
|
@rymorale The review follow-up is pushed in 74ae7c3 and ready for another look. It addresses nested link styling, invalid CSS/programmatic typography values, bold-link precedence, and binary compatibility documentation, plus the line-height and accessibility-scaling issues found during follow-up validation. Permanent regression coverage includes 389 focused unit tests, 138 UI/integration tests across two runs, and a 96-combination scaling matrix. The PR description now distinguishes verified results, intentional behavior fixes, and local tooling limitations. This update is Android-only; iOS parity is called out separately. Thank you for reviewing. |
Compare identical two-line text in response and reference layouts. Assert line counts and expand the accessibility matrix to cover narrow and wide layouts without weakening spacing checks.
rymorale
left a comment
There was a problem hiding this comment.
A few remaining items, none blocking:
[LOW] CSSValueConverter.parseLineHeight (CSSValueConverter.kt:154) is no longer used by production code now that line-height-body goes through parsePxValue. Only its own tests reference it. It still silently falls back to 1.5 on invalid input, which is the behavior this PR moves away from. Consider removing it and its tests, or delegating it to the new parsing, so it doesn't get reused by mistake.
| lineHeight = typography.lineHeight?.let { (this.fontSize.value * it).sp } ?: this.lineHeight | ||
| fontSize = typography.fontSize?.sp ?: this.fontSize, | ||
| fontWeight = typography.fontWeight?.let { FontWeight(it) } ?: this.fontWeight, | ||
| lineHeight = safeLineHeight?.sp ?: this.lineHeight |
There was a problem hiding this comment.
[MEDIUM] When a theme sets only --message-font-size and no line height, the ?: this.lineHeight fallback keeps the base style's line height. For the message bubble style that's Material3 bodyLarge's fixed 24.sp. User message bubbles (ChatMessageItem, Text(style = style.textStyle)) and the privacy notice use this style directly, so larger font sizes render with overlapping lines.
I confirmed this with a probe test on an API 31 emulator. With fontSize = 32 and no line height, the resolved style was fontSize=32.sp, lineHeight=24.sp, and the baseline-to-baseline gap was 63px for an 84px font.
Bot responses aren't affected because ClickableText there gets only fontSize. Suggested fix: when typography.fontSize is set and no line height is configured, either scale the inherited line height proportionally (this.lineHeight * resolvedSize / fontSize.value) or drop it (TextUnit.Unspecified) so the font's natural metrics apply. A UI test for a user bubble with a large font size would cover it.
| ### Message typography | ||
|
|
||
| Added optional message body size/weight and inline link weight/underline theme | ||
| overrides. Defaults preserve existing behavior. Invalid CSS sizes and weights |
There was a problem hiding this comment.
[LOW] "Defaults preserve existing behavior" undersells one visible change. --line-height-body previously never reached bot markdown responses, because toSpanStyle() drops lineHeight. It now does, via ParagraphStyle. Every bundled sample theme sets it (1.5–1.75), and most customer themes probably do too, so bot response spacing will change on upgrade. This matches iOS, which already applies the multiplier to agent messages, but it's worth stating explicitly as a behavior change so integrators expect it.
| Log.w(LOG_TAG, "Ignoring invalid --line-height-body; expected a finite positive multiplier or pixel value.") | ||
| theme | ||
| } else { | ||
| val absolute = cssValue.trim().endsWith("px") |
There was a problem hiding this comment.
[NIT] endsWith("px") and parsePxValue are case-sensitive, so "24PX" is rejected with a warning, while parseFontWeightOrNull lowercases its input. This matches existing parsePxValue behavior elsewhere, so it's fine to leave. Just flagging the inconsistency.
Delete parseLineHeight, which is no longer used in production and silently defaults invalid values to 1.5. Remove its obsolete tests; the active line-height parsing behavior is unchanged.
|
it looks like the legacy line-height parser was addressed but can you also take a look at the medium priority issue (as well as the nit if possible)? |
When only a message font size is configured, scale the inherited line height proportionally to avoid cramped message text. Also accept case-insensitive px suffixes when parsing and classifying absolute line heights. Add regression tests for font-size-only line-height scaling and mixed-case pixel units, and update the style guide and release notes.
Replace the incorrect previous-multiplier expectation with explicit checks for unspecified line height and no paragraph override. Compare fallback dimensions and baselines against a Material text reference while retaining multiplier and absolute-height precedence checks. Test-only change; no production code or dependency changes. Validation: all 11 typography UI tests passed locally. Kotlin formatting and instrumentation-test compilation passed.
rymorale
left a comment
There was a problem hiding this comment.
Re-review at 43dec3a: thanks for the follow-ups. The font-size-only line-height scaling fixes the overlapping lines in user bubbles, and px is now case-insensitive, which also matches iOS. The overflow fallback to TextUnit.Unspecified is a nice improvement too.
Validation, with the PR merged onto current dev (clean merge):
make checkformat: passmake unit-test: 1,801 tests, 0 failuresMessageTypographyTestandMarkdownParserComposeTeston an API 31 emulator: pass
One non-blocking edge case is inline. Approving.
| val resolvedSize = themedFontSize ?: fontSize.value | ||
| val inheritedScaledLineHeight = themedFontSize?.let { size -> | ||
| if (fontSize != TextUnit.Unspecified && lineHeight != TextUnit.Unspecified && fontSize.value > 0) { | ||
| lineHeight * (size / fontSize.value) |
There was a problem hiding this comment.
[LOW, non-blocking] TextUnit.times keeps the unit type, so this only works when the inherited lineHeight is in sp. ConciergeTheme inherits the host app's MaterialTheme.typography. If a host defines bodyLarge with an em line height, that value already scales with font size, so multiplying it by the size ratio applies the scaling twice.
I checked this with a probe on an API 31 emulator: host bodyLarge = TextStyle(fontSize = 16.sp, lineHeight = 1.5.em) plus --message-font-size: 32px resolved to lineHeight = 3.0.em, giving a 96px baseline gap instead of 48px. Material's defaults use sp, so this is rare. Guarding the scaling with lineHeight.isSp (and leaving em values unchanged) would cover it.
Scale only sp values when theming message size, retaining inherited em values and explicit overrides. Add a regression layout test for the preserved line heights. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
Adds four message typography theme keys for readability and brand customization:
--message-font-sizetypography.fontSize--message-font-weighttypography.fontWeight--message-concierge-link-font-weighttypography.linkFontWeight--message-concierge-link-underlinetypography.linkUnderlinetrueBody size/weight apply to user and concierge message bodies and the privacy notice sharing that style. Link overrides apply to inline concierge response links, including nested lists and blockquotes, not Sources rows or other UI links. Italic links retain italics.
Review follow-up
Commit
74ae7c3addresses the review feedback and related rendering regressions:--line-height-bodypixel values from unitless multipliers."24px"maps to 24sp;"1.5"scales with body size. ProgrammaticlineHeightPxtakes precedence overlineHeight.Accessibility
These controls do not by themselves establish WCAG compliance. Underlining helps distinguish links but does not replace text/background contrast. Normal text requires 4.5:1 for WCAG AA; the 3:1 threshold applies only to qualifying large text. Heavier weight alone does not improve the contrast ratio. Check the actual message background.
Compatibility
Omitted new message keys preserve existing defaults. Explicit body line height is now honored in assistant response paragraphs, with corrected absolute pixel handling; these are intentional fixes.
ConciergeTypographyis a public Kotlin data class. Added parameters change its JVM constructor and generatedcopysignatures: ordinary source calls that omit the new defaulted fields continue to compile, but previously compiled applications/libraries must be recompiled. This is not binary-compatible. Details are inDocumentation/release-notes.md.The iOS counterpart is adobe/aepsdk-concierge-ios#202. This follow-up changes Android only; iOS bold-link precedence still needs separate follow-up, so platform parity is not claimed.
Validation
Theme usage
Values in the CSS-style
themeblock are strings, including"true"rather than booleantrue.