Commit c931fa8
Fix text clipping on Android 15+ due to useBoundsForWidth change (#54721)
Summary:
Android 15 (API 35) changed TextView's default behavior to use visual glyph bounds for width calculation (useBoundsForWidth=true). This causes text clipping for italic fonts and other typefaces where glyphs extend beyond their advance width:
https://developer.android.com/about/versions/15/behavior-changes-15
This PR uses a two-pass layout approach on Android 15+:
1. Create an unconstrained layout with setUseBoundsForWidth(true) to measure the actual visual bounds width
2. Create the final layout using the visual bounds width as layoutWidth
This ensures the container is sized correctly to accommodate the full visual extent of the text, preventing clipping while maintaining backwards compatibility with earlier Android versions.
Performance impact:
- On Android 14 and below: No change
- On Android 15+: Creates two StaticLayout instances instead of one for text with unconstrained or AT_MOST width. This overhead is mitigated by React Native's text measurement caching in the C++ layer, which avoids redundant measurements.
Text with EXACTLY width mode is unaffected as it only requires a single layout pass.
Closes #53286
Thanks a lot to intergalacticspacehighway for finding the root cause and creating a proof of concept fix.
## Changelog:
[ANDROID] [FIXED] - Fix text clipping on Android 15+ due to useBoundsForWidth change
Pull Request resolved: #54721
Test Plan:
Tested on RNTester + Android 16 on physical device:
| before | after |
| -- |
| {F1983971719} | {F1983971720} |
Also tested on the reproducer provided by #53286
| before | after |
| -- |
| {F1983971723} | {F1983971718} |
Reviewed By: javache
Differential Revision: D88001642
Pulled By: cortinico
fbshipit-source-id: 4bc20ef6da47bd4141f6b19fcc3e93ea7f0c343c1 parent f2fabd1 commit c931fa8
2 files changed
Lines changed: 89 additions & 4 deletions
File tree
- packages
- react-native/ReactAndroid/src/main/java/com/facebook/react/views/text
- rn-tester/js/examples/Text
Lines changed: 85 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
620 | 620 | | |
621 | 621 | | |
622 | 622 | | |
623 | | - | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
624 | 672 | | |
625 | 673 | | |
626 | 674 | | |
627 | | - | |
628 | | - | |
629 | | - | |
| 675 | + | |
| 676 | + | |
630 | 677 | | |
631 | 678 | | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
632 | 706 | | |
633 | 707 | | |
634 | 708 | | |
| |||
649 | 723 | | |
650 | 724 | | |
651 | 725 | | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
652 | 733 | | |
653 | 734 | | |
654 | 735 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1408 | 1408 | | |
1409 | 1409 | | |
1410 | 1410 | | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
1411 | 1415 | | |
1412 | 1416 | | |
1413 | 1417 | | |
| |||
0 commit comments