diff --git a/CHANGES.md b/CHANGES.md index 970c9527c..6d0f6fef5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,14 @@ +## Changes in 1.9.5 (2022-09-12) + +🐛 Bugfixes + +- Fix timeline items text height calculation ([#6702](https://github.com/vector-im/element-ios/pull/6702)) + +🚧 In development 🚧 + +- Device manager: Add other sessions section read only in user sessions overview screen. ([#6672](https://github.com/vector-im/element-ios/issues/6672)) + + ## Changes in 1.9.4 (2022-09-09) ✨ Features diff --git a/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleCellData.m b/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleCellData.m index 2cd44566e..8ee0a6190 100644 --- a/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleCellData.m +++ b/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleCellData.m @@ -533,15 +533,7 @@ 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 | NSStringDrawingUsesDeviceMetrics - 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); + CGSize size = [self sizeForAttributedString:attributedText fittingWidth:_maxTextViewWidth - horizontalInset]; // The result is expected to contain the textView textContainer's paddings. Add them back if necessary if (removeVerticalInset == NO) { @@ -553,6 +545,27 @@ return size; } +// https://stackoverflow.com/questions/54497598/nsattributedstring-boundingrect-returns-wrong-height +- (CGSize)sizeForAttributedString:(NSAttributedString *)attributedString fittingWidth:(CGFloat)width +{ + NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:attributedString]; + + CGRect boundingRect = CGRectMake(0.0, 0.0, width, CGFLOAT_MAX); + + NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:boundingRect.size]; + textContainer.lineFragmentPadding = 0; + + NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init]; + [layoutManager addTextContainer: textContainer]; + + [textStorage addLayoutManager:layoutManager]; + [layoutManager glyphRangeForBoundingRect:boundingRect inTextContainer:textContainer]; + + CGRect rect = [layoutManager usedRectForTextContainer:textContainer]; + + return CGRectIntegral(rect).size; +} + #pragma mark - Properties - (MXSession*)mxSession diff --git a/changelog.d/6672.wip b/changelog.d/6672.wip deleted file mode 100644 index c04ba7598..000000000 --- a/changelog.d/6672.wip +++ /dev/null @@ -1 +0,0 @@ -Device manager: Add other sessions section read only in user sessions overview screen. diff --git a/changelog.d/pr-6702.bugfix b/changelog.d/pr-6702.bugfix deleted file mode 100644 index af2b8f154..000000000 --- a/changelog.d/pr-6702.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix timeline items text height calculation \ No newline at end of file