Repository navigation
Fix Android adjustsFontSizeToFit shrinking text that fits - #56815
danyalahmed1995 wants to merge 1 commit into
Conversation
87cc0bd to
c5db280
Compare
c5db280 to
9c161e0
Compare
|
@CalixTang has imported this pull request. If you are a Meta employee, you can view this in D105609185. |
|
Any updates here? |
|
46 px still draws at 40 px on 0.89.0-rc.0. This PR needs a rebase: its Setup: template app on 0.88.1 and 0.89.0-rc.0, release build, API 36 arm64 emulator, 420 dpi, font scale 1, 2208×1840. Each row draws
The list depends on density; only 420 dpi was measured. The cause is the From the diff, this PR's early return should skip the loop for these rows. There was no patched build here; the reporter of #56799 wrote: "I tested the provided patch and it fixes this bug." For text that has to shrink, Mixed sizes that have to shrink still drift, because each step rescales sizes that are already rounded. In the replay at 420 dpi, with #59792 and #59800 (open) change the width and height limits, including On Repro (needs a screen about 816 dp wide)npx @react-native-community/cli@latest init FitRepro --version 0.89.0-rc.0 --skip-install --skip-git-init --pm npm
cd FitRepro && npm install
# replace App.tsx with the file below
cd android && ./gradlew :app:assembleRelease -PreactNativeArchitectures=arm64-v8a
adb install app/build/outputs/apk/release/app-release.apkimport React from 'react';
import {PixelRatio, Text, View} from 'react-native';
const SAMPLE = 'Hxg 00:00';
const density = PixelRatio.get();
// RN applies ceil(fontSize * density), so this lands on the wanted pixel size.
const fontSizeFor = (px: number) => (px - 0.5) / density;
const range = (a: number, b: number) => Array.from({length: b - a + 1}, (_, i) => a + i);
const COLUMNS = [range(20, 52), range(53, 70)];
const cell = {width: 130};
function Row({px}: {px: number}) {
const style = {fontSize: fontSizeFor(px), color: 'black'};
return (
<View style={{flexDirection: 'row'}}>
<View style={cell}><Text style={style} numberOfLines={1}>{SAMPLE}</Text></View>
<View style={cell}><Text style={style} numberOfLines={1} adjustsFontSizeToFit>{SAMPLE}</Text></View>
<View style={cell}><Text style={style} numberOfLines={1} adjustsFontSizeToFit minimumFontScale={0.8}>{SAMPLE}</Text></View>
</View>
);
}
export default function App() {
return (
<View style={{flex: 1, backgroundColor: 'white', flexDirection: 'row', paddingTop: 40, paddingLeft: 16}}>
{COLUMNS.map(sizes => (
<View key={sizes[0]} style={{width: 400}}>
{sizes.map(px => <Row key={px} px={px} />)}
</View>
))}
</View>
);
}Claude Code ran these checks and drafted this comment. |

Summary
Fixes an Android
Textregression whereadjustsFontSizeToFit={true}could shrink text even when the original size already fits.The Android font-size fitting path now performs an initial layout check before entering the binary-search resize loop. If the original layout already satisfies the same max-lines, height, and single-character-width constraints used by the fitting logic, it returns without mutating
TextPaintorReactAbsoluteSizeSpanvalues.Fixes #56799.
Test Plan
adjustsFontSizeToFit.ReactAbsoluteSizeSpan(22)andTextPaint.textSize = 22fremain unchanged when the text has enough space and no max-line pressure.Changelog:
[Android] [Fixed] - Prevent adjustsFontSizeToFit from shrinking text when the original Android Text layout already fits.