94 lines
2.6 KiB
Objective-C
94 lines
2.6 KiB
Objective-C
//
|
||
// YMMessageInfoModel.m
|
||
// YUMI
|
||
//
|
||
// Created by YUMI on 2022/10/21.
|
||
//
|
||
|
||
#import "XPMessageInfoModel.h"
|
||
#import "XPRoomMessageConstant.h"
|
||
|
||
|
||
|
||
@implementation XPMessageInfoModel
|
||
|
||
- (instancetype)init {
|
||
if ([super init]) {
|
||
self.contentLeftMargin = 12;
|
||
self.contentRightMargin = 0;
|
||
self.contentTopMargin = 10;
|
||
self.contentBottomMargin = 10;
|
||
self.cellBottomMargin = 6;
|
||
self.isUpdateContentFrame = NO;
|
||
self.isHiddenBubble = NO;
|
||
}
|
||
return self;
|
||
}
|
||
|
||
- (void)setContent:(NSAttributedString *)content {
|
||
_content = content;
|
||
|
||
if (self.first == 9 && self.second == 91) {
|
||
self.rowHeight = 100;
|
||
return;
|
||
}
|
||
|
||
if (self.isBoom) {
|
||
self.rowHeight = kGetScaleWidth(60)+6+6+20;
|
||
return;
|
||
}
|
||
|
||
// 减去 contentLabel 的左右边距 (UIEdgeInsetsMake(4, 12, 4, 12) 中的左右各12px)
|
||
CGFloat width = kRoomMessageMaxWidth - 24;
|
||
if (self.isBoom) {
|
||
width = kRoomMessageMaxWidth - 24 - kGetScaleWidth(60);
|
||
}
|
||
|
||
YYTextContainer *container = [YYTextContainer containerWithSize:CGSizeMake(width, CGFLOAT_MAX)];
|
||
container.maximumNumberOfRows = 0;
|
||
|
||
// 根据文本方向配置容器
|
||
if (isMSRTL()) {
|
||
container.truncationType = YYTextTruncationTypeStart;
|
||
} else {
|
||
container.truncationType = YYTextTruncationTypeEnd;
|
||
}
|
||
|
||
container.insets = UIEdgeInsetsMake(self.contentTopMargin, self.contentLeftMargin, self.contentBottomMargin, self.contentLeftMargin);
|
||
YYTextLayout *textLayout = [YYTextLayout layoutWithContainer:container text:content];
|
||
|
||
CGSize textSize = textLayout.textBoundingRect.size;
|
||
self.textWidth = textSize.width;
|
||
self.rowHeight = textSize.height;
|
||
|
||
// if ([NSString isEmpty:self.bubbleImageUrl]) {
|
||
self.rowHeight =
|
||
ceil(textSize.height) +
|
||
self.cellBottomMargin +
|
||
self.contentTopMargin;
|
||
// (isMSRTL() ? self.contentTopMargin : (self.isBoom ? 20 : 8));
|
||
|
||
// } else {
|
||
// self.rowHeight =
|
||
// ceil(textSize.height) +
|
||
// (isMSRTL() ? self.contentTopMargin : (self.isBoom ? 20 : 8)) +
|
||
//// self.contentBottomMargin +
|
||
// self.cellBottomMargin;
|
||
// }
|
||
self.rowHeight += 10;
|
||
self.rowHeight += (self.isBoom ? 20 : 0);
|
||
// 移除额外的阿拉伯文本高度调整,YYTextLayout 已能正确处理 RTL 文本
|
||
}
|
||
|
||
- (BOOL)isStringContainArabic:(NSString *)string {
|
||
for (NSUInteger i = 0; i < string.length; i++) {
|
||
unichar c = [string characterAtIndex:i];
|
||
if (c >= 0x0600 && c <= 0x06FF) {
|
||
return YES;
|
||
}
|
||
}
|
||
return NO;
|
||
}
|
||
|
||
@end
|