Skip to content

Commit

Permalink
Revert "Fixes /issues/6441 - Incorrect timeline item text height calc…
Browse files Browse the repository at this point in the history
…ulation (#6679)"

This reverts commit 405c2d8.
  • Loading branch information
stefanceriu committed Nov 8, 2022
1 parent f0b3395 commit f3723a8
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -518,39 +518,46 @@ - (CGFloat)rawTextHeight: (NSAttributedString*)attributedText

- (CGSize)textContentSize:(NSAttributedString*)attributedText removeVerticalInset:(BOOL)removeVerticalInset
{
if (attributedText.length == 0) {
return CGSizeZero;
}

// Grab the default textContainer insets and lineFragmentPadding from a dummy text view.
// This has no business being here but the refactoring effort would be too great (sceriu 05.09.2022)
static UITextView* measurementTextView = nil;
if (!measurementTextView)
{
measurementTextView = [[UITextView alloc] init];
}

CGFloat verticalInset = measurementTextView.textContainerInset.top + measurementTextView.textContainerInset.bottom;
CGFloat horizontalInset = measurementTextView.textContainer.lineFragmentPadding * 2;
static UITextView* measurementTextViewWithoutInset = nil;

CGSize size = [attributedText boundingRectWithSize:CGSizeMake(_maxTextViewWidth - horizontalInset, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
context:nil].size;

//In iOS 7 and later, this method returns fractional sizes (in the size component of the returned rectangle);
// to use a returned size to size views, you must use raise its value to the nearest higher integer using the
// [ceil](https://developer.apple.com/documentation/kernel/1557272-ceil?changes=latest_major) function.
size.width = ceil(size.width);
size.height = ceil(size.height);
if (attributedText.length)
{
if (!measurementTextView)
{
measurementTextView = [[UITextView alloc] init];

measurementTextViewWithoutInset = [[UITextView alloc] init];
// Remove the container inset: this operation impacts only the vertical margin.
// Note: consider textContainer.lineFragmentPadding to remove horizontal margin
measurementTextViewWithoutInset.textContainerInset = UIEdgeInsetsZero;
}

// Select the right text view for measurement
UITextView *selectedTextView = (removeVerticalInset ? measurementTextViewWithoutInset : measurementTextView);

selectedTextView.frame = CGRectMake(0, 0, _maxTextViewWidth, 0);
selectedTextView.attributedText = attributedText;

CGSize size = [selectedTextView sizeThatFits:selectedTextView.frame.size];

// Manage the case where a string attribute has a single paragraph with a left indent
// In this case, [UITextView sizeThatFits] ignores the indent and return the width
// of the text only.
// So, add this indent afterwards
NSRange textRange = NSMakeRange(0, attributedText.length);
NSRange longestEffectiveRange;
NSParagraphStyle *paragraphStyle = [attributedText attribute:NSParagraphStyleAttributeName atIndex:0 longestEffectiveRange:&longestEffectiveRange inRange:textRange];

// The result is expected to contain the textView textContainer's paddings. Add them back if necessary
if (removeVerticalInset == NO) {
size.height += verticalInset;
if (NSEqualRanges(textRange, longestEffectiveRange))
{
size.width = size.width + paragraphStyle.headIndent;
}

return size;
}

size.width += horizontalInset;

return size;
return CGSizeZero;
}

#pragma mark - Properties
Expand Down

0 comments on commit f3723a8

Please sign in to comment.