Skip to content

Fix adjustsFontSizeToFit clipping when container height shrinks on Android#57597

Open
imsankalp wants to merge 1 commit into
react:mainfrom
imsankalp:fix/android-adjusts-font-size-to-fit-resize
Open

Fix adjustsFontSizeToFit clipping when container height shrinks on Android#57597
imsankalp wants to merge 1 commit into
react:mainfrom
imsankalp:fix/android-adjusts-font-size-to-fit-resize

Conversation

@imsankalp

Copy link
Copy Markdown

Summary:

When a <Text adjustsFontSizeToFit> component's container height decreases dynamically (e.g. height=60 → height=20), the text is clipped instead of having its font size recalculated.

Root cause: mShouldAdjustSpannableFontSize — the gate that triggers font recalculation in onDraw — is only set by text-content setters (setSpanned, setNumberOfLines, etc.). A pure container resize never sets it. Meanwhile the background Fabric measurement thread mutates the shared cached spannable (tagToSpannableCache) to the larger font size. When the container then shrinks, onDraw skips recalculation and draws the stale large font in the smaller container, causing clipping.

Fix: Override onSizeChanged in ReactTextView to set mShouldAdjustSpannableFontSize = true whenever the view dimensions change and adjustsFontSizeToFit is active. Android automatically schedules a redraw on size change, so the next onDraw recalculates the font with the correct current height.

Changelog:

[ANDROID] [FIXED] - Fix Text with adjustsFontSizeToFit being clipped when container height decreases dynamically

Test Plan:

Tested using the existing RNTester example which already reproduces this bug:

  1. Build and run RNTester on Android
  2. Navigate to TextFont Size Adjustment with Dynamic Layout
  3. Press Set Height to 60 — text grows to fill the yellow container
  4. Press Set Height to 20 — before this fix, text is clipped; after this fix, text shrinks to fit correctly
  5. Repeat steps 3–4 rapidly — no clipping at any point

The reproducer is packages/rn-tester/js/examples/Text/TextAdjustsDynamicLayoutExample.js.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 18, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant