Skip to content

Fix backwards write in DancingBotHeadlineText - #220

Merged
riggaroo merged 1 commit into
mainfrom
riggaroo/fix-dancing-bot-backwards-write
Nov 18, 2026
Merged

riggaroo merged 1 commit into
mainfrom
riggaroo/fix-dancing-bot-backwards-write

Conversation

@riggaroo

@riggaroo riggaroo commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes a backwards write in DancingBotHeadlineText (Home screen headline with the inline dancing bot).

Problem

placeHolderSize was read during composition to size the inline bot (Placeholder(width = placeHolderSize, …)), then written back from onTextLayout after the auto-sized text was laid out:

var placeHolderSize by remember { mutableStateOf(220.sp) }
Placeholder(width = placeHolderSize, height = placeHolderSize, …)        // read in composition
onTextLayout = { result ->
    placeHolderSize = result.layoutInput.style.fontSize * 3.5f          // written after layout
}

That is a Composition-read → Layout-write backwards write. Every text layout invalidates composition and triggers another pass. The first frame always uses the hard-coded 220.sp default, and after a size change the bot keeps its old size for one frame before snapping to the right size.

Fix

Size the placeholder in em. That is resolved against the auto-sized font during text layout itself, so there's no state, no onTextLayout write-back and no extra pass:

Placeholder(width = 3.5.em, height = 3.5.em, …)

Before / after (resize, frame by frame, slowed down)

Before After
before after

The frame right after the resize: before keeps the stale 232 dp bot over the text, after is already 180 dp:

frame 1 side by side

How these were captured: a Robolectric test (GraphicsMode.NATIVE, paused mainClock, one advanceTimeByFrame() per capture) rendered DancingBotHeadlineText on both commits and read the placeholder rects from TextLayoutResult.

  • Before: the stale size shows on exactly 1 frame per layout change, both on first composition (220 → 232 dp) and after a resize (232 → 180 dp).
  • After: frame 0 already matches before's settled layout, and every frame from then on is pixel-identical to before's settled frames.
  • Limits: the bot is the bundled static placeholder image, because inspection mode was on. Frames are drawn on a software canvas, not a device.

Device check (real Home screen, Robolectric)

HomeScreenContents rendered on 6 device configurations on both commits (LocalInspectionMode, the same wrapper the app's @Previews use). Once settled, AFTER is pixel-identical to BEFORE on every device, so the em change causes no visual regression. The only difference is that BEFORE's wrong first frame is gone.

Device Layout BEFORE: frame 0 → settled bot AFTER: frame 0
Phone portrait 411×914dp Compact 220 → 232 dp 232 dp
Phone landscape 914×411dp Medium 220 → 200.7 dp 200.7 dp
Foldable unfolded 841×701dp Medium 220 → 290 dp 290 dp
Foldable unfolded portrait 701×841dp Medium 220 → 234 dp 234 dp
Foldable folded 388×841dp Compact 220 → 216.3 dp 216.3 dp
Tablet landscape 1280×800dp Medium 220 → 466.5 dp 466.5 dp

Unfold, folded → unfolded in one composition (top: before, bottom: after). BEFORE renders one frame with the 220.sp default (bot too small) before 290 dp. AFTER is 290 dp immediately.

unfold before/after

Settled Home screen on all 6 devices (before | after)

devices

Caveats: preview images stand in for the bot and video card; no system bars or insets; the unfold is a container resize inside a fixed window, not a real configuration change.

Testing

  • ./gradlew :feature:home:spotlessCheck :feature:home:compileReleaseKotlin passes.
  • Robolectric renders of the headline and the full Home screen on phone, foldable and tablet configurations (above).
  • Not yet checked on a physical device. Please sanity-check the Home screen headline, including fold/unfold, resizing and rotation, before merging.

Found with the jetpack-compose-performance agent skill.

The placeholder size was read in composition and written back from
onTextLayout, so every text layout invalidated composition and the first
frame used the 220.sp default. Size the placeholder in em instead, which is
resolved against the auto-sized font during text layout.
@riggaroo
riggaroo marked this pull request as ready for review November 16, 2026 17:30
@riggaroo
riggaroo requested a review from tiwiz as a code owner November 16, 2026 17:30
@riggaroo
riggaroo merged commit 19f1c1b into main Nov 18, 2026
10 checks passed
@tiwiz
tiwiz deleted the riggaroo/fix-dancing-bot-backwards-write branch November 18, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants