cdts/xdts-ios 3/TreeHole/Code/Features/Chat/UIPatch/UIImage+TUIPatch.m
2023-07-27 09:20:00 +08:00

66 lines
1.8 KiB
Objective-C

//
// UIImage+TUIPatch.m
// Youth
//
// Created by mambaxie on 2022/1/2.
//
#import "UIImage+TUIPatch.h"
#import <JRSwizzle.h>
#import <TUIDarkModel.h>
#import <TUIDefine.h>
@implementation UIImage (TUIPatch)
+ (void)load {
NSError *error;
[self jr_swizzleClassMethod:@selector(d_imageNamed:bundle:) withClassMethod:@selector(patch_d_imageNamed:bundle:) error:&error];
[self jr_swizzleClassMethod:@selector(d_imageWithImageLight:dark:) withClassMethod:@selector(patch_d_imageWithImageLight:dark:) error:&error];
[self jr_swizzleClassMethod:@selector(d_imagePath:) withClassMethod:@selector(patch_d_imagePath:) error:&error];
if (error) {
NSLog(@"patch TUI error: %@", error);
}
}
+ (UIImage *)patch_d_imageWithImageLight:(NSString *)lightImagePath dark:(NSString *)darkImagePath {
UIImage *image = [UIImage imageNamed:darkImagePath.lastPathComponent];
if (image) {
return image;
}
return [self patch_d_imageWithImageLight:lightImagePath dark:darkImagePath];
}
+ (UIImage *)patch_d_imagePath:(NSString *)path {
UIImage *image = ImageNamed(path.lastPathComponent);
if (image) {
return image;
}
return [self patch_d_imagePath:path];
}
+ (UIImage *)patch_d_imageNamed:(NSString *)imageName bundle:(NSString *)bundleName {
UIImage *image = ImageNamed(imageName);
if (image) {
return image;
}
NSString *path = nil;
if ([bundleName isEqualToString:TUIChatBundle]) {
if (image) {
path = imageName;
}
}
if (path) {
UIImage *image = [UIImage d_imageWithImageLight:path dark:[NSString stringWithFormat:@"%@_dark",path]];
if (image) {
return image;
}
}
// 兜底 原始实现
return [self patch_d_imageNamed:imageName bundle:bundleName];
}
@end