mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Add read-only names to UIView and CALayer
- Backed by name of the underlying ASDisplayNode. - Remove goofy usages of `setValue:forKey:` in ASDisplayNodeTests and ASDisplayNodeAppearanceTests.
This commit is contained in:
@@ -650,6 +650,7 @@ typedef void (^ASDisplayNodeDidLoadBlock)(ASDisplayNode *node);
|
||||
* @param node The node to be added.
|
||||
*/
|
||||
- (void)addSubnode:(ASDisplayNode *)node;
|
||||
- (NSString *)name;
|
||||
@end
|
||||
|
||||
/** CALayer(AsyncDisplayKit) defines convenience method for adding sub-ASDisplayNode to a CALayer. */
|
||||
@@ -660,6 +661,7 @@ typedef void (^ASDisplayNodeDidLoadBlock)(ASDisplayNode *node);
|
||||
* @param node The node to be added.
|
||||
*/
|
||||
- (void)addSubnode:(ASDisplayNode *)node;
|
||||
- (NSString *)name;
|
||||
@end
|
||||
|
||||
@interface ASDisplayNode (Deprecated)
|
||||
|
||||
@@ -2203,6 +2203,11 @@ static const char *ASDisplayNodeAssociatedNodeKey = "ASAssociatedNode";
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)name
|
||||
{
|
||||
return self.asyncdisplaykit_node.name;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CALayer (AsyncDisplayKit)
|
||||
@@ -2212,6 +2217,11 @@ static const char *ASDisplayNodeAssociatedNodeKey = "ASAssociatedNode";
|
||||
[self addSublayer:node.layer];
|
||||
}
|
||||
|
||||
- (NSString *)name
|
||||
{
|
||||
return self.asyncdisplaykit_node.name;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@@ -56,12 +56,15 @@ static dispatch_block_t modifyMethodByAddingPrologueBlockAndReturnCleanupBlock(C
|
||||
@interface ASDisplayNodeAppearanceTests : XCTestCase
|
||||
@end
|
||||
|
||||
// Conveniences for making nodes named a certain way
|
||||
#define DeclareNodeNamed(n) ASDisplayNode *n = [[ASDisplayNode alloc] init]; n.name = @#n
|
||||
#define DeclareViewNamed(v) UIView *v = viewWithName(@#v)
|
||||
|
||||
// FIXME: It's goofy to use `setValue:forKey:` here but importing ASDisplayNodeInternal.h
|
||||
// in this file causes build to fail (compiler chokes at ASDN::RecursiveMutex)
|
||||
#define DeclareViewNamed(v) UIView *v = [[UIView alloc] init]; [v.layer setValue:@#v forKey:@"asyncdisplaykit_node.name"]
|
||||
#define DeclareLayerNamed(l) CALayer *l = [[CALayer alloc] init]; [l setValue:@#l forKey:@"asyncdisplaykit_node.name"]
|
||||
static UIView *viewWithName(NSString *name) {
|
||||
ASDisplayNode *n = [[ASDisplayNode alloc] init];
|
||||
n.name = name;
|
||||
return n.view;
|
||||
}
|
||||
|
||||
@implementation ASDisplayNodeAppearanceTests
|
||||
{
|
||||
|
||||
@@ -17,20 +17,29 @@
|
||||
#import "UIView+ASConvenience.h"
|
||||
|
||||
// Conveniences for making nodes named a certain way
|
||||
|
||||
#define DeclareNodeNamed(n) ASDisplayNode *n = [[ASDisplayNode alloc] init]; n.name = @#n
|
||||
#define DeclareViewNamed(v) UIView *v = viewWithName(@#v)
|
||||
#define DeclareLayerNamed(l) CALayer *l = layerWithName(@#l)
|
||||
|
||||
// FIXME: It's goofy to use `setValue:forKey:` here but importing ASDisplayNodeInternal.h
|
||||
// in this file causes build to fail (compiler chokes at ASDN::RecursiveMutex)
|
||||
#define DeclareViewNamed(v) UIView *v = [[UIView alloc] init]; [v.layer setValue:@#v forKey:@"asyncdisplaykit_node.name"]
|
||||
#define DeclareLayerNamed(l) CALayer *l = [[CALayer alloc] init]; [l setValue:@#l forKey:@"asyncdisplaykit_node.name"]
|
||||
static UIView *viewWithName(NSString *name) {
|
||||
ASDisplayNode *n = [[ASDisplayNode alloc] init];
|
||||
n.name = name;
|
||||
return n.view;
|
||||
}
|
||||
|
||||
static CALayer *layerWithName(NSString *name) {
|
||||
ASDisplayNode *n = [[ASDisplayNode alloc] init];
|
||||
n.layerBacked = YES;
|
||||
n.name = name;
|
||||
return n.layer;
|
||||
}
|
||||
|
||||
static NSString *orderStringFromSublayers(CALayer *l) {
|
||||
return [[l.sublayers valueForKey:@"asyncdisplaykit_node.name"] componentsJoinedByString:@","];
|
||||
return [[l.sublayers valueForKey:@"name"] componentsJoinedByString:@","];
|
||||
}
|
||||
|
||||
static NSString *orderStringFromSubviews(UIView *v) {
|
||||
return [[v.subviews valueForKeyPath:@"layer.asyncdisplaykit_node.name"] componentsJoinedByString:@","];
|
||||
return [[v.subviews valueForKey:@"name"] componentsJoinedByString:@","];
|
||||
}
|
||||
|
||||
static NSString *orderStringFromSubnodes(ASDisplayNode *n) {
|
||||
@@ -1377,7 +1386,6 @@ static inline BOOL _CGPointEqualToPointWithEpsilon(CGPoint point1, CGPoint point
|
||||
DeclareNodeNamed(b);
|
||||
DeclareNodeNamed(c);
|
||||
DeclareViewNamed(d);
|
||||
DeclareLayerNamed(e);
|
||||
|
||||
[parent layer];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user