diff --git a/AsyncDisplayKit.xcodeproj/project.pbxproj b/AsyncDisplayKit.xcodeproj/project.pbxproj index 545f9d05e7..fb4230ab72 100644 --- a/AsyncDisplayKit.xcodeproj/project.pbxproj +++ b/AsyncDisplayKit.xcodeproj/project.pbxproj @@ -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; @@ -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; }; diff --git a/AsyncDisplayKit/ASDisplayNode.h b/AsyncDisplayKit/ASDisplayNode.h index bb84512f43..0f5c3a8c97 100644 --- a/AsyncDisplayKit/ASDisplayNode.h +++ b/AsyncDisplayKit/ASDisplayNode.h @@ -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. @@ -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. */ @@ -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. diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index 2c536006e0..9829ea5311 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -19,6 +19,7 @@ #import "_ASDisplayView.h" #import "_ASScopeTimer.h" #import "ASDisplayNodeExtras.h" +#import "ASEqualityHelpers.h" #import "ASInternalHelpers.h" #import "ASLayout.h" @@ -47,6 +48,7 @@ // 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; @@ -526,6 +528,20 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c) 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; diff --git a/AsyncDisplayKit/Details/UIView+ASConvenience.h b/AsyncDisplayKit/Details/UIView+ASConvenience.h index d1f0032469..908c99b2fc 100644 --- a/AsyncDisplayKit/Details/UIView+ASConvenience.h +++ b/AsyncDisplayKit/Details/UIView+ASConvenience.h @@ -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; @@ -79,7 +78,3 @@ @property (nonatomic, copy) NSString *accessibilityIdentifier; @end - -@interface CALayer (ASDisplayNodeLayer) -@property (atomic, copy) NSString *asyncdisplaykit_name; -@end diff --git a/AsyncDisplayKit/Details/UIView+ASConvenience.m b/AsyncDisplayKit/Details/UIView+ASConvenience.m deleted file mode 100644 index 6772024821..0000000000 --- a/AsyncDisplayKit/Details/UIView+ASConvenience.m +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (c) 2014-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import "UIView+ASConvenience.h" - -@implementation CALayer (ASDisplayNodeLayer) -@dynamic asyncdisplaykit_name; -@end diff --git a/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm b/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm index 4909abdd46..63ef4ed8da 100644 --- a/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm +++ b/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm @@ -496,18 +496,6 @@ _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; diff --git a/AsyncDisplayKit/Private/_ASPendingState.m b/AsyncDisplayKit/Private/_ASPendingState.m index f8c2426971..0ce85df83e 100644 --- a/AsyncDisplayKit/Private/_ASPendingState.m +++ b/AsyncDisplayKit/Private/_ASPendingState.m @@ -37,7 +37,6 @@ CGFloat borderWidth; CGColorRef borderColor; BOOL asyncTransactionContainer; - NSString *name; BOOL isAccessibilityElement; NSString *accessibilityLabel; NSString *accessibilityHint; @@ -85,7 +84,6 @@ int setBorderWidth:1; int setBorderColor:1; int setAsyncTransactionContainer:1; - int setName:1; int setAllowsEdgeAntialiasing:1; int setEdgeAntialiasingMask:1; int setIsAccessibilityElement:1; @@ -133,7 +131,6 @@ @synthesize borderWidth=borderWidth; @synthesize borderColor=borderColor; @synthesize asyncdisplaykit_asyncTransactionContainer=asyncTransactionContainer; -@synthesize asyncdisplaykit_name=name; - (id)init { @@ -419,20 +416,6 @@ _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; @@ -641,9 +624,6 @@ 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"); } @@ -756,9 +736,6 @@ 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"); diff --git a/AsyncDisplayKitTests/ASDisplayNodeAppearanceTests.m b/AsyncDisplayKitTests/ASDisplayNodeAppearanceTests.m index 02bb2c427e..8eedb0711d 100644 --- a/AsyncDisplayKitTests/ASDisplayNodeAppearanceTests.m +++ b/AsyncDisplayKitTests/ASDisplayNodeAppearanceTests.m @@ -57,8 +57,11 @@ static dispatch_block_t modifyMethodByAddingPrologueBlockAndReturnCleanupBlock(C @end #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 + +// 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"] @implementation ASDisplayNodeAppearanceTests { diff --git a/AsyncDisplayKitTests/ASDisplayNodeTests.m b/AsyncDisplayKitTests/ASDisplayNodeTests.m index 4ce0c49bcf..1984308ca6 100644 --- a/AsyncDisplayKitTests/ASDisplayNodeTests.m +++ b/AsyncDisplayKitTests/ASDisplayNodeTests.m @@ -19,19 +19,22 @@ // 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 + +// 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 NSString *orderStringFromSublayers(CALayer *l) { - return [[[l.sublayers valueForKey:@"asyncdisplaykit_name"] allObjects] componentsJoinedByString:@","]; + return [[l.sublayers valueForKey:@"asyncdisplaykit_node.name"] componentsJoinedByString:@","]; } static NSString *orderStringFromSubviews(UIView *v) { - return [[[v.subviews valueForKeyPath:@"layer.asyncdisplaykit_name"] allObjects] componentsJoinedByString:@","]; + return [[v.subviews valueForKeyPath:@"layer.asyncdisplaykit_node.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