mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 16:42:44 +02:00
Revert "Fixes vector-im/element-ios/issues/6441 - Incorrect timeline item text height calculation (#6679)"
This reverts commit 405c2d8e324c08c1a40e037aeb3c54e93f30bc9f.
This commit is contained in:
committed by
Stefan Ceriu
parent
5795d80d65
commit
fbab7d717c
@@ -518,39 +518,46 @@
|
||||
|
||||
- (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)
|
||||
static UITextView* measurementTextViewWithoutInset = nil;
|
||||
|
||||
if (attributedText.length)
|
||||
{
|
||||
measurementTextView = [[UITextView alloc] init];
|
||||
}
|
||||
|
||||
CGFloat verticalInset = measurementTextView.textContainerInset.top + measurementTextView.textContainerInset.bottom;
|
||||
CGFloat horizontalInset = measurementTextView.textContainer.lineFragmentPadding * 2;
|
||||
|
||||
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 (!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];
|
||||
|
||||
// The result is expected to contain the textView textContainer's paddings. Add them back if necessary
|
||||
if (removeVerticalInset == NO) {
|
||||
size.height += verticalInset;
|
||||
// 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];
|
||||
|
||||
if (NSEqualRanges(textRange, longestEffectiveRange))
|
||||
{
|
||||
size.width = size.width + paragraphStyle.headIndent;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
size.width += horizontalInset;
|
||||
|
||||
return size;
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
#pragma mark - Properties
|
||||
|
||||
Reference in New Issue
Block a user