Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(RN Patch) TextLayout: take full width if text wrapped #53388

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java
index 2921f84..93da34c 100644
--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java
+++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java
@@ -579,6 +579,10 @@ public class TextLayoutManager {
for (int lineIndex = 0; lineIndex < calculatedLineCount; lineIndex++) {
boolean endsWithNewLine =
text.length() > 0 && text.charAt(layout.getLineEnd(lineIndex) - 1) == '\n';
+ if (!endsWithNewLine && lineIndex + 1 < layout.getLineCount()) {
+ calculatedWidth = width;
+ break;
+ }
float lineWidth =
endsWithNewLine ? layout.getLineMax(lineIndex) : layout.getLineWidth(lineIndex);
if (lineWidth > calculatedWidth) {
diff --git a/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm b/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm
index b4a7033..499e12e 100644
--- a/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm
+++ b/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm
@@ -285,8 +285,33 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(EllipsizeMode ellipsi
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
[layoutManager ensureLayoutForTextContainer:textContainer];

+ NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
+ __block BOOL textDidWrap = NO;
+ [layoutManager
+ enumerateLineFragmentsForGlyphRange:glyphRange
+ usingBlock:^(
+ CGRect overallRect,
+ CGRect usedRect,
+ NSTextContainer *_Nonnull usedTextContainer,
+ NSRange lineGlyphRange,
+ BOOL *_Nonnull stop) {
+ NSRange range = [layoutManager characterRangeForGlyphRange:lineGlyphRange
+ actualGlyphRange:nil];
+ NSUInteger lastCharacterIndex = range.location + range.length - 1;
+ BOOL endsWithNewLine =
+ [textStorage.string characterAtIndex:lastCharacterIndex] == '\n';
+ if (!endsWithNewLine && textStorage.string.length > lastCharacterIndex + 1) {
+ textDidWrap = YES;
+ *stop = YES;
+ }
+ }];
+
CGSize size = [layoutManager usedRectForTextContainer:textContainer].size;

+ if (textDidWrap) {
+ size.width = textContainer.size.width;
+ }
+
size = (CGSize){RCTCeilPixelValue(size.width), RCTCeilPixelValue(size.height)};

__block auto attachments = TextMeasurement::Attachments{};
Loading