Skip to content

Commit

Permalink
Create and set delegate for clip corner layers within ASDisplayNode (T…
Browse files Browse the repository at this point in the history
…extureGroup#1029)

* Create and use ASDisplayNodeCornerLayerDelegate

* Return kCFNull for actionForLayer:forKey:
  • Loading branch information
maicki authored and nguyenhuy committed Jul 18, 2018
1 parent db0f515 commit b1f6030
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 46 deletions.
8 changes: 8 additions & 0 deletions AsyncDisplayKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
6900C5F41E8072DA00BCD75C /* ASImageNode+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 6900C5F31E8072DA00BCD75C /* ASImageNode+Private.h */; };
6907C2581DC4ECFE00374C66 /* ASObjectDescriptionHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 6907C2561DC4ECFE00374C66 /* ASObjectDescriptionHelpers.h */; settings = {ATTRIBUTES = (Public, ); }; };
6907C25A1DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 6907C2571DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m */; };
690BC8C120F6D3490052A434 /* ASDisplayNodeCornerLayerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 690BC8BF20F6D3490052A434 /* ASDisplayNodeCornerLayerDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
690BC8C220F6D3490052A434 /* ASDisplayNodeCornerLayerDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 690BC8C020F6D3490052A434 /* ASDisplayNodeCornerLayerDelegate.m */; };
690C35621E055C5D00069B91 /* ASDimensionInternal.mm in Sources */ = {isa = PBXBuildFile; fileRef = 690C35601E055C5D00069B91 /* ASDimensionInternal.mm */; };
690C35641E055C7B00069B91 /* ASDimensionInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 690C35631E055C7B00069B91 /* ASDimensionInternal.h */; settings = {ATTRIBUTES = (Public, ); }; };
690ED58E1E36BCA6000627C0 /* ASLayoutElementStylePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 690ED58D1E36BCA6000627C0 /* ASLayoutElementStylePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -691,6 +693,8 @@
6900C5F31E8072DA00BCD75C /* ASImageNode+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ASImageNode+Private.h"; sourceTree = "<group>"; };
6907C2561DC4ECFE00374C66 /* ASObjectDescriptionHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASObjectDescriptionHelpers.h; sourceTree = "<group>"; };
6907C2571DC4ECFE00374C66 /* ASObjectDescriptionHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASObjectDescriptionHelpers.m; sourceTree = "<group>"; };
690BC8BF20F6D3490052A434 /* ASDisplayNodeCornerLayerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ASDisplayNodeCornerLayerDelegate.h; sourceTree = "<group>"; };
690BC8C020F6D3490052A434 /* ASDisplayNodeCornerLayerDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASDisplayNodeCornerLayerDelegate.m; sourceTree = "<group>"; };
690C35601E055C5D00069B91 /* ASDimensionInternal.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASDimensionInternal.mm; sourceTree = "<group>"; };
690C35631E055C7B00069B91 /* ASDimensionInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASDimensionInternal.h; sourceTree = "<group>"; };
690ED58D1E36BCA6000627C0 /* ASLayoutElementStylePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASLayoutElementStylePrivate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1483,6 +1487,8 @@
058D0A0A195D050800B7D73C /* ASDisplayNode+DebugTiming.mm */,
DE6EA3211C14000600183B10 /* ASDisplayNode+FrameworkPrivate.h */,
058D0A0B195D050800B7D73C /* ASDisplayNode+UIViewBridge.mm */,
690BC8BF20F6D3490052A434 /* ASDisplayNodeCornerLayerDelegate.h */,
690BC8C020F6D3490052A434 /* ASDisplayNodeCornerLayerDelegate.m */,
058D0A0C195D050800B7D73C /* ASDisplayNodeInternal.h */,
6959433D1D70815300B0EE1F /* ASDisplayNodeLayout.h */,
6959433C1D70815300B0EE1F /* ASDisplayNodeLayout.mm */,
Expand Down Expand Up @@ -1929,6 +1935,7 @@
254C6B7E1BF94DF4003EC431 /* ASTextKitTailTruncater.h in Headers */,
B35062491B010EFD0018CF92 /* _ASCoreAnimationExtras.h in Headers */,
683F563720E409D700CEB7A3 /* ASDisplayNode+InterfaceState.h in Headers */,
690BC8C120F6D3490052A434 /* ASDisplayNodeCornerLayerDelegate.h in Headers */,
68EE0DBE1C1B4ED300BA1B99 /* ASMainSerialQueue.h in Headers */,
CCCCCCE11EC3EF060087FE10 /* ASTextUtilities.h in Headers */,
B350624B1B010EFD0018CF92 /* _ASPendingState.h in Headers */,
Expand Down Expand Up @@ -2434,6 +2441,7 @@
68355B401CB57A69001D4E68 /* ASImageContainerProtocolCategories.m in Sources */,
E5855DEF1EBB4D83003639AE /* ASCollectionLayoutDefines.m in Sources */,
B35062031B010EFD0018CF92 /* ASImageNode.mm in Sources */,
690BC8C220F6D3490052A434 /* ASDisplayNodeCornerLayerDelegate.m in Sources */,
254C6B821BF94F8A003EC431 /* ASTextKitComponents.mm in Sources */,
34EFC7601B701C8B00AD841F /* ASInsetLayoutSpec.mm in Sources */,
AC6145441D8AFD4F003D62A2 /* ASSection.m in Sources */,
Expand Down
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
- Optimize layout flattening, particularly reducing retain/release operations. [Adlai Holler](https://github.com/Adlai-Holler)
- Create a method to transfer strong C-arrays into immutable NSArrays, reducing retain/release traffic. [Adlai Holler](https://github.com/Adlai-Holler)
- Remove yoga layout spec, which has been superseded by tighter Yoga integration (`ASDisplayNode+Yoga.h`)
- Properly consider node for responder methods [Michael Schneider](https://github.com/maicki)
- [IGListKit] Adds missing UIScrollViewDelegate method to DataSource proxy [Sergey Pronin](https://github.com/wannabehero)
- Properly consider node for responder methods [Michael Schneider](https://github.com/maicki)
- [IGListKit] Adds missing UIScrollViewDelegate method to DataSource proxy [Sergey Pronin](https://github.com/wannabehero)
- Fix misleading/scary stack trace shown when an assertion occurs during node measurement [Huy Nguyen](https://github.com/nguyenhuy) [#1022](https://github.com/TextureGroup/Texture/pull/1022)
- Fix build on 32-bit simulator in Xcode 9.3 and later, caused by `Thread-local storage is not supported on this architecture.` [Adlai Holler](https://github.com/Adlai-Holler)
- Enable locking assertions (and add some more) to improve and enforce locking safety within the framework [Huy Nguyen](https://github.com/nguyenhuy) [#1024](https://github.com/TextureGroup/Texture/pull/1024)
- Split MapKit, Photos, and AssetsLibrary dependent code into separate subspecs to improve binary size and start time when they're not needed. The default subspec includes all three for backwards compatibility, but this **will change in 3.0**. When using non-Cocoapods build environments, define `AS_USE_PHOTOS, AS_USE_MAPKIT, AS_USE_ASSETS_LIBRARY` to 1 respectively to signal their use. [Adlai Holler](https://github.com/Adlai-Holler)
- Optimization: Removed an NSMutableArray in flattened layouts. [Adlai Holler](https://github.com/Adlai-Holler)
- Reduced binary size by disabling exception support (which we don't use.) [Adlai Holler](https://github.com/Adlai-Holler)
- Create and set delegate for clip corner layers within ASDisplayNode [Michael Schneider](https://github.com/maicki) [#1024](https://github.com/TextureGroup/Texture/pull/1029)

## 2.7
- Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877)
- [ASTextNode2] Upgrade lock safety by protecting all ivars (including rarely-changed ones).
- User FLT_EPSILON in ASCeilPixelValue and ASFloorPixelValue to help with floating point precision errors when computing layouts for 3x devices. [Ricky Cancro](https://github.com/rcancro) [#838](https://github.com/TextureGroup/Texture/pull/864)
- Disable interface colescing and match to pre-colescing interface update behavior [Max Wang](https://github.com/wsdwsd0829) [#862](https://github.com/TextureGroup/Texture/pull/862)
- Disable interface colescing and match to pre-colescing interface update behavior [Max Wang](https://github.com/wsdwsd0829) [#862](https://github.com/TextureGroup/Texture/pull/862)
- [ASDisplayNode] Add safeAreaInsets, layoutMargins and related properties to ASDisplayNode, with full support for older OS versions [Yevgen Pogribnyi](https://github.com/ypogribnyi) [#685](https://github.com/TextureGroup/Texture/pull/685)
- [ASPINRemoteImageDownloader] Allow cache to provide animated image. [Max Wang](https://github.com/wsdwsd0829) [#850](https://github.com/TextureGroup/Texture/pull/850)
- [tvOS] Fixes errors when building against tvOS SDK [Alex Hill](https://github.com/alexhillc) [#728](https://github.com/TextureGroup/Texture/pull/728)
Expand Down Expand Up @@ -63,7 +64,8 @@
- Optimized ASNetworkImageNode loading and resolved edge cases where the image provided to the delegate was not the image that was loaded. [Adlai Holler](https://github.com/Adlai-Holler) [#778](https://github.com/TextureGroup/Texture/pull/778/)
- Make `ASCellNode` tint color apply to table view cell accessories. [Vladyslav Chapaev](https://github.com/ShogunPhyched) [#764](https://github.com/TextureGroup/Texture/pull/764)
- Fix ASTextNode2 is accessing backgroundColor off main while sizing / layout is happening. [Michael Schneider](https://github.com/maicki) [#794](https://github.com/TextureGroup/Texture/pull/778/)
- Pass scrollViewWillEndDragging delegation through in ASIGListAdapterDataSource for IGListKit integration. [#796](https://github.com/TextureGroup/Texture/pull/796)
- Pass scrollViewWillEndDragging delegation through in ASIGListAdapterDataSource for IGListKit integration. [#796](https://github.com/TextureGro
- up/Texture/pull/796)
- Fix UIResponder handling with view backing ASDisplayNode. [Michael Schneider](https://github.com/maicki) [#789](https://github.com/TextureGroup/Texture/pull/789/)
- Optimized thread-local storage by replacing pthread_specific with C11 thread-local variables. [Adlai Holler](https://github.com/Adlai-Holler) [#811](https://github.com/TextureGroup/Texture/pull/811/)
- Fixed a thread-sanitizer warning in ASTextNode. [Adlai Holler](https://github.com/Adlai-Holler) [#830](https://github.com/TextureGroup/Texture/pull/830/)
Expand Down
72 changes: 36 additions & 36 deletions Source/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -624,10 +624,10 @@ AS_EXTERN NSInteger const ASDefaultDrawingPriority;
*/
- (void)layoutIfNeeded;

@property CGRect frame; // default=CGRectZero
@property CGRect bounds; // default=CGRectZero
@property CGPoint position; // default=CGPointZero
@property CGFloat alpha; // default=1.0f
@property CGRect frame; // default=CGRectZero
@property CGRect bounds; // default=CGRectZero
@property CGPoint position; // default=CGPointZero
@property CGFloat alpha; // default=1.0f

/* @abstract Sets the corner rounding method to use on the ASDisplayNode.
* There are three types of corner rounding provided by Texture: CALayer, Precomposited, and Clipping.
Expand All @@ -651,7 +651,7 @@ AS_EXTERN NSInteger const ASDefaultDrawingPriority;
*
* @default ASCornerRoundingTypeDefaultSlowCALayer
*/
@property ASCornerRoundingType cornerRoundingType; // default=Slow CALayer .cornerRadius (offscreen rendering)
@property ASCornerRoundingType cornerRoundingType; // default=ASCornerRoundingTypeDefaultSlowCALayer .cornerRadius (offscreen rendering)

/** @abstract The radius to use when rounding corners of the ASDisplayNode.
*
Expand All @@ -660,24 +660,24 @@ AS_EXTERN NSInteger const ASDefaultDrawingPriority;
*/
@property CGFloat cornerRadius; // default=0.0

@property BOOL clipsToBounds; // default==NO
@property (getter=isHidden) BOOL hidden; // default==NO
@property (getter=isOpaque) BOOL opaque; // default==YES
@property BOOL clipsToBounds; // default==NO
@property (getter=isHidden) BOOL hidden; // default==NO
@property (getter=isOpaque) BOOL opaque; // default==YES

@property (nullable) id contents; // default=nil
@property CGRect contentsRect; // default={0,0,1,1}. @see CALayer.h for details.
@property CGRect contentsCenter; // default={0,0,1,1}. @see CALayer.h for details.
@property CGFloat contentsScale; // default=1.0f. See @contentsScaleForDisplay for details.
@property CGFloat rasterizationScale; // default=1.0f.
@property (nullable) id contents; // default=nil
@property CGRect contentsRect; // default={0,0,1,1}. @see CALayer.h for details.
@property CGRect contentsCenter; // default={0,0,1,1}. @see CALayer.h for details.
@property CGFloat contentsScale; // default=1.0f. See @contentsScaleForDisplay for details.
@property CGFloat rasterizationScale; // default=1.0f.

@property CGPoint anchorPoint; // default={0.5, 0.5}
@property CGFloat zPosition; // default=0.0
@property CATransform3D transform; // default=CATransform3DIdentity
@property CATransform3D subnodeTransform; // default=CATransform3DIdentity
@property CGPoint anchorPoint; // default={0.5, 0.5}
@property CGFloat zPosition; // default=0.0
@property CATransform3D transform; // default=CATransform3DIdentity
@property CATransform3D subnodeTransform; // default=CATransform3DIdentity

@property (getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // default=YES (NO for layer-backed nodes)
#if TARGET_OS_IOS
@property (getter=isExclusiveTouch) BOOL exclusiveTouch; // default=NO
@property (getter=isExclusiveTouch) BOOL exclusiveTouch; // default=NO
#endif

/**
Expand All @@ -686,10 +686,10 @@ AS_EXTERN NSInteger const ASDefaultDrawingPriority;
* @discussion In contrast to UIView, setting a transparent color will not set opaque = NO.
* This only affects nodes that implement +drawRect like ASTextNode.
*/
@property (nullable, copy) UIColor *backgroundColor; // default=nil
@property (nullable, copy) UIColor *backgroundColor; // default=nil

@property (null_resettable, copy) UIColor *tintColor; // default=Blue
- (void)tintColorDidChange; // Notifies the node when the tintColor has changed.
@property (null_resettable, copy) UIColor *tintColor; // default=Blue
- (void)tintColorDidChange; // Notifies the node when the tintColor has changed.

/**
* @abstract A flag used to determine how a node lays out its content when its bounds change.
Expand All @@ -699,24 +699,24 @@ AS_EXTERN NSInteger const ASDefaultDrawingPriority;
* Thus, UIViewContentModeRedraw is not allowed; use needsDisplayOnBoundsChange = YES instead, and pick an appropriate
* contentMode for your content while it's being re-rendered.
*/
@property UIViewContentMode contentMode; // default=UIViewContentModeScaleToFill
@property (copy) NSString *contentsGravity; // Use .contentMode in preference when possible.
@property UISemanticContentAttribute semanticContentAttribute;
@property UIViewContentMode contentMode; // default=UIViewContentModeScaleToFill
@property (copy) NSString *contentsGravity; // Use .contentMode in preference when possible.
@property UISemanticContentAttribute semanticContentAttribute;

@property (nullable) CGColorRef shadowColor; // default=opaque rgb black
@property CGFloat shadowOpacity; // default=0.0
@property CGSize shadowOffset; // default=(0, -3)
@property CGFloat shadowRadius; // default=3
@property CGFloat borderWidth; // default=0
@property (nullable) CGColorRef borderColor; // default=opaque rgb black
@property (nullable) CGColorRef shadowColor; // default=opaque rgb black
@property CGFloat shadowOpacity; // default=0.0
@property CGSize shadowOffset; // default=(0, -3)
@property CGFloat shadowRadius; // default=3
@property CGFloat borderWidth; // default=0
@property (nullable) CGColorRef borderColor; // default=opaque rgb black

@property BOOL allowsGroupOpacity;
@property BOOL allowsEdgeAntialiasing;
@property unsigned int edgeAntialiasingMask; // default==all values from CAEdgeAntialiasingMask
@property BOOL allowsGroupOpacity;
@property BOOL allowsEdgeAntialiasing;
@property unsigned int edgeAntialiasingMask; // default==all values from CAEdgeAntialiasingMask

@property BOOL needsDisplayOnBoundsChange; // default==NO
@property BOOL autoresizesSubviews; // default==YES (undefined for layer-backed nodes)
@property UIViewAutoresizing autoresizingMask; // default==UIViewAutoresizingNone (undefined for layer-backed nodes)
@property BOOL needsDisplayOnBoundsChange; // default==NO
@property BOOL autoresizesSubviews; // default==YES (undefined for layer-backed nodes)
@property UIViewAutoresizing autoresizingMask; // default==UIViewAutoresizingNone (undefined for layer-backed nodes)

/**
* @abstract Content margins
Expand Down
16 changes: 11 additions & 5 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#import <AsyncDisplayKit/ASDimension.h>
#import <AsyncDisplayKit/ASDisplayNodeExtras.h>
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
#import <AsyncDisplayKit/ASDisplayNodeCornerLayerDelegate.h>
#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h>
#import <AsyncDisplayKit/ASDisplayNode+InterfaceState.h>
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
Expand Down Expand Up @@ -1642,7 +1643,7 @@ - (void)_layoutClipCornersIfNeeded
}

CGSize boundsSize = self.bounds.size;
for (int idx = 0; idx < 4; idx++) {
for (int idx = 0; idx < NUM_CLIP_CORNER_LAYERS; idx++) {
BOOL isTop = (idx == 0 || idx == 1);
BOOL isRight = (idx == 1 || idx == 2);
if (_clipCornerLayers[idx]) {
Expand All @@ -1656,7 +1657,7 @@ - (void)_layoutClipCornersIfNeeded
- (void)_updateClipCornerLayerContentsWithRadius:(CGFloat)radius backgroundColor:(UIColor *)backgroundColor
{
ASPerformBlockOnMainThread(^{
for (int idx = 0; idx < 4; idx++) {
for (int idx = 0; idx < NUM_CLIP_CORNER_LAYERS; idx++) {
// Layers are, in order: Top Left, Top Right, Bottom Right, Bottom Left.
// anchorPoint is Bottom Left at 0,0 and Top Right at 1,1.
BOOL isTop = (idx == 0 || idx == 1);
Expand Down Expand Up @@ -1693,16 +1694,21 @@ - (void)_setClipCornerLayersVisible:(BOOL)visible
ASPerformBlockOnMainThread(^{
ASDisplayNodeAssertMainThread();
if (visible) {
for (int idx = 0; idx < 4; idx++) {
for (int idx = 0; idx < NUM_CLIP_CORNER_LAYERS; idx++) {
if (_clipCornerLayers[idx] == nil) {
static ASDisplayNodeCornerLayerDelegate *clipCornerLayers;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
clipCornerLayers = [[ASDisplayNodeCornerLayerDelegate alloc] init];
});
_clipCornerLayers[idx] = [[CALayer alloc] init];
_clipCornerLayers[idx].zPosition = 99999;
_clipCornerLayers[idx].delegate = self;
_clipCornerLayers[idx].delegate = clipCornerLayers;
}
}
[self _updateClipCornerLayerContentsWithRadius:_cornerRadius backgroundColor:self.backgroundColor];
} else {
for (int idx = 0; idx < 4; idx++) {
for (int idx = 0; idx < NUM_CLIP_CORNER_LAYERS; idx++) {
[_clipCornerLayers[idx] removeFromSuperlayer];
_clipCornerLayers[idx] = nil;
}
Expand Down
Loading

0 comments on commit b1f6030

Please sign in to comment.