86 lines
2.4 KiB
Objective-C
86 lines
2.4 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;
|
|
|
|
CGFloat width = kRoomMessageMaxWidth;
|
|
if (self.isBoom) {
|
|
width = kRoomMessageMaxWidth - kGetScaleWidth(60);
|
|
}
|
|
|
|
CGSize size = [content boundingRectWithSize:CGSizeMake(width, 0)
|
|
options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin
|
|
context:nil].size;
|
|
|
|
if (self.first == 9 && self.second == 91) {
|
|
self.rowHeight = 100;
|
|
return;
|
|
}
|
|
|
|
YYTextContainer *container = [YYTextContainer containerWithSize:CGSizeMake(size.width, CGFLOAT_MAX)];
|
|
container.maximumNumberOfRows = 0;
|
|
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;
|
|
|
|
if ([NSString isEmpty:self.bubbleImageUrl]) {
|
|
self.rowHeight =
|
|
ceil(textSize.height) +
|
|
self.cellBottomMargin +
|
|
(isMSRTL() ? self.contentTopMargin : (self.isBoom ? 20 : 8));
|
|
} else {
|
|
self.rowHeight =
|
|
ceil(textSize.height) +
|
|
(isMSRTL() ? self.contentTopMargin : (self.isBoom ? 20 : 8)) +
|
|
// self.contentBottomMargin +
|
|
self.cellBottomMargin;
|
|
}
|
|
// if ([self.cellKey isEqualToString:@"ChatMessage"]) {
|
|
self.rowHeight += 10;
|
|
// }
|
|
self.rowHeight += (self.isBoom ? 20 : 0);
|
|
if ([self isStringContainArabic:content.string]) {
|
|
self.rowHeight += 20;
|
|
}
|
|
}
|
|
|
|
- (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
|