-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53388 from s77rt/measureText-full-width-if-wraps
(RN Patch) TextLayout: take full width if text wrapped
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
patches/react-native+0.75.2+024+measureText-full-width-if-wraps.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}; |