LookinDisplayItem.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. #ifdef SHOULD_COMPILE_LOOKIN_SERVER
  2. //
  3. // LookinDisplayItem.m
  4. // qmuidemo
  5. //
  6. // Created by Li Kai on 2018/11/15.
  7. // Copyright © 2018 QMUI Team. All rights reserved.
  8. //
  9. #import "LookinDisplayItem.h"
  10. #import "LookinAttributesGroup.h"
  11. #import "LookinAttributesSection.h"
  12. #import "LookinAttribute.h"
  13. #import "LookinEventHandler.h"
  14. #import "LookinIvarTrace.h"
  15. #import "Color+Lookin.h"
  16. #import "NSArray+Lookin.h"
  17. #import "NSObject+Lookin.h"
  18. #if TARGET_OS_IPHONE
  19. #import "UIColor+LookinServer.h"
  20. #import "UIImage+LookinServer.h"
  21. #elif TARGET_OS_MAC
  22. #endif
  23. @interface LookinDisplayItem ()
  24. @property(nonatomic, assign, readwrite) CGRect frameToRoot;
  25. @property(nonatomic, assign, readwrite) BOOL inNoPreviewHierarchy;
  26. @property(nonatomic, assign) NSInteger indentLevel;
  27. @property(nonatomic, assign, readwrite) BOOL isExpandable;
  28. @property(nonatomic, assign, readwrite) BOOL inHiddenHierarchy;
  29. @property(nonatomic, assign, readwrite) BOOL displayingInHierarchy;
  30. @end
  31. @implementation LookinDisplayItem
  32. #pragma mark - <NSCopying>
  33. - (id)copyWithZone:(NSZone *)zone {
  34. LookinDisplayItem *newDisplayItem = [[LookinDisplayItem allocWithZone:zone] init];
  35. newDisplayItem.subitems = [self.subitems lookin_map:^id(NSUInteger idx, LookinDisplayItem *value) {
  36. return value.copy;
  37. }];
  38. newDisplayItem.isHidden = self.isHidden;
  39. newDisplayItem.alpha = self.alpha;
  40. newDisplayItem.frame = self.frame;
  41. newDisplayItem.bounds = self.bounds;
  42. newDisplayItem.soloScreenshot = self.soloScreenshot;
  43. newDisplayItem.groupScreenshot = self.groupScreenshot;
  44. newDisplayItem.viewObject = self.viewObject.copy;
  45. newDisplayItem.layerObject = self.layerObject.copy;
  46. newDisplayItem.hostViewControllerObject = self.hostViewControllerObject.copy;
  47. newDisplayItem.attributesGroupList = [self.attributesGroupList lookin_map:^id(NSUInteger idx, LookinAttributesGroup *value) {
  48. return value.copy;
  49. }];
  50. newDisplayItem.eventHandlers = [self.eventHandlers lookin_map:^id(NSUInteger idx, LookinEventHandler *value) {
  51. return value.copy;
  52. }];
  53. newDisplayItem.shouldCaptureImage = self.shouldCaptureImage;
  54. newDisplayItem.representedAsKeyWindow = self.representedAsKeyWindow;
  55. [newDisplayItem _updateDisplayingInHierarchyProperty];
  56. return newDisplayItem;
  57. }
  58. #pragma mark - <NSCoding>
  59. - (void)encodeWithCoder:(NSCoder *)aCoder {
  60. [aCoder encodeObject:self.subitems forKey:@"subitems"];
  61. [aCoder encodeBool:self.isHidden forKey:@"hidden"];
  62. [aCoder encodeFloat:self.alpha forKey:@"alpha"];
  63. [aCoder encodeObject:self.viewObject forKey:@"viewObject"];
  64. [aCoder encodeObject:self.layerObject forKey:@"layerObject"];
  65. [aCoder encodeObject:self.hostViewControllerObject forKey:@"hostViewControllerObject"];
  66. [aCoder encodeObject:self.attributesGroupList forKey:@"attributesGroupList"];
  67. [aCoder encodeBool:self.representedAsKeyWindow forKey:@"representedAsKeyWindow"];
  68. [aCoder encodeObject:self.eventHandlers forKey:@"eventHandlers"];
  69. [aCoder encodeBool:self.shouldCaptureImage forKey:@"shouldCaptureImage"];
  70. if (self.screenshotEncodeType == LookinDisplayItemImageEncodeTypeNSData) {
  71. [aCoder encodeObject:[self.soloScreenshot lookin_encodedObjectWithType:LookinCodingValueTypeImage] forKey:@"soloScreenshot"];
  72. [aCoder encodeObject:[self.groupScreenshot lookin_encodedObjectWithType:LookinCodingValueTypeImage] forKey:@"groupScreenshot"];
  73. } else if (self.screenshotEncodeType == LookinDisplayItemImageEncodeTypeImage) {
  74. [aCoder encodeObject:self.soloScreenshot forKey:@"soloScreenshot"];
  75. [aCoder encodeObject:self.groupScreenshot forKey:@"groupScreenshot"];
  76. }
  77. #if TARGET_OS_IPHONE
  78. [aCoder encodeCGRect:self.frame forKey:@"frame"];
  79. [aCoder encodeCGRect:self.bounds forKey:@"bounds"];
  80. [aCoder encodeObject:self.backgroundColor.lks_rgbaComponents forKey:@"backgroundColor"];
  81. #elif TARGET_OS_MAC
  82. [aCoder encodeRect:self.frame forKey:@"frame"];
  83. [aCoder encodeRect:self.bounds forKey:@"bounds"];
  84. [aCoder encodeObject:self.backgroundColor.lookin_rgbaComponents forKey:@"backgroundColor"];
  85. #endif
  86. }
  87. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  88. if (self = [super init]) {
  89. self.subitems = [aDecoder decodeObjectForKey:@"subitems"];
  90. self.isHidden = [aDecoder decodeBoolForKey:@"hidden"];
  91. self.alpha = [aDecoder decodeFloatForKey:@"alpha"];
  92. self.viewObject = [aDecoder decodeObjectForKey:@"viewObject"];
  93. self.layerObject = [aDecoder decodeObjectForKey:@"layerObject"];
  94. self.hostViewControllerObject = [aDecoder decodeObjectForKey:@"hostViewControllerObject"];
  95. self.attributesGroupList = [aDecoder decodeObjectForKey:@"attributesGroupList"];
  96. self.representedAsKeyWindow = [aDecoder decodeBoolForKey:@"representedAsKeyWindow"];
  97. id soloScreenshotObj = [aDecoder decodeObjectForKey:@"soloScreenshot"];
  98. if (soloScreenshotObj) {
  99. if ([soloScreenshotObj isKindOfClass:[NSData class]]) {
  100. self.soloScreenshot = [soloScreenshotObj lookin_decodedObjectWithType:LookinCodingValueTypeImage];
  101. } else if ([soloScreenshotObj isKindOfClass:[LookinImage class]]) {
  102. self.soloScreenshot = soloScreenshotObj;
  103. } else {
  104. NSAssert(NO, @"");
  105. }
  106. }
  107. id groupScreenshotObj = [aDecoder decodeObjectForKey:@"groupScreenshot"];
  108. if (groupScreenshotObj) {
  109. if ([groupScreenshotObj isKindOfClass:[NSData class]]) {
  110. self.groupScreenshot = [groupScreenshotObj lookin_decodedObjectWithType:LookinCodingValueTypeImage];
  111. } else if ([groupScreenshotObj isKindOfClass:[LookinImage class]]) {
  112. self.groupScreenshot = groupScreenshotObj;
  113. } else {
  114. NSAssert(NO, @"");
  115. }
  116. }
  117. self.eventHandlers = [aDecoder decodeObjectForKey:@"eventHandlers"];
  118. /// this property was added in LookinServer 1.1.3
  119. self.shouldCaptureImage = [aDecoder containsValueForKey:@"shouldCaptureImage"] ? [aDecoder decodeBoolForKey:@"shouldCaptureImage"] : YES;
  120. #if TARGET_OS_IPHONE
  121. self.frame = [aDecoder decodeCGRectForKey:@"frame"];
  122. self.bounds = [aDecoder decodeCGRectForKey:@"bounds"];
  123. self.backgroundColor = [UIColor lks_colorFromRGBAComponents:[aDecoder decodeObjectForKey:@"backgroundColor"]];
  124. #elif TARGET_OS_MAC
  125. self.frame = [aDecoder decodeRectForKey:@"frame"];
  126. self.bounds = [aDecoder decodeRectForKey:@"bounds"];
  127. self.backgroundColor = [NSColor lookin_colorFromRGBAComponents:[aDecoder decodeObjectForKey:@"backgroundColor"]];
  128. #endif
  129. [self _updateDisplayingInHierarchyProperty];
  130. }
  131. return self;
  132. }
  133. + (BOOL)supportsSecureCoding {
  134. return YES;
  135. }
  136. - (instancetype)init {
  137. if (self = [super init]) {
  138. /// 在手机端,displayItem 被创建时会调用这个方法
  139. [self _updateDisplayingInHierarchyProperty];
  140. }
  141. return self;
  142. }
  143. - (LookinObject *)displayingObject {
  144. return self.viewObject ? : self.layerObject;
  145. }
  146. - (void)setAttributesGroupList:(NSSet<LookinAttributesGroup *> *)attributesGroupList {
  147. _attributesGroupList = [attributesGroupList copy];
  148. [attributesGroupList enumerateObjectsUsingBlock:^(LookinAttributesGroup * _Nonnull group, BOOL * _Nonnull stop) {
  149. [group.attrSections enumerateObjectsUsingBlock:^(LookinAttributesSection * _Nonnull section, NSUInteger idx, BOOL * _Nonnull stop) {
  150. [section.attributes enumerateObjectsUsingBlock:^(LookinAttribute * _Nonnull attr, NSUInteger idx, BOOL * _Nonnull stop) {
  151. attr.targetDisplayItem = self;
  152. }];
  153. }];
  154. }];
  155. }
  156. - (BOOL)representedForSystemClass {
  157. return [self.title hasPrefix:@"UI"] || [self.title hasPrefix:@"CA"] || [self.title hasPrefix:@"_"];
  158. }
  159. - (BOOL)itemIsKindOfClassWithName:(NSString *)className {
  160. if (!className) {
  161. NSAssert(NO, @"");
  162. return NO;
  163. }
  164. return [self itemIsKindOfClassesWithNames:[NSSet setWithObject:className]];
  165. }
  166. - (BOOL)itemIsKindOfClassesWithNames:(NSSet<NSString *> *)targetClassNames {
  167. if (!targetClassNames.count) {
  168. return NO;
  169. }
  170. LookinObject *selfObj = self.viewObject ? : self.layerObject;
  171. if (!selfObj) {
  172. return NO;
  173. }
  174. __block BOOL boolValue = NO;
  175. [targetClassNames enumerateObjectsUsingBlock:^(NSString * _Nonnull targetClassName, BOOL * _Nonnull stop_outer) {
  176. [selfObj.classChainList enumerateObjectsUsingBlock:^(NSString * _Nonnull selfClass, NSUInteger idx, BOOL * _Nonnull stop_inner) {
  177. NSString *nonPrefixSelfClass = [selfClass componentsSeparatedByString:@"."].lastObject;
  178. if ([nonPrefixSelfClass isEqualToString:targetClassName]) {
  179. boolValue = YES;
  180. *stop_inner = YES;
  181. }
  182. }];
  183. if (boolValue) {
  184. *stop_outer = YES;
  185. }
  186. }];
  187. return boolValue;
  188. }
  189. - (void)setSubitems:(NSArray<LookinDisplayItem *> *)subitems {
  190. [_subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  191. obj.superItem = nil;
  192. }];
  193. _subitems = subitems;
  194. self.isExpandable = (subitems.count > 0);
  195. [subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  196. NSAssert(!obj.superItem, @"");
  197. obj.superItem = self;
  198. [obj _updateInHiddenHierarchyProperty];
  199. [obj _updateDisplayingInHierarchyProperty];
  200. [obj _updateFrameToRoot];
  201. }];
  202. }
  203. - (void)setIsExpandable:(BOOL)isExpandable {
  204. if (_isExpandable == isExpandable) {
  205. return;
  206. }
  207. _isExpandable = isExpandable;
  208. [self _notifyDelegatesWith:LookinDisplayItemProperty_IsExpandable];
  209. }
  210. - (void)setIsExpanded:(BOOL)isExpanded {
  211. if (_isExpanded == isExpanded) {
  212. return;
  213. }
  214. _isExpanded = isExpanded;
  215. [self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  216. [obj _updateDisplayingInHierarchyProperty];
  217. }];
  218. [self _notifyDelegatesWith:LookinDisplayItemProperty_IsExpanded];
  219. }
  220. - (void)setSoloScreenshot:(LookinImage *)soloScreenshot {
  221. if (_soloScreenshot == soloScreenshot) {
  222. return;
  223. }
  224. _soloScreenshot = soloScreenshot;
  225. [self _notifyDelegatesWith:LookinDisplayItemProperty_SoloScreenshot];
  226. }
  227. - (void)setIsSelected:(BOOL)isSelected {
  228. if (_isSelected == isSelected) {
  229. return;
  230. }
  231. _isSelected = isSelected;
  232. [self _notifyDelegatesWith:LookinDisplayItemProperty_IsSelected];
  233. }
  234. - (void)setDoNotFetchScreenshotReason:(LookinDoNotFetchScreenshotReason)doNotFetchScreenshotReason {
  235. if (_doNotFetchScreenshotReason == doNotFetchScreenshotReason) {
  236. return;
  237. }
  238. _doNotFetchScreenshotReason = doNotFetchScreenshotReason;
  239. [self _notifyDelegatesWith:LookinDisplayItemProperty_AvoidSyncScreenshot];
  240. }
  241. - (void)setIsHovered:(BOOL)isHovered {
  242. if (_isHovered == isHovered) {
  243. return;
  244. }
  245. _isHovered = isHovered;
  246. [self _notifyDelegatesWith:LookinDisplayItemProperty_IsHovered];
  247. }
  248. - (void)setGroupScreenshot:(LookinImage *)groupScreenshot {
  249. if (_groupScreenshot == groupScreenshot) {
  250. return;
  251. }
  252. _groupScreenshot = groupScreenshot;
  253. [self _notifyDelegatesWith:LookinDisplayItemProperty_GroupScreenshot];
  254. }
  255. - (void)setDisplayingInHierarchy:(BOOL)displayingInHierarchy {
  256. if (_displayingInHierarchy == displayingInHierarchy) {
  257. return;
  258. }
  259. _displayingInHierarchy = displayingInHierarchy;
  260. [self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  261. [obj _updateDisplayingInHierarchyProperty];
  262. }];
  263. [self _notifyDelegatesWith:LookinDisplayItemProperty_DisplayingInHierarchy];
  264. }
  265. - (void)_updateDisplayingInHierarchyProperty {
  266. if (self.superItem && (!self.superItem.displayingInHierarchy || !self.superItem.isExpanded)) {
  267. self.displayingInHierarchy = NO;
  268. } else {
  269. self.displayingInHierarchy = YES;
  270. }
  271. }
  272. - (void)setIsHidden:(BOOL)isHidden {
  273. _isHidden = isHidden;
  274. [self _updateInHiddenHierarchyProperty];
  275. }
  276. - (void)setAlpha:(float)alpha {
  277. _alpha = alpha;
  278. [self _updateInHiddenHierarchyProperty];
  279. }
  280. - (void)setInHiddenHierarchy:(BOOL)inHiddenHierarchy {
  281. if (_inHiddenHierarchy == inHiddenHierarchy) {
  282. return;
  283. }
  284. _inHiddenHierarchy = inHiddenHierarchy;
  285. [self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  286. [obj _updateInHiddenHierarchyProperty];
  287. }];
  288. [self _notifyDelegatesWith:LookinDisplayItemProperty_InHiddenHierarchy];
  289. }
  290. - (void)_updateInHiddenHierarchyProperty {
  291. if (self.superItem.inHiddenHierarchy || self.isHidden || self.alpha <= 0) {
  292. self.inHiddenHierarchy = YES;
  293. } else {
  294. self.inHiddenHierarchy = NO;
  295. }
  296. }
  297. - (void)enumerateSelfAndAncestors:(void (^)(LookinDisplayItem *, BOOL *))block {
  298. if (!block) {
  299. return;
  300. }
  301. LookinDisplayItem *item = self;
  302. while (item) {
  303. BOOL shouldStop = NO;
  304. block(item, &shouldStop);
  305. if (shouldStop) {
  306. break;
  307. }
  308. item = item.superItem;
  309. }
  310. }
  311. - (void)enumerateAncestors:(void (^)(LookinDisplayItem *, BOOL *))block {
  312. [self.superItem enumerateSelfAndAncestors:block];
  313. }
  314. - (void)enumerateSelfAndChildren:(void (^)(LookinDisplayItem *item))block {
  315. if (!block) {
  316. return;
  317. }
  318. block(self);
  319. [self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull subitem, NSUInteger idx, BOOL * _Nonnull stop) {
  320. [subitem enumerateSelfAndChildren:block];
  321. }];
  322. }
  323. + (NSArray<LookinDisplayItem *> *)flatItemsFromHierarchicalItems:(NSArray<LookinDisplayItem *> *)items {
  324. NSMutableArray *resultArray = [NSMutableArray array];
  325. [items enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  326. if (obj.superItem) {
  327. obj.indentLevel = obj.superItem.indentLevel + 1;
  328. }
  329. [resultArray addObject:obj];
  330. if (obj.subitems.count) {
  331. [resultArray addObjectsFromArray:[self flatItemsFromHierarchicalItems:obj.subitems]];
  332. }
  333. }];
  334. return resultArray;
  335. }
  336. - (NSString *)description {
  337. return [NSString stringWithFormat:@"%@", self.title];
  338. }
  339. - (void)setFrameToRoot:(CGRect)frameToRoot {
  340. if (CGRectEqualToRect(_frameToRoot, frameToRoot)) {
  341. return;
  342. }
  343. _frameToRoot = frameToRoot;
  344. [(NSArray<LookinDisplayItem *> *)self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  345. [obj _updateFrameToRoot];
  346. [obj _updateInNoPreviewHierarchy];
  347. }];
  348. [self _notifyDelegatesWith:LookinDisplayItemProperty_FrameToRoot];
  349. }
  350. - (void)setPreviewItemDelegate:(id<LookinDisplayItemDelegate>)previewItemDelegate {
  351. _previewItemDelegate = previewItemDelegate;
  352. if (![previewItemDelegate respondsToSelector:@selector(displayItem:propertyDidChange:)]) {
  353. NSAssert(NO, @"");
  354. _previewItemDelegate = nil;
  355. return;
  356. }
  357. [self.previewItemDelegate displayItem:self propertyDidChange:LookinDisplayItemProperty_None];
  358. }
  359. - (void)setRowViewDelegate:(id<LookinDisplayItemDelegate>)rowViewDelegate {
  360. if (_rowViewDelegate == rowViewDelegate) {
  361. return;
  362. }
  363. _rowViewDelegate = rowViewDelegate;
  364. if (![rowViewDelegate respondsToSelector:@selector(displayItem:propertyDidChange:)]) {
  365. NSAssert(NO, @"");
  366. _rowViewDelegate = nil;
  367. return;
  368. }
  369. [self.rowViewDelegate displayItem:self propertyDidChange:LookinDisplayItemProperty_None];
  370. }
  371. - (void)setFrame:(CGRect)frame {
  372. _frame = frame;
  373. [self _updateFrameToRoot];
  374. }
  375. - (void)setBounds:(CGRect)bounds {
  376. _bounds = bounds;
  377. [(NSArray<LookinDisplayItem *> *)self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  378. [obj _updateFrameToRoot];
  379. }];
  380. }
  381. - (void)_updateFrameToRoot {
  382. if (!self.superItem) {
  383. self.frameToRoot = self.frame;
  384. return;
  385. }
  386. CGRect superFrameToRoot = self.superItem.frameToRoot;
  387. CGRect superBounds = self.superItem.bounds;
  388. CGRect selfFrame = self.frame;
  389. CGFloat x = selfFrame.origin.x - superBounds.origin.x + superFrameToRoot.origin.x;
  390. CGFloat y = selfFrame.origin.y - superBounds.origin.y + superFrameToRoot.origin.y;
  391. CGFloat width = selfFrame.size.width;
  392. CGFloat height = selfFrame.size.height;
  393. self.frameToRoot = CGRectMake(x, y, width, height);
  394. }
  395. - (void)setInNoPreviewHierarchy:(BOOL)inNoPreviewHierarchy {
  396. if (_inNoPreviewHierarchy == inNoPreviewHierarchy) {
  397. return;
  398. }
  399. _inNoPreviewHierarchy = inNoPreviewHierarchy;
  400. [self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  401. [obj _updateInNoPreviewHierarchy];
  402. }];
  403. [self _notifyDelegatesWith:LookinDisplayItemProperty_InNoPreviewHierarchy];
  404. }
  405. - (void)setNoPreview:(BOOL)noPreview {
  406. _noPreview = noPreview;
  407. [self _updateInNoPreviewHierarchy];
  408. }
  409. - (void)_updateInNoPreviewHierarchy {
  410. if (self.superItem.inNoPreviewHierarchy || self.noPreview) {
  411. self.inNoPreviewHierarchy = YES;
  412. } else {
  413. self.inNoPreviewHierarchy = NO;
  414. }
  415. }
  416. - (LookinImage *)appropriateScreenshot {
  417. if (self.isExpandable && self.isExpanded) {
  418. return self.soloScreenshot;
  419. }
  420. return self.groupScreenshot;
  421. }
  422. - (void)_notifyDelegatesWith:(LookinDisplayItemProperty)property {
  423. [self.previewItemDelegate displayItem:self propertyDidChange:property];
  424. [self.rowViewDelegate displayItem:self propertyDidChange:property];
  425. }
  426. - (BOOL)isMatchedWithSearchString:(NSString *)string {
  427. if (string.length == 0) {
  428. NSAssert(NO, @"");
  429. return NO;
  430. }
  431. if ([self.title.lowercaseString containsString:string.lowercaseString]) {
  432. return YES;
  433. }
  434. if ([self.subtitle.lowercaseString containsString:string.lowercaseString]) {
  435. return YES;
  436. }
  437. return NO;
  438. }
  439. - (void)setIsInSearch:(BOOL)isInSearch {
  440. _isInSearch = isInSearch;
  441. [self _notifyDelegatesWith:LookinDisplayItemProperty_IsInSearch];
  442. }
  443. - (void)setHighlightedSearchString:(NSString *)highlightedSearchString {
  444. _highlightedSearchString = highlightedSearchString;
  445. [self _notifyDelegatesWith:LookinDisplayItemProperty_HighlightedSearchString];
  446. }
  447. - (void)setHostViewControllerObject:(LookinObject *)hostViewControllerObject {
  448. _hostViewControllerObject = hostViewControllerObject;
  449. [self _updateSubtitleProperty];
  450. }
  451. - (void)setViewObject:(LookinObject *)viewObject {
  452. _viewObject = viewObject;
  453. [self _updateSubtitleProperty];
  454. [self _updateTitleProperty];
  455. }
  456. - (void)setLayerObject:(LookinObject *)layerObject {
  457. _layerObject = layerObject;
  458. [self _updateSubtitleProperty];
  459. [self _updateTitleProperty];
  460. }
  461. - (void)_updateTitleProperty {
  462. if (self.viewObject) {
  463. _title = self.viewObject.shortSelfClassName;
  464. } else if (self.layerObject) {
  465. _title = self.layerObject.shortSelfClassName;
  466. } else {
  467. _title = nil;
  468. }
  469. }
  470. - (void)_updateSubtitleProperty {
  471. NSString *subtitle = @"";
  472. if (self.hostViewControllerObject.shortSelfClassName.length) {
  473. subtitle = [NSString stringWithFormat:@"%@.view", self.hostViewControllerObject.shortSelfClassName];
  474. } else {
  475. LookinObject *representedObject = self.viewObject ? : self.layerObject;
  476. if (representedObject.specialTrace.length) {
  477. subtitle = representedObject.specialTrace;
  478. } else if (representedObject.ivarTraces.count) {
  479. NSArray<NSString *> *ivarNameList = [representedObject.ivarTraces lookin_map:^id(NSUInteger idx, LookinIvarTrace *value) {
  480. return value.ivarName;
  481. }];
  482. subtitle = [[[NSSet setWithArray:ivarNameList] allObjects] componentsJoinedByString:@" "];
  483. }
  484. }
  485. _subtitle = subtitle;
  486. }
  487. @end
  488. #endif /* SHOULD_COMPILE_LOOKIN_SERVER */