Skip to content

Commit b236e15

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Fix font scaling when numberOfLines is not set on Android on the new arch (#44165)
Summary: This is a follow-up to #44075. I've missed the fact that `ReactConstants.UNSET` is `-1` and the default value of `numberOfLines` prop is `0`. This resulted in font size being set to the minimal value when `adjustFontSizeToFit` was used without setting `numberOfLines` to a positive value. ## Changelog: [ANDROID] [FIXED] - Fixed `adjustFontSizeToFit` when used without `numberOfLines` Pull Request resolved: #44165 Test Plan: <details> <summary>Tested on the following code</summary> ```jsx import { Text, SafeAreaView, View, StyleSheet } from 'react-native'; export default function Test() { return ( <SafeAreaView style={styles.container}> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }}> Some text that fits (no adjust, unlimited height) </Text> </View> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }} adjustsFontSizeToFit> Some text that fits (adjust, unlimited height) </Text> </View> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }} numberOfLines={1}> Some text that fits (no adjust, 1 line) </Text> </View> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }} adjustsFontSizeToFit numberOfLines={1}> Some text that fits (adjust, 1 line) </Text> </View> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }}> Some longer text that doesn't fit if displayed in one line (no adjust, unlimited height) </Text> </View> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }} adjustsFontSizeToFit> Some longer text that doesn't fit if displayed in one line (adjust, unlimited height) </Text> </View> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }} numberOfLines={1}> Some longer text that doesn't fit if displayed in one line (no adjust, 1 line) </Text> </View> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }} adjustsFontSizeToFit numberOfLines={1}> Some longer text that doesn't fit if displayed in one line (adjust, 1 line) </Text> </View> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }}> Even longer text that doesn't even fit if it has as much as two entire lines for itself, what a darn shame (no adjust, unlimited height) </Text> </View> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }} adjustsFontSizeToFit> Even longer text that doesn't even fit if it has as much as two entire lines for itself, what a darn shame (adjust, unlimited height) </Text> </View> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }} numberOfLines={2}> Even longer text that doesn't even fit if it has as much as two entire lines for itself, what a darn shame (no adjust, 2 lines) </Text> </View> <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}> <Text style={{ fontSize: 16 }} numberOfLines={2} adjustsFontSizeToFit> Even longer text that doesn't even fit if it has as much as two entire lines for itself, what a darn shame (adjust, 2 lines) </Text> </View> </SafeAreaView> ); } ``` </details> |Old arch|New arch (without this PR)|New arch (with this PR)| |-|-|-| |<img width="447" alt="a_old" src="https://github.com/facebook/react-native/assets/21055725/4822f7f1-a19c-4225-9318-0eb2fec6f925">|<img width="447" alt="a_new_no_change" src="https://github.com/facebook/react-native/assets/21055725/ff594673-b362-4a81-8837-624cb1061d28">|<img width="447" alt="a_new_changed" src="https://github.com/facebook/react-native/assets/21055725/1f29c01c-1c91-4c9f-9edd-0950338b5d39">| Reviewed By: NickGerleman Differential Revision: D56362020 Pulled By: cortinico fbshipit-source-id: 2aecbe66043870cf14536850ecbfb7c3890acd72
1 parent 03a51da commit b236e15

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ public static void adjustSpannableFontToFit(
419419
int initialFontSize = currentFontSize;
420420
while (currentFontSize > minimumFontSize
421421
&& ((maximumNumberOfLines != ReactConstants.UNSET
422+
&& maximumNumberOfLines != 0
422423
&& layout.getLineCount() > maximumNumberOfLines)
423424
|| (heightYogaMeasureMode != YogaMeasureMode.UNDEFINED
424425
&& layout.getHeight() > height))) {

0 commit comments

Comments
 (0)