Skip to content

Commit

Permalink
refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
hughkli committed Mar 3, 2024
1 parent 2f46182 commit 6f6bb7a
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<UITouch>, 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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions LookinDemo/OC_Pod/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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 `../../`)
Expand All @@ -11,7 +11,7 @@ EXTERNAL SOURCES:
:path: "../../"

SPEC CHECKSUMS:
LookinServer: 00c7588043ed8e7ab64ce55b9fb747e51371ad06
LookinServer: de929b55f8fa2e241c18c39af3f900eaa9166389

PODFILE CHECKSUM: c1b5f203c9e81bcbf3888ba95a03c31e2435a4f7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "LKS_ConnectionManager.h"
#import "LookinServerDefines.h"
#import "LKS_CustomAttrGroupsMaker.h"
#import "LKS_HierarchyDisplayItemsMaker.h"

@interface LKS_HierarchyDetailsHandler ()

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions Src/Main/Server/Others/LKS_HierarchyDisplayItemsMaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
/// @param saveCustomSetter 是否要读取并保存用户给 attribute 配置的 custom setter
+ (NSArray<LookinDisplayItem *> *)itemsWithScreenshots:(BOOL)hasScreenshots attrList:(BOOL)hasAttrList lowImageQuality:(BOOL)lowQuality readCustomInfo:(BOOL)readCustomInfo saveCustomSetter:(BOOL)saveCustomSetter;

/// 把 layer 的 sublayers 转换为 displayItem 数组并返回
+ (NSArray<LookinDisplayItem *> *)subitemsOfLayer:(CALayer *)layer;

@end

#endif /* SHOULD_COMPILE_LOOKIN_SERVER */
24 changes: 24 additions & 0 deletions Src/Main/Server/Others/LKS_HierarchyDisplayItemsMaker.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ + (LookinDisplayItem *)_displayItemWithLayer:(CALayer *)layer screenshots:(BOOL)
return item;
}

+ (NSArray<LookinDisplayItem *> *)subitemsOfLayer:(CALayer *)layer {
if (!layer || layer.sublayers.count == 0) {
return @[];
}
[[LKS_TraceManager sharedInstance] reload];

NSMutableArray<LookinDisplayItem *> *resultSubitems = [NSMutableArray array];

NSArray<CALayer *> *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<LookinDisplayItem *> *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];
}
Expand Down
5 changes: 5 additions & 0 deletions Src/Main/Shared/LookinDisplayItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ - (void)setHighlightedSearchString:(NSString *)highlightedSearchString {
return array;
}

//- (void)dealloc
//{
// NSLog(@"moss dealloc -%@", self);
//}

@end

#endif /* SHOULD_COMPILE_LOOKIN_SERVER */
6 changes: 6 additions & 0 deletions Src/Main/Shared/LookinDisplayItemDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "LookinDefines.h"

@class LookinAttributesGroup;
@class LookinDisplayItem;

@interface LookinDisplayItemDetail : NSObject <NSSecureCoding>

Expand All @@ -35,6 +36,11 @@
@property(nonatomic, copy) NSArray<LookinAttributesGroup *> *attributesGroupList;
@property(nonatomic, copy) NSArray<LookinAttributesGroup *> *customAttrGroupList;

/// 注意 nil 和空数组的区别:nil 表示该属性无意义,空数组表示 subviews 为空
/// Client 1.0.7 & Server 1.2.7 开始支持该属性
/// 默认为 nil
@property(nonatomic, copy) NSArray<LookinDisplayItem *> *subitems;

/// 当 Server 找不到 task 对应的图层时,会返回一个特殊的 LookinDisplayItemDetail 对象,这个对象会被设置 displayItemOid 和 failureCode,其中 failureCode 会被置为 -1
/// Client 1.0.7 & Server 1.2.7 开始支持该属性
/// 默认为 0
Expand Down
8 changes: 8 additions & 0 deletions Src/Main/Shared/LookinDisplayItemDetail.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down
9 changes: 7 additions & 2 deletions Src/Main/Shared/LookinStaticAsyncUpdateTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef NS_ENUM(NSInteger, LookinDetailUpdateTaskAttrRequest) {
LookinDetailUpdateTaskAttrRequest_NotNeed
};

/// 如果两个 Task 对象的 oid 和 taskType 均相同,则二者 equal
/// 业务重写了 isEqual
@interface LookinStaticAsyncUpdateTask : NSObject <NSSecureCoding>

@property(nonatomic, assign) unsigned long oid;
Expand All @@ -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;
Expand Down
23 changes: 17 additions & 6 deletions Src/Main/Shared/LookinStaticAsyncUpdateTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}

}
Expand All @@ -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 {
Expand All @@ -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;
Expand Down

0 comments on commit 6f6bb7a

Please sign in to comment.