mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +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.
|
* @param node The node to be added.
|
||||||
*/
|
*/
|
||||||
- (void)addSubnode:(ASDisplayNode *)node;
|
- (void)addSubnode:(ASDisplayNode *)node;
|
||||||
|
- (NSString *)name;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
/** CALayer(AsyncDisplayKit) defines convenience method for adding sub-ASDisplayNode to a CALayer. */
|
/** 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.
|
* @param node The node to be added.
|
||||||
*/
|
*/
|
||||||
- (void)addSubnode:(ASDisplayNode *)node;
|
- (void)addSubnode:(ASDisplayNode *)node;
|
||||||
|
- (NSString *)name;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface ASDisplayNode (Deprecated)
|
@interface ASDisplayNode (Deprecated)
|
||||||
|
|||||||
@@ -2203,6 +2203,11 @@ static const char *ASDisplayNodeAssociatedNodeKey = "ASAssociatedNode";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *)name
|
||||||
|
{
|
||||||
|
return self.asyncdisplaykit_node.name;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation CALayer (AsyncDisplayKit)
|
@implementation CALayer (AsyncDisplayKit)
|
||||||
@@ -2212,6 +2217,11 @@ static const char *ASDisplayNodeAssociatedNodeKey = "ASAssociatedNode";
|
|||||||
[self addSublayer:node.layer];
|
[self addSublayer:node.layer];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *)name
|
||||||
|
{
|
||||||
|
return self.asyncdisplaykit_node.name;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,12 +56,15 @@ static dispatch_block_t modifyMethodByAddingPrologueBlockAndReturnCleanupBlock(C
|
|||||||
@interface ASDisplayNodeAppearanceTests : XCTestCase
|
@interface ASDisplayNodeAppearanceTests : XCTestCase
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
// Conveniences for making nodes named a certain way
|
||||||
#define DeclareNodeNamed(n) ASDisplayNode *n = [[ASDisplayNode alloc] init]; n.name = @#n
|
#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
|
static UIView *viewWithName(NSString *name) {
|
||||||
// in this file causes build to fail (compiler chokes at ASDN::RecursiveMutex)
|
ASDisplayNode *n = [[ASDisplayNode alloc] init];
|
||||||
#define DeclareViewNamed(v) UIView *v = [[UIView alloc] init]; [v.layer setValue:@#v forKey:@"asyncdisplaykit_node.name"]
|
n.name = name;
|
||||||
#define DeclareLayerNamed(l) CALayer *l = [[CALayer alloc] init]; [l setValue:@#l forKey:@"asyncdisplaykit_node.name"]
|
return n.view;
|
||||||
|
}
|
||||||
|
|
||||||
@implementation ASDisplayNodeAppearanceTests
|
@implementation ASDisplayNodeAppearanceTests
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,20 +17,29 @@
|
|||||||
#import "UIView+ASConvenience.h"
|
#import "UIView+ASConvenience.h"
|
||||||
|
|
||||||
// Conveniences for making nodes named a certain way
|
// Conveniences for making nodes named a certain way
|
||||||
|
|
||||||
#define DeclareNodeNamed(n) ASDisplayNode *n = [[ASDisplayNode alloc] init]; n.name = @#n
|
#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
|
static UIView *viewWithName(NSString *name) {
|
||||||
// in this file causes build to fail (compiler chokes at ASDN::RecursiveMutex)
|
ASDisplayNode *n = [[ASDisplayNode alloc] init];
|
||||||
#define DeclareViewNamed(v) UIView *v = [[UIView alloc] init]; [v.layer setValue:@#v forKey:@"asyncdisplaykit_node.name"]
|
n.name = name;
|
||||||
#define DeclareLayerNamed(l) CALayer *l = [[CALayer alloc] init]; [l setValue:@#l forKey:@"asyncdisplaykit_node.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) {
|
static NSString *orderStringFromSublayers(CALayer *l) {
|
||||||
return [[l.sublayers valueForKey:@"asyncdisplaykit_node.name"] componentsJoinedByString:@","];
|
return [[l.sublayers valueForKey:@"name"] componentsJoinedByString:@","];
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSString *orderStringFromSubviews(UIView *v) {
|
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) {
|
static NSString *orderStringFromSubnodes(ASDisplayNode *n) {
|
||||||
@@ -1377,7 +1386,6 @@ static inline BOOL _CGPointEqualToPointWithEpsilon(CGPoint point1, CGPoint point
|
|||||||
DeclareNodeNamed(b);
|
DeclareNodeNamed(b);
|
||||||
DeclareNodeNamed(c);
|
DeclareNodeNamed(c);
|
||||||
DeclareViewNamed(d);
|
DeclareViewNamed(d);
|
||||||
DeclareLayerNamed(e);
|
|
||||||
|
|
||||||
[parent layer];
|
[parent layer];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user