Skip to content

Conversation

athenayao
Copy link

Cherry-picking some fixes for calculating width of ellipsized text to fix
https://app.asana.com/1/236888843494340/project/1199705967702853/task/1210664752040993

athenayao and others added 4 commits September 19, 2025 21:37
This updates the config file for a couple feature flags where we'd only  modified the derived files. This separates out the baseline output of yarn run v1.22.19
$ cd packages/react-native && yarn featureflags --update
$ node ./scripts/featureflags/index.js --update
Done in 1.11s.

so that it's clear what actual new changes are when we add a new feature flag
…cebook#51040)

Summary:
Pull Request resolved: facebook#51040

We were previously only checking for `maxNumberOfLines` of `ReactConstants.UNSET` (-1), but it may also be `0` to signify unset from other checks (wut), and different versions of Android would handle this case of `maxLines={0}` differently.

The resubmission adds an explicit check for zero here as well.

```
      if (ReactNativeFeatureFlags.incorporateMaxLinesDuringAndroidLayout()) {
        if (maxNumberOfLines != ReactConstants.UNSET && maxNumberOfLines != 0) {
          builder.setEllipsize(ellipsizeMode).setMaxLines(maxNumberOfLines);
        }
      }
```

Right now, we fully layout text, then use max lines to determine  a metric to use when calculating size.

Android API 23+ which we fully target allows incorporating ellipsization and maxlines directly into the layout. This will let us directly draw the layout when using maxLines later. This may also let Android optimize line-breaking a bit, when we hit truncation.

Special care is taken not to set this when we are in `adjustsFontSizeToFit` path, so that line count will flow over, signifing overflow.

I think the main user-facing change is that `onTextLayout` events will have measures post-ellipsization.

Changelog:
[Android][Changed] - Incorporate maxLines and ellipsization into text layout

Reviewed By: lenaic, joevilches

Differential Revision: D73953691

fbshipit-source-id: 2e08faab5bb9eda90a126545571bb441ea1ece39
Summary:
Pull Request resolved: facebook#51108

We calculate the width of text to be the full width of the container, if the text overflows the bounds of the container, instead of the wrapped width, to match the behavior on web.

Incorporating line count into layout defeats this logic, since the final layout never overflows. We need to also check to see if we are ellipsized (had overflow) instead.

Changelog:
[Android][Fixed] - Assume full container width when ellipsizing line

Reviewed By: joevilches

Differential Revision: D74204041

fbshipit-source-id: 1c2a7fc50f101bd4c9ed2f979534731992b5310b
@athenayao athenayao changed the title Athena/text rounding cp Cherry-Pick Text Ellipsizing Fixes Sep 23, 2025
@athenayao athenayao merged commit 81838be into 0.78.0-discord Sep 24, 2025
13 of 19 checks passed
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