Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions AsyncDisplayKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,6 @@
205F0E221B376416007741D0 /* CGRect+ASConvenience.m in Sources */,
058D0A21195D050800B7D73C /* NSMutableAttributedString+TextKitAdditions.m in Sources */,
205F0E101B371875007741D0 /* UICollectionViewLayout+ASConvenience.m in Sources */,
058D0A25195D050800B7D73C /* UIView+ASConvenience.m in Sources */,
CC7FD9DF1BB5E962005CCB2B /* ASPhotosFrameworkImageRequest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1660,7 +1659,6 @@
34566CB31BC1213700715E6B /* ASPhotosFrameworkImageRequest.m in Sources */,
B350623B1B010EFD0018CF92 /* NSMutableAttributedString+TextKitAdditions.m in Sources */,
044284FD1BAA365100D16268 /* UICollectionViewLayout+ASConvenience.m in Sources */,
B35062441B010EFD0018CF92 /* UIView+ASConvenience.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
9 changes: 7 additions & 2 deletions AsyncDisplayKit/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ typedef void (^ASDisplayNodeDidLoadBlock)(ASDisplayNode *node);

/** @name Properties */

/**
* @abstract The name of this node, which will be displayed in `description`. The default value is nil.
*/
@property (atomic, copy) NSString *name;

/**
* @abstract Returns whether the node is synchronous.
Expand Down Expand Up @@ -539,7 +543,7 @@ typedef void (^ASDisplayNodeDidLoadBlock)(ASDisplayNode *node);
* Using them will not cause the actual view/layer to be created, and will be applied when it is created (when the view
* or layer property is accessed).
*
* After the view is created, the properties pass through to the view directly as if called on the main thread.
* - NOTE: After the view or layer is created, the properties pass through to the view or layer directly and must be called on the main thread.
*
* See UIView and CALayer for documentation on these common properties.
*/
Expand Down Expand Up @@ -583,7 +587,6 @@ typedef void (^ASDisplayNodeDidLoadBlock)(ASDisplayNode *node);
@property (atomic, assign) CGFloat contentsScale; // default=1.0f. See @contentsScaleForDisplay for more info
@property (atomic, assign) CATransform3D transform; // default=CATransform3DIdentity
@property (atomic, assign) CATransform3D subnodeTransform; // default=CATransform3DIdentity
@property (atomic, copy) NSString *name; // default=nil. Use this to tag your layers in the server-recurse-description / pca or for your own purposes

/**
* @abstract The node view's background color.
Expand Down Expand Up @@ -647,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. */
Expand All @@ -657,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)
Expand Down
30 changes: 27 additions & 3 deletions AsyncDisplayKit/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#import "_ASDisplayView.h"
#import "_ASScopeTimer.h"
#import "ASDisplayNodeExtras.h"
#import "ASEqualityHelpers.h"

#import "ASInternalHelpers.h"
#import "ASLayout.h"
Expand Down Expand Up @@ -47,6 +48,7 @@ @implementation ASDisplayNode

// these dynamic properties all defined in ASLayoutOptionsPrivate.m
@dynamic spacingAfter, spacingBefore, flexGrow, flexShrink, flexBasis, alignSelf, ascender, descender, sizeRange, layoutPosition, layoutOptions;
@synthesize name = _name;
@synthesize preferredFrameSize = _preferredFrameSize;
@synthesize isFinalLayoutable = _isFinalLayoutable;

Expand Down Expand Up @@ -458,9 +460,7 @@ - (void)_loadViewOrLayerIsLayerBacked:(BOOL)isLayerBacked
_layer = _view.layer;
}
_layer.asyncdisplaykit_node = self;
#if DEBUG
_layer.name = self.description;
#endif

self.asyncLayer.asyncDelegate = self;

{
Expand Down Expand Up @@ -526,6 +526,20 @@ - (BOOL)isNodeLoaded
return (_view != nil || (_flags.layerBacked && _layer != nil));
}

- (NSString *)name
{
ASDN::MutexLocker l(_propertyLock);
return _name;
}

- (void)setName:(NSString *)name
{
ASDN::MutexLocker l(_propertyLock);
if (!ASObjectIsEqual(_name, name)) {
_name = [name copy];
}
}

- (BOOL)isSynchronous
{
return _flags.synchronous;
Expand Down Expand Up @@ -2187,6 +2201,11 @@ - (void)addSubnode:(ASDisplayNode *)node
}
}

- (NSString *)name
{
return self.asyncdisplaykit_node.name;
}

@end

@implementation CALayer (AsyncDisplayKit)
Expand All @@ -2196,6 +2215,11 @@ - (void)addSubnode:(ASDisplayNode *)node
[self addSublayer:node.layer];
}

- (NSString *)name
{
return self.asyncdisplaykit_node.name;
}

@end


Expand Down
5 changes: 0 additions & 5 deletions AsyncDisplayKit/Details/UIView+ASConvenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
@property (nonatomic, assign) CGFloat borderWidth;
@property (nonatomic, assign, getter = isOpaque) BOOL opaque;
@property (nonatomic, retain) __attribute__((NSObject)) CGColorRef borderColor;
@property (nonatomic, copy) NSString *asyncdisplaykit_name;
@property (nonatomic, retain) __attribute__((NSObject)) CGColorRef backgroundColor;
@property (nonatomic, assign) BOOL allowsEdgeAntialiasing;
@property (nonatomic, assign) unsigned int edgeAntialiasingMask;
Expand Down Expand Up @@ -79,7 +78,3 @@
@property (nonatomic, copy) NSString *accessibilityIdentifier;

@end

@interface CALayer (ASDisplayNodeLayer)
@property (atomic, copy) NSString *asyncdisplaykit_name;
@end
13 changes: 0 additions & 13 deletions AsyncDisplayKit/Details/UIView+ASConvenience.m

This file was deleted.

5 changes: 0 additions & 5 deletions AsyncDisplayKit/Details/_ASDisplayLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ - (id)init
_displaySentinel = [[ASSentinel alloc] init];

self.opaque = YES;

#if DEBUG
// This is too expensive to do in production on all layers.
self.name = [NSString stringWithFormat:@"%@ (%p)", NSStringFromClass([self class]), self];
#endif
}
return self;
}
Expand Down
12 changes: 0 additions & 12 deletions AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -496,18 +496,6 @@ - (void)setEdgeAntialiasingMask:(unsigned int)edgeAntialiasingMask
_setToLayer(edgeAntialiasingMask, edgeAntialiasingMask);
}

- (NSString *)name
{
_bridge_prologue;
return _getFromLayer(asyncdisplaykit_name);
}

- (void)setName:(NSString *)name
{
_bridge_prologue;
_setToLayer(asyncdisplaykit_name, name);
}

- (BOOL)isAccessibilityElement
{
_bridge_prologue;
Expand Down
23 changes: 0 additions & 23 deletions AsyncDisplayKit/Private/_ASPendingState.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ @implementation _ASPendingState
CGFloat borderWidth;
CGColorRef borderColor;
BOOL asyncTransactionContainer;
NSString *name;
BOOL isAccessibilityElement;
NSString *accessibilityLabel;
NSString *accessibilityHint;
Expand Down Expand Up @@ -85,7 +84,6 @@ @implementation _ASPendingState
int setBorderWidth:1;
int setBorderColor:1;
int setAsyncTransactionContainer:1;
int setName:1;
int setAllowsEdgeAntialiasing:1;
int setEdgeAntialiasingMask:1;
int setIsAccessibilityElement:1;
Expand Down Expand Up @@ -133,7 +131,6 @@ @implementation _ASPendingState
@synthesize borderWidth=borderWidth;
@synthesize borderColor=borderColor;
@synthesize asyncdisplaykit_asyncTransactionContainer=asyncTransactionContainer;
@synthesize asyncdisplaykit_name=name;

- (id)init
{
Expand Down Expand Up @@ -419,20 +416,6 @@ - (void)asyncdisplaykit_setAsyncTransactionContainer:(BOOL)flag
_flags.setAsyncTransactionContainer = YES;
}

// This is named this way, since I'm not sure we can change the setter for the CA version
- (void)setAsyncdisplaykit_name:(NSString *)newName
{
_flags.setName = YES;
if (name != newName) {
name = [newName copy];
}
}

- (NSString *)asyncdisplaykit_name
{
return name;
}

- (BOOL)isAccessibilityElement
{
return isAccessibilityElement;
Expand Down Expand Up @@ -641,9 +624,6 @@ - (void)applyToLayer:(CALayer *)layer
if (_flags.setAsyncTransactionContainer)
layer.asyncdisplaykit_asyncTransactionContainer = asyncTransactionContainer;

if (_flags.setName)
layer.asyncdisplaykit_name = name;

if (_flags.setOpaque)
ASDisplayNodeAssert(layer.opaque == opaque, @"Didn't set opaque as desired");
}
Expand Down Expand Up @@ -756,9 +736,6 @@ - (void)applyToView:(UIView *)view
if (_flags.setAsyncTransactionContainer)
view.asyncdisplaykit_asyncTransactionContainer = asyncTransactionContainer;

if (_flags.setName)
layer.asyncdisplaykit_name = name;

if (_flags.setOpaque)
ASDisplayNodeAssert(view.layer.opaque == opaque, @"Didn't set opaque as desired");

Expand Down
10 changes: 8 additions & 2 deletions AsyncDisplayKitTests/ASDisplayNodeAppearanceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ - (id)initWithLayerClass:(Class)layerClass;
@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 = [[UIView alloc] init]; v.layer.asyncdisplaykit_name = @#v
#define DeclareLayerNamed(l) CALayer *l = [[CALayer alloc] init]; l.asyncdisplaykit_name = @#l
#define DeclareViewNamed(v) UIView *v = viewWithName(@#v)

static UIView *viewWithName(NSString *name) {
ASDisplayNode *n = [[ASDisplayNode alloc] init];
n.name = name;
return n.view;
}

@implementation ASDisplayNodeAppearanceTests
{
Expand Down
25 changes: 18 additions & 7 deletions AsyncDisplayKitTests/ASDisplayNodeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,33 @@
#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 = [[UIView alloc] init]; v.layer.asyncdisplaykit_name = @#v
#define DeclareLayerNamed(l) CALayer *l = [[CALayer alloc] init]; l.asyncdisplaykit_name = @#l
#define DeclareViewNamed(v) UIView *v = viewWithName(@#v)
#define DeclareLayerNamed(l) CALayer *l = layerWithName(@#l)

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_name"] allObjects] componentsJoinedByString:@","];
return [[l.sublayers valueForKey:@"name"] componentsJoinedByString:@","];
}

static NSString *orderStringFromSubviews(UIView *v) {
return [[[v.subviews valueForKeyPath:@"layer.asyncdisplaykit_name"] allObjects] componentsJoinedByString:@","];
return [[v.subviews valueForKey:@"name"] componentsJoinedByString:@","];
}

static NSString *orderStringFromSubnodes(ASDisplayNode *n) {
return [[[n.subnodes valueForKey:@"name"] allObjects] componentsJoinedByString:@","];
return [[n.subnodes valueForKey:@"name"] componentsJoinedByString:@","];
}

// Asserts subnode, subview, sublayer order match what you provide here
Expand Down Expand Up @@ -1374,7 +1386,6 @@ - (void)testInsertSubviewAtIndexWithMeddlingView
DeclareNodeNamed(b);
DeclareNodeNamed(c);
DeclareViewNamed(d);
DeclareLayerNamed(e);

[parent layer];

Expand Down