cdts/xdts-ios 3/TreeHole/CYHResetCode/CYH/QMUIKit/QMUIComponents/QMUIAppearance.m

81 lines
3.6 KiB
Mathematica
Raw Normal View History

2023-07-27 09:20:00 +08:00
/**
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2021 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
//
// QMUIAppearance.m
// QMUIKit
//
// Created by MoLice on 2020/3/25.
//
#import "QMUIAppearance.h"
#import "QMUICore.h"
#import "QMUIWeakObjectContainer.h"
@implementation QMUIAppearance
static NSMutableDictionary *appearances;
+ (id)appearanceForClass:(Class)aClass {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (!appearances) {
appearances = NSMutableDictionary.new;
}
});
NSString *className = NSStringFromClass(aClass);
id appearance = appearances[className];
if (!appearance) {
BeginIgnorePerformSelectorLeaksWarning
SEL selector = NSSelectorFromString([NSString stringWithFormat:@"_%@:%@:", @"appearanceForClass", @"withContainerList"]);
appearance = [NSClassFromString(@"_UIAppearance") performSelector:selector withObject:aClass withObject:nil];
appearances[className] = appearance;
EndIgnorePerformSelectorLeaksWarning
}
return appearance;
}
@end
BeginIgnoreClangWarning(-Wincomplete-implementation)
@interface NSObject (QMUIAppearance_Private)
@property(nonatomic, assign) BOOL qmui_applyingAppearance;
+ (instancetype)appearance;
@end
@implementation NSObject (QMUIAppearnace)
QMUISynthesizeBOOLProperty(qmui_applyingAppearance, setQmui_applyingAppearance)
/**
appearance
1.
2. appearance
3. property ClassA UI_APPEARANCE_SELECTOR Class B : Class A property nil appearance property nil
*/
- (void)qmui_applyAppearance {
Class class = self.class;
if ([class respondsToSelector:@selector(appearance)]) {
// -[_UIAppearance _applyInvocationsTo:window:] _appearanceGuideClass UIView UIViewController
SEL appearanceGuideClassSelector = NSSelectorFromString(@"_appearanceGuideClass");
if (!class_respondsToSelector(class, appearanceGuideClassSelector)) {
const char * typeEncoding = method_getTypeEncoding(class_getInstanceMethod(UIView.class, appearanceGuideClassSelector));
class_addMethod(class, appearanceGuideClassSelector, imp_implementationWithBlock(^Class(void) {
return nil;
}), typeEncoding);
}
self.qmui_applyingAppearance = YES;
BeginIgnorePerformSelectorLeaksWarning
SEL selector = NSSelectorFromString([NSString stringWithFormat:@"_%@:%@:", @"applyInvocationsTo", @"window"]);
[NSClassFromString(@"_UIAppearance") performSelector:selector withObject:self withObject:nil];
EndIgnorePerformSelectorLeaksWarning
self.qmui_applyingAppearance = NO;
}
}
@end
EndIgnoreClangWarning