From 6f6bb7a8e929c59b84ae658fcfc61e1d4b6810b0 Mon Sep 17 00:00:00 2001 From: "likai.123" <471633877@qq.com> Date: Sun, 3 Mar 2024 23:53:23 +0800 Subject: [PATCH] refresh --- .../LookinCustomInfoDemo/ViewController.swift | 56 ++++++++++++++++--- LookinDemo/OC_Pod/Podfile.lock | 8 +-- .../LKS_HierarchyDetailsHandler.m | 7 ++- .../Others/LKS_HierarchyDisplayItemsMaker.h | 3 + .../Others/LKS_HierarchyDisplayItemsMaker.m | 24 ++++++++ Src/Main/Shared/LookinDisplayItem.m | 5 ++ Src/Main/Shared/LookinDisplayItemDetail.h | 6 ++ Src/Main/Shared/LookinDisplayItemDetail.m | 8 +++ Src/Main/Shared/LookinStaticAsyncUpdateTask.h | 9 ++- Src/Main/Shared/LookinStaticAsyncUpdateTask.m | 23 ++++++-- 10 files changed, 127 insertions(+), 22 deletions(-) diff --git a/LookinDemo/LookinCustomInfoDemo/LookinCustomInfoDemo/ViewController.swift b/LookinDemo/LookinCustomInfoDemo/LookinCustomInfoDemo/ViewController.swift index 569b503..7bf3734 100644 --- a/LookinDemo/LookinCustomInfoDemo/LookinCustomInfoDemo/ViewController.swift +++ b/LookinDemo/LookinCustomInfoDemo/LookinCustomInfoDemo/ViewController.swift @@ -20,34 +20,72 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - label.font = UIFont.systemFont(ofSize: 12) + label.text = "\(Date().timeIntervalSince1970)" + label.font = UIFont.systemFont(ofSize: 20) + label.sizeToFit() view.addSubview(label) - + viewModel0.viewModelTargetView = catView viewModel1.viewModelTargetView = birdView - + dogLayer.backgroundColor = UIColor.blue.cgColor view.layer.addSublayer(dogLayer) dogLayer.frame = CGRect(x: 20, y: 20, width: 100, height: 100) - + catView.backgroundColor = UIColor.green view.addSubview(catView) catView.frame = CGRect(x: 20, y: 200, width: 100, height: 100) - + birdView.backgroundColor = UIColor.blue view.addSubview(birdView) birdView.frame = CGRect(x: 20, y: 400, width: 100, height: 100) - + horseLayer.backgroundColor = UIColor.orange.cgColor view.layer.addSublayer(horseLayer) horseLayer.frame = CGRect(x: 20, y: 600, width: 100, height: 100) - + getLookinVersion() - // addManyViews() +// let v2 = UIView() +// v2.frame = CGRect(x: 50, y: 50, width: 50, height: 50) +// v2.backgroundColor = .red +// view.addSubview(v2) + +// addManyViews() // addNestedViews(containerView: view, level: 0) + +// refreshView() } + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + super.touchesBegan(touches, with: event) + if label.superview == nil { + view.addSubview(label) + } else { + label.removeFromSuperview() + } + } + +// private func refreshView() { +//// let v: UILabel +// guard let v = view.viewWithTag(899) as? UILabel else { +// return +// // oldView.removeFromSuperview() +// } +// +//// let v = UILabel() +// v.text = "\(Date().timeIntervalSince1970)" +// +// v.alpha = CGFloat.random(in: 0.3...1.0) +// v.font = UIFont.systemFont(ofSize: CGFloat.random(in: 14...35)) +// v.frame = CGRect(x: CGFloat(arc4random_uniform(100)) + 1, y: CGFloat(arc4random_uniform(500)) + 1, width: 0, height: 0) +// v.sizeToFit() +// +// DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { [weak self] in +// self?.refreshView() +// } +// } + private func getLookinVersion() { // NSMutableDictionary 是引用传递,而 Swift 原生字典是值传递,因此这里只能用 NSMutableDictionary // NSMutableDictionary is passed by reference, while Swift's native dictionary is passed by value, so here we can only use NSMutableDictionary. @@ -82,7 +120,7 @@ class ViewController: UIViewController { containerView.addSubview(v) addNestedViews(containerView: v, level: level + 1) - for i in 0..<20 { + for _ in 0..<20 { let label = UILabel(frame: containerView.bounds) label.text = "fdjsoijfoisdjfioasdjiopfjsdaoijfoipsdjopifjasoipdjfoiapsjdopifjasdoipjfipjewijf9-wejf9ew8f9sd-fjdsai9jf-9adsf9ewf-9aw-f9js9-djf-9wejf-8jwe9-fae-9ejf-9sd-9fjsd-jf9-wejf-9jwe-" label.textColor = .blue diff --git a/LookinDemo/OC_Pod/Podfile.lock b/LookinDemo/OC_Pod/Podfile.lock index a5f4f6e..53bfdf7 100644 --- a/LookinDemo/OC_Pod/Podfile.lock +++ b/LookinDemo/OC_Pod/Podfile.lock @@ -1,7 +1,7 @@ PODS: - - LookinServer (1.2.4): - - LookinServer/Core (= 1.2.4) - - LookinServer/Core (1.2.4) + - LookinServer (1.2.6): + - LookinServer/Core (= 1.2.6) + - LookinServer/Core (1.2.6) DEPENDENCIES: - LookinServer (from `../../`) @@ -11,7 +11,7 @@ EXTERNAL SOURCES: :path: "../../" SPEC CHECKSUMS: - LookinServer: 00c7588043ed8e7ab64ce55b9fb747e51371ad06 + LookinServer: de929b55f8fa2e241c18c39af3f900eaa9166389 PODFILE CHECKSUM: c1b5f203c9e81bcbf3888ba95a03c31e2435a4f7 diff --git a/Src/Main/Server/Connection/RequestHandler/LKS_HierarchyDetailsHandler.m b/Src/Main/Server/Connection/RequestHandler/LKS_HierarchyDetailsHandler.m index b63b199..28999f9 100644 --- a/Src/Main/Server/Connection/RequestHandler/LKS_HierarchyDetailsHandler.m +++ b/Src/Main/Server/Connection/RequestHandler/LKS_HierarchyDetailsHandler.m @@ -15,6 +15,7 @@ #import "LKS_ConnectionManager.h" #import "LookinServerDefines.h" #import "LKS_CustomAttrGroupsMaker.h" +#import "LKS_HierarchyDisplayItemsMaker.h" @interface LKS_HierarchyDetailsHandler () @@ -103,13 +104,17 @@ - (void)_dequeueAndHandlePackage { [self.attrGroupsSyncedOids addObject:@(task.oid)]; } - if (task.needBasisInfo) { + if (task.needBasisVisualInfo) { itemDetail.frameValue = [NSValue valueWithCGRect:layer.frame]; itemDetail.boundsValue = [NSValue valueWithCGRect:layer.bounds]; itemDetail.hiddenValue = [NSNumber numberWithBool:layer.isHidden]; itemDetail.alphaValue = @(layer.opacity); } + if (task.needSubitems) { + itemDetail.subitems = [LKS_HierarchyDisplayItemsMaker subitemsOfLayer:layer]; + } + return itemDetail; }]; self.progressBlock(details); diff --git a/Src/Main/Server/Others/LKS_HierarchyDisplayItemsMaker.h b/Src/Main/Server/Others/LKS_HierarchyDisplayItemsMaker.h index 298ab5c..6e9bbe0 100644 --- a/Src/Main/Server/Others/LKS_HierarchyDisplayItemsMaker.h +++ b/Src/Main/Server/Others/LKS_HierarchyDisplayItemsMaker.h @@ -23,6 +23,9 @@ /// @param saveCustomSetter 是否要读取并保存用户给 attribute 配置的 custom setter + (NSArray *)itemsWithScreenshots:(BOOL)hasScreenshots attrList:(BOOL)hasAttrList lowImageQuality:(BOOL)lowQuality readCustomInfo:(BOOL)readCustomInfo saveCustomSetter:(BOOL)saveCustomSetter; +/// 把 layer 的 sublayers 转换为 displayItem 数组并返回 ++ (NSArray *)subitemsOfLayer:(CALayer *)layer; + @end #endif /* SHOULD_COMPILE_LOOKIN_SERVER */ diff --git a/Src/Main/Server/Others/LKS_HierarchyDisplayItemsMaker.m b/Src/Main/Server/Others/LKS_HierarchyDisplayItemsMaker.m index 7780977..93f5960 100644 --- a/Src/Main/Server/Others/LKS_HierarchyDisplayItemsMaker.m +++ b/Src/Main/Server/Others/LKS_HierarchyDisplayItemsMaker.m @@ -116,6 +116,30 @@ + (LookinDisplayItem *)_displayItemWithLayer:(CALayer *)layer screenshots:(BOOL) return item; } ++ (NSArray *)subitemsOfLayer:(CALayer *)layer { + if (!layer || layer.sublayers.count == 0) { + return @[]; + } + [[LKS_TraceManager sharedInstance] reload]; + + NSMutableArray *resultSubitems = [NSMutableArray array]; + + NSArray *sublayers = [layer.sublayers copy]; + [sublayers enumerateObjectsUsingBlock:^(__kindof CALayer * _Nonnull sublayer, NSUInteger idx, BOOL * _Nonnull stop) { + LookinDisplayItem *sublayer_item = [self _displayItemWithLayer:sublayer screenshots:NO attrList:NO lowImageQuality:NO readCustomInfo:YES saveCustomSetter:YES]; + if (sublayer_item) { + [resultSubitems addObject:sublayer_item]; + } + }]; + + NSArray *customSubitems = [[[LKS_CustomDisplayItemsMaker alloc] initWithLayer:layer saveAttrSetter:YES] make]; + if (customSubitems.count > 0) { + [resultSubitems addObjectsFromArray:customSubitems]; + } + + return resultSubitems; +} + + (BOOL)validateFrame:(CGRect)frame { return !CGRectIsNull(frame) && !CGRectIsInfinite(frame) && ![self cgRectIsNaN:frame] && ![self cgRectIsInf:frame] && ![self cgRectIsUnreasonable:frame]; } diff --git a/Src/Main/Shared/LookinDisplayItem.m b/Src/Main/Shared/LookinDisplayItem.m index 66baf03..82ef8d9 100644 --- a/Src/Main/Shared/LookinDisplayItem.m +++ b/Src/Main/Shared/LookinDisplayItem.m @@ -440,6 +440,11 @@ - (void)setHighlightedSearchString:(NSString *)highlightedSearchString { return array; } +//- (void)dealloc +//{ +// NSLog(@"moss dealloc -%@", self); +//} + @end #endif /* SHOULD_COMPILE_LOOKIN_SERVER */ diff --git a/Src/Main/Shared/LookinDisplayItemDetail.h b/Src/Main/Shared/LookinDisplayItemDetail.h index 8c244e3..adb60c3 100644 --- a/Src/Main/Shared/LookinDisplayItemDetail.h +++ b/Src/Main/Shared/LookinDisplayItemDetail.h @@ -11,6 +11,7 @@ #import "LookinDefines.h" @class LookinAttributesGroup; +@class LookinDisplayItem; @interface LookinDisplayItemDetail : NSObject @@ -35,6 +36,11 @@ @property(nonatomic, copy) NSArray *attributesGroupList; @property(nonatomic, copy) NSArray *customAttrGroupList; +/// 注意 nil 和空数组的区别:nil 表示该属性无意义,空数组表示 subviews 为空 +/// Client 1.0.7 & Server 1.2.7 开始支持该属性 +/// 默认为 nil +@property(nonatomic, copy) NSArray *subitems; + /// 当 Server 找不到 task 对应的图层时,会返回一个特殊的 LookinDisplayItemDetail 对象,这个对象会被设置 displayItemOid 和 failureCode,其中 failureCode 会被置为 -1 /// Client 1.0.7 & Server 1.2.7 开始支持该属性 /// 默认为 0 diff --git a/Src/Main/Shared/LookinDisplayItemDetail.m b/Src/Main/Shared/LookinDisplayItemDetail.m index 80d00d4..195c03c 100644 --- a/Src/Main/Shared/LookinDisplayItemDetail.m +++ b/Src/Main/Shared/LookinDisplayItemDetail.m @@ -30,6 +30,9 @@ - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:self.customDisplayTitle forKey:@"customDisplayTitle"]; [aCoder encodeObject:self.danceUISource forKey:@"danceUISource"]; [aCoder encodeInteger:self.failureCode forKey:@"failureCode"]; + if (self.subitems) { + [aCoder encodeObject:self.subitems forKey:@"subitems"]; + } } - (instancetype)initWithCoder:(NSCoder *)aDecoder { @@ -45,11 +48,16 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder { self.customAttrGroupList = [aDecoder decodeObjectForKey:@"customAttrGroupList"]; self.customDisplayTitle = [aDecoder decodeObjectForKey:@"customDisplayTitle"]; self.danceUISource = [aDecoder decodeObjectForKey:@"danceUISource"]; + if ([aDecoder containsValueForKey:@"failureCode"]) { self.failureCode = [aDecoder decodeIntegerForKey:@"failureCode"]; } else { self.failureCode = 0; } + + if ([aDecoder containsValueForKey:@"subitems"]) { + self.subitems = [aDecoder decodeObjectForKey:@"subitems"]; + } } return self; } diff --git a/Src/Main/Shared/LookinStaticAsyncUpdateTask.h b/Src/Main/Shared/LookinStaticAsyncUpdateTask.h index 21eba86..85e1925 100644 --- a/Src/Main/Shared/LookinStaticAsyncUpdateTask.h +++ b/Src/Main/Shared/LookinStaticAsyncUpdateTask.h @@ -28,7 +28,7 @@ typedef NS_ENUM(NSInteger, LookinDetailUpdateTaskAttrRequest) { LookinDetailUpdateTaskAttrRequest_NotNeed }; -/// 如果两个 Task 对象的 oid 和 taskType 均相同,则二者 equal +/// 业务重写了 isEqual @interface LookinStaticAsyncUpdateTask : NSObject @property(nonatomic, assign) unsigned long oid; @@ -42,7 +42,12 @@ typedef NS_ENUM(NSInteger, LookinDetailUpdateTaskAttrRequest) { /// 如果置为 YES,则 server 侧会返回这些基础信息:frameValue, boundsValue, hiddenValue, alphaValue /// 默认为 NO /// Client 1.0.7 & Server 1.2.7 开始支持这个参数 -@property(nonatomic, assign) BOOL needBasisInfo; +@property(nonatomic, assign) BOOL needBasisVisualInfo; + +/// 如果置为 YES,则 server 侧会返回 subitems +/// 默认为 NO +/// Client 1.0.7 & Server 1.2.7 开始支持这个参数 +@property(nonatomic, assign) BOOL needSubitems; /// Client 1.0.4 开始加入这个参数 @property(nonatomic, copy) NSString *clientReadableVersion; diff --git a/Src/Main/Shared/LookinStaticAsyncUpdateTask.m b/Src/Main/Shared/LookinStaticAsyncUpdateTask.m index ca6b397..aef73a1 100644 --- a/Src/Main/Shared/LookinStaticAsyncUpdateTask.m +++ b/Src/Main/Shared/LookinStaticAsyncUpdateTask.m @@ -19,7 +19,8 @@ - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeInteger:self.taskType forKey:@"taskType"]; [aCoder encodeObject:self.clientReadableVersion forKey:@"clientReadableVersion"]; [aCoder encodeInteger:self.attrRequest forKey:@"attrRequest"]; - [aCoder encodeBool:self.needBasisInfo forKey:@"needBasisInfo"]; + [aCoder encodeBool:self.needBasisVisualInfo forKey:@"needBasisVisualInfo"]; + [aCoder encodeBool:self.needSubitems forKey:@"needSubitems"]; } - (instancetype)initWithCoder:(NSCoder *)aDecoder { @@ -38,10 +39,16 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder { self.attrRequest = LookinDetailUpdateTaskAttrRequest_Automatic; } - if ([aDecoder containsValueForKey:@"needBasisInfo"]) { - self.needBasisInfo = [aDecoder decodeBoolForKey:@"needBasisInfo"]; + if ([aDecoder containsValueForKey:@"needBasisVisualInfo"]) { + self.needBasisVisualInfo = [aDecoder decodeBoolForKey:@"needBasisVisualInfo"]; } else { - self.needBasisInfo = NO; + self.needBasisVisualInfo = NO; + } + + if ([aDecoder containsValueForKey:@"needSubitems"]) { + self.needSubitems = [aDecoder decodeBoolForKey:@"needSubitems"]; + } else { + self.needSubitems = NO; } } @@ -53,7 +60,7 @@ + (BOOL)supportsSecureCoding { } - (NSUInteger)hash { - return self.oid ^ self.taskType; + return self.oid ^ self.taskType ^ self.attrRequest ^ self.needBasisVisualInfo ^ self.needSubitems; } - (BOOL)isEqual:(id)object { @@ -64,7 +71,11 @@ - (BOOL)isEqual:(id)object { return NO; } LookinStaticAsyncUpdateTask *targetTask = object; - if (self.oid == targetTask.oid && self.taskType == targetTask.taskType) { + if (self.oid == targetTask.oid + && self.taskType == targetTask.taskType + && self.attrRequest == targetTask.attrRequest + && self.needBasisVisualInfo == targetTask.needBasisVisualInfo + && self.needSubitems == targetTask.needSubitems) { return YES; } return NO;