新增 emoji 缓存清理功能以确保新的尺寸设置生效,优化表情处理逻辑,支持带场景参数的表情转换。同时,更新相关方法以适应新功能,提升用户体验。

This commit is contained in:
edwinQQQ
2025-08-27 16:35:52 +08:00
parent 4d60296a4d
commit eee967c2e1
9 changed files with 67 additions and 19 deletions

View File

@@ -180,6 +180,9 @@ UIKIT_EXTERN NSString * adImageName;
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
faceManager.emotionArray = array;
// emoji
[QEmotionHelper clearEmojiCache];
#if DEBUG
//
NSLog(@"表情数组加载完成,总数: %lu", (unsigned long)array.count);

View File

@@ -25,7 +25,17 @@
//把 @"[微笑]" 转为 @"😊"
- (NSAttributedString *)obtainAttributedStringByImageKey:(NSString *)imageKey font:(UIFont *)font useCache:(BOOL)useCache;
//imageKey[微笑] fontlabel的Font返回😊 (带场景参数)
//把 @"[微笑]" 转为 @"😊"
- (NSAttributedString *)obtainAttributedStringByImageKey:(NSString *)imageKey font:(UIFont *)font useCache:(BOOL)useCache forMessageBubble:(BOOL)isMessageBubble;
//把 @"害~你好啊[微笑]" 转为 @"害~你好啊😊"
- (NSMutableAttributedString *)attributedStringByText:(NSString *)text font:(UIFont *)font;
//把 @"害~你好啊[微笑]" 转为 @"害~你好啊😊" (带场景参数)
- (NSMutableAttributedString *)attributedStringByText:(NSString *)text font:(UIFont *)font forMessageBubble:(BOOL)isMessageBubble;
// 清理 emoji 缓存,用于尺寸变更后刷新
+ (void)clearEmojiCache;
@end

View File

@@ -46,6 +46,12 @@
return _sharedFaceManager;
}
// emoji
+ (void)clearEmojiCache {
QEmotionHelper *helper = [QEmotionHelper sharedEmotionHelper];
[helper.cacheAttributedDictionary removeAllObjects];
}
#pragma mark - public
//demo
//emotionArrayImage0.5MB
@@ -78,6 +84,11 @@
//String@"害~你好[微笑]", @"害~你好😊"
- (NSMutableAttributedString *)attributedStringByText:(NSString *)text font:(UIFont *)font {
return [self attributedStringByText:text font:font forMessageBubble:NO];
}
//String@"害~你好[微笑]", @"害~你好😊" ()
- (NSMutableAttributedString *)attributedStringByText:(NSString *)text font:(UIFont *)font forMessageBubble:(BOOL)isMessageBubble {
if(text.length == 0){
return [[NSMutableAttributedString alloc] initWithString:@""];;
}
@@ -98,7 +109,7 @@
//ios15NSTextAttachmentViewProvider
useCache = NO;
}
NSAttributedString *imageAttributedString = [self obtainAttributedStringByImageKey:emojiKey font:font useCache:useCache];
NSAttributedString *imageAttributedString = [self obtainAttributedStringByImageKey:emojiKey font:font useCache:useCache forMessageBubble:isMessageBubble];
if (imageAttributedString) {
[intactAttributeString replaceCharactersInRange:result.range withAttributedString:imageAttributedString];
}
@@ -115,6 +126,13 @@
//imageKey[] fontlabelFont😊
// @@"[微笑]", @"😊"
- (NSAttributedString *)obtainAttributedStringByImageKey:(NSString *)imageKey font:(UIFont *)font useCache:(BOOL)useCache {
return [self obtainAttributedStringByImageKey:imageKey font:font useCache:useCache forMessageBubble:NO];
}
//AttributedString ()
//imageKey[] fontlabelFont😊
// @@"[微笑]", @"😊"
- (NSAttributedString *)obtainAttributedStringByImageKey:(NSString *)imageKey font:(UIFont *)font useCache:(BOOL)useCache forMessageBubble:(BOOL)isMessageBubble {
if([self.emojiHantList containsObject:imageKey]){
NSString *getImageKey = [self.emojiHansList xpSafeObjectAtIndex:[self.emojiHantList indexOfObject:imageKey]];
if(getImageKey != nil){
@@ -133,14 +151,17 @@
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.displayText = imageKey;
imageView.image = image;
// emoji
CGFloat emojiSize = isMessageBubble ? font.lineHeight * 2.0 : font.lineHeight; //
if (image) {
CGFloat scale = image.size.width / image.size.height;
imageView.bounds = CGRectMake(0, 0, 20 * scale, 20);
imageView.bounds = CGRectMake(0, 0, emojiSize * scale, emojiSize);
} else {
imageView.bounds = CGRectMake(0, 0, 20, 20);
imageView.bounds = CGRectMake(0, 0, emojiSize, emojiSize);
}
imageView.bounds = CGRectMake(0, 0, font.lineHeight, font.lineHeight);
NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height) alignToFont:font alignment:YYTextVerticalAlignmentCenter];
return attrString;
}
@@ -165,14 +186,17 @@
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.displayText = imageKey;
imageView.image = image;
// emoji
CGFloat emojiSize = isMessageBubble ? font.lineHeight * 2.0 : font.lineHeight; //
if (image) {
CGFloat scale = image.size.width / image.size.height;
imageView.bounds = CGRectMake(0, 0, 20 * scale, 20);
imageView.bounds = CGRectMake(0, 0, emojiSize * scale, emojiSize);
} else {
imageView.bounds = CGRectMake(0, 0, 20, 20);
imageView.bounds = CGRectMake(0, 0, emojiSize, emojiSize);
}
imageView.bounds = CGRectMake(0, 0, font.lineHeight, font.lineHeight);
NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height) alignToFont:font alignment:YYTextVerticalAlignmentCenter];
//[]17 NSAttributedString Dictionary
[_cacheAttributedDictionary setObject:attrString forKey:keyFont];
return result;

View File

@@ -64,7 +64,7 @@
model.message.rawAttachContent];
}
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:[UIFont systemFontOfSize:13]];
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:[UIFont systemFontOfSize:13] forMessageBubble:YES];
_messageText.attributedText = attribute;
}
[_messageText.superview layoutIfNeeded];

View File

@@ -48,7 +48,7 @@
CGSize dstRect = CGSizeMake(width, MAXFLOAT);
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:kFontMedium(14)];
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:kFontMedium(14) forMessageBubble:YES];
if(extModel.iosBubbleUrl.length > 0){
[attribute addAttributes:@{NSForegroundColorAttributeName: UIColorFromRGB(0x333333)} range:[attribute.string rangeOfString:attribute.string]];
}else{

View File

@@ -34,7 +34,7 @@
}
CGSize dstRect = CGSizeMake(CONTENT_WIDTH_MAX - MESSAGE_PADDING * 2, MAXFLOAT);
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:[UIFont systemFontOfSize:13]];
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:[UIFont systemFontOfSize:13] forMessageBubble:YES];
self.textAttribute = attribute;
YYTextContainer *container = [YYTextContainer containerWithSize:dstRect];
container.maximumNumberOfRows = 0;

View File

@@ -266,8 +266,9 @@
if ([[XPSkillCardPlayerManager shareInstance] isInRoomVC]) {
[self.boomEventsQueue addObject:attachment];
[[NSNotificationCenter defaultCenter] postNotificationName:@"UpdateWhenBoomExplosion" object:nil];
[self.bannerEventsQueue addObject:attachment];
}
[self.bannerEventsQueue addObject:attachment];
// [self.bannerEventsQueue addObject:attachment];
[self checkAndStartBoomEvent];
[self checkAndStartBannerEvent];

View File

@@ -140,6 +140,9 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
[[NIMSDK sharedSDK].chatManager removeDelegate:self];
[[NIMSDK sharedSDK].systemNotificationManager removeDelegate:self];
[[NIMSDK sharedSDK].broadcastManager removeDelegate:self];
// 🔧 RoomBoomManager
[[RoomBoomManager sharedManager] removeEventListenerForTarget:self];
}
- (void)viewDidLoad {
@@ -186,10 +189,13 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
[[RoomBoomManager sharedManager] registerBoomBanner:^(id _Nonnull sth) {
dispatch_async(dispatch_get_main_queue(), ^{
[RoomBoomBannerAnimation display:kWindow
with:sth
tapToRoom:YES
complete:^{}];
// 🔧
if ([XPSkillCardPlayerManager shareInstance].isInRoom == YES) {
[RoomBoomBannerAnimation display:kWindow
with:sth
tapToRoom:YES
complete:^{}];
}
});
} target:self];

View File

@@ -13,6 +13,7 @@
#import "BaseNavigationController.h"
#import "FirstRechargeManager.h"
#import "PublicRoomManager.h"
#import "RoomBoomManager.h"
@interface BaseMvpPresenter()
@@ -37,13 +38,16 @@
// 2.
[[PublicRoomManager sharedManager] reset];
// 3. logout
// 3.
[[RoomBoomManager sharedManager] leaveRoom];
// 4. logout
[[AccountInfoStorage instance] saveAccountInfo:nil];
[[AccountInfoStorage instance] saveTicket:nil];
if ([NIMSDK sharedSDK].loginManager.isLogined) {
[[NIMSDK sharedSDK].loginManager logout:nil];
}
// 4.
// 5.
[self tokenInvalid];
// ///
// [[ClientConfig shareConfig] resetHeartBratTimer];