Skip to content

Commit

Permalink
Revert "Add layer-action support to nodes (#1396)"
Browse files Browse the repository at this point in the history
This reverts commit 34f1621.
  • Loading branch information
nguyenhuy committed Apr 1, 2019
1 parent 442317b commit e750dfc
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 82 deletions.
7 changes: 0 additions & 7 deletions Source/ASDisplayNode+Subclasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,6 @@ AS_CATEGORY_IMPLEMENTABLE
*/
@property (readonly) CGFloat contentsScaleForDisplay;

/**
* Called as part of actionForLayer:forKey:. Gives the node a chance to provide a custom action for its layer.
*
* The default implementation returns NSNull, indicating that no action should be taken.
*/
AS_CATEGORY_IMPLEMENTABLE
- (nullable id<CAAction>)layerActionForKey:(NSString *)event;

#pragma mark - Touch handling
/** @name Touch handling */
Expand Down
2 changes: 0 additions & 2 deletions Source/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,6 @@ AS_EXTERN NSInteger const ASDefaultDrawingPriority;
@property (getter=isExclusiveTouch) BOOL exclusiveTouch; // default=NO
#endif

@property (nullable, copy) NSDictionary<NSString *, id<CAAction>> *actions; // default = nil

/**
* @abstract The node view's background color.
*
Expand Down
19 changes: 11 additions & 8 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@

static ASDisplayNodeNonFatalErrorBlock _nonFatalErrorBlock = nil;

@interface ASDisplayNode () <UIGestureRecognizerDelegate, _ASDisplayLayerDelegate, ASCATransactionQueueObserving>
// Forward declare CALayerDelegate protocol as the iOS 10 SDK moves CALayerDelegate from an informal delegate to a protocol.
// We have to forward declare the protocol as this place otherwise it will not compile compiling with an Base SDK < iOS 10
@protocol CALayerDelegate;

@interface ASDisplayNode () <UIGestureRecognizerDelegate, CALayerDelegate, _ASDisplayLayerDelegate, ASCATransactionQueueObserving>
/**
* See ASDisplayNodeInternal.h for ivars
*/
Expand Down Expand Up @@ -103,10 +107,9 @@ BOOL ASDisplayNodeNeedsSpecialPropertiesHandling(BOOL isSynchronous, BOOL isLaye
return result;
}

void StubImplementationWithNoArgs(id receiver, SEL _cmd) {}
void StubImplementationWithSizeRange(id receiver, SEL _cmd, ASSizeRange sr) {}
void StubImplementationWithTwoInterfaceStates(id receiver, SEL _cmd, ASInterfaceState s0, ASInterfaceState s1) {}
id StubLayerActionImplementation(id receiver, SEL _cmd, NSString *key) { return (id)kCFNull; }
void StubImplementationWithNoArgs(id receiver) {}
void StubImplementationWithSizeRange(id receiver, ASSizeRange sr) {}
void StubImplementationWithTwoInterfaceStates(id receiver, ASInterfaceState s0, ASInterfaceState s1) {}

/**
* Returns ASDisplayNodeFlags for the given class/instance. instance MAY BE NIL.
Expand Down Expand Up @@ -278,8 +281,6 @@ + (void)initialize
auto interfaceStateType = std::string(@encode(ASInterfaceState));
auto type1 = "v@:" + interfaceStateType + interfaceStateType;
class_addMethod(self, @selector(interfaceStateDidChange:fromState:), (IMP)StubImplementationWithTwoInterfaceStates, type1.c_str());

class_addMethod(self, @selector(layerActionForKey:), (IMP)StubLayerActionImplementation, "@@:@");
}
}

Expand Down Expand Up @@ -1817,6 +1818,7 @@ - (void)subnodeDisplayDidFinish:(ASDisplayNode *)subnode

#pragma mark <CALayerDelegate>

// We are only the delegate for the layer when we are layer-backed, as UIView performs this function normally
- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
{
if (event == kCAOnOrderIn) {
Expand All @@ -1825,7 +1827,8 @@ - (void)subnodeDisplayDidFinish:(ASDisplayNode *)subnode
[self __exitHierarchy];
}

return [self layerActionForKey:event];
ASDisplayNodeAssert(_flags.layerBacked, @"We shouldn't get called back here unless we are layer-backed.");
return (id)kCFNull;
}

#pragma mark - Error Handling
Expand Down
1 change: 0 additions & 1 deletion Source/Details/UIView+ASConvenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) BOOL allowsGroupOpacity;
@property (nonatomic) BOOL allowsEdgeAntialiasing;
@property (nonatomic) unsigned int edgeAntialiasingMask;
@property (nonatomic, nullable, copy) NSDictionary<NSString *, id<CAAction>> *actions;

- (void)setNeedsDisplay;
- (void)setNeedsLayout;
Expand Down
7 changes: 0 additions & 7 deletions Source/Details/_ASDisplayLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,6 @@ - (void)setNeedsDisplay

#pragma mark -

+ (id<CAAction>)defaultActionForKey:(NSString *)event
{
// We never want to run one of CA's root default actions. So if we return nil from actionForLayer:forKey:, and let CA
// dig into the actions dictionary, and it doesn't find it there, it will check here and we need to stop the search.
return (id)kCFNull;
}

+ (dispatch_queue_t)displayQueue
{
static dispatch_queue_t displayQueue = NULL;
Expand Down
23 changes: 13 additions & 10 deletions Source/Details/_ASDisplayView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,22 @@ - (NSString *)description

#pragma mark - UIView Overrides

- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
- (void)willMoveToWindow:(UIWindow *)newWindow
{
id<CAAction> uikitAction = [super actionForLayer:layer forKey:event];

// Even though the UIKit action will take precedence, we still unconditionally forward to the node so that it can
// track events like kCAOnOrderIn.
id<CAAction> nodeAction = [_asyncdisplaykit_node actionForLayer:layer forKey:event];
ASDisplayNode *node = _asyncdisplaykit_node; // Create strong reference to weak ivar.
BOOL visible = (newWindow != nil);
if (visible && !node.inHierarchy) {
[node __enterHierarchy];
}
}

// If UIKit specifies an action, that takes precedence. That's an animation block so it's explicit.
if (uikitAction && uikitAction != (id)kCFNull) {
return uikitAction;
- (void)didMoveToWindow
{
ASDisplayNode *node = _asyncdisplaykit_node; // Create strong reference to weak ivar.
BOOL visible = (self.window != nil);
if (!visible && node.inHierarchy) {
[node __exitHierarchy];
}
return nodeAction;
}

- (void)willMoveToSuperview:(UIView *)newSuperview
Expand Down
12 changes: 0 additions & 12 deletions Source/Private/ASDisplayNode+UIViewBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -959,18 +959,6 @@ - (void)setInsetsLayoutMarginsFromSafeArea:(BOOL)insetsLayoutMarginsFromSafeArea
}
}

- (NSDictionary<NSString *,id<CAAction>> *)actions
{
_bridge_prologue_read;
return _getFromLayer(actions);
}

- (void)setActions:(NSDictionary<NSString *,id<CAAction>> *)actions
{
_bridge_prologue_write;
_setToLayer(actions, actions);
}

- (void)safeAreaInsetsDidChange
{
ASDisplayNodeAssertMainThread();
Expand Down
2 changes: 1 addition & 1 deletion Source/Private/ASDisplayNodeInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static constexpr CACornerMask kASCACornerAllCorners =

#define NUM_CLIP_CORNER_LAYERS 4

@interface ASDisplayNode () <_ASTransitionContextCompletionDelegate, CALayerDelegate>
@interface ASDisplayNode () <_ASTransitionContextCompletionDelegate>
{
@package
AS::RecursiveMutex __instanceLock__;
Expand Down
88 changes: 68 additions & 20 deletions Source/Private/_ASPendingState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,9 @@
int setLayoutMargins:1;
int setPreservesSuperviewLayoutMargins:1;
int setInsetsLayoutMarginsFromSafeArea:1;
int setActions:1;
int setMaskedCorners : 1;
} ASPendingStateFlags;


static constexpr ASPendingStateFlags kZeroFlags = {0};

@implementation _ASPendingState
{
@package //Expose all ivars for ASDisplayNode to bypass getters for efficiency
Expand Down Expand Up @@ -145,7 +141,6 @@ @implementation _ASPendingState
CGPoint accessibilityActivationPoint;
UIBezierPath *accessibilityPath;
UISemanticContentAttribute semanticContentAttribute API_AVAILABLE(ios(9.0), tvos(9.0));
NSDictionary<NSString *, id<CAAction>> *actions;

ASPendingStateFlags _flags;
}
Expand Down Expand Up @@ -215,8 +210,11 @@ ASDISPLAYNODE_INLINE void ASPendingStateApplyMetricsToLayer(_ASPendingState *sta
@synthesize layoutMargins=layoutMargins;
@synthesize preservesSuperviewLayoutMargins=preservesSuperviewLayoutMargins;
@synthesize insetsLayoutMarginsFromSafeArea=insetsLayoutMarginsFromSafeArea;
<<<<<<< HEAD
@synthesize actions=actions;
@synthesize maskedCorners = maskedCorners;
=======
>>>>>>> parent of 34f16217... Add layer-action support to nodes (#1396)

static CGColorRef blackColorRef = NULL;
static UIColor *defaultTintColor = nil;
Expand Down Expand Up @@ -600,12 +598,6 @@ - (void)setSemanticContentAttribute:(UISemanticContentAttribute)attribute API_AV
_flags.setSemanticContentAttribute = YES;
}

- (void)setActions:(NSDictionary<NSString *,id<CAAction>> *)actionsArg
{
actions = [actionsArg copy];
_flags.setActions = YES;
}

- (BOOL)isAccessibilityElement
{
return isAccessibilityElement;
Expand Down Expand Up @@ -943,9 +935,6 @@ - (void)applyToLayer:(CALayer *)layer
if (flags.setOpaque)
ASDisplayNodeAssert(layer.opaque == opaque, @"Didn't set opaque as desired");

if (flags.setActions)
layer.actions = actions;

ASPendingStateApplyMetricsToLayer(self, layer);

if (flags.needsLayout)
Expand All @@ -965,7 +954,7 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
because a different setter would be called.
*/

unowned CALayer *layer = view.layer;
CALayer *layer = view.layer;

ASPendingStateFlags flags = _flags;
if (__shouldSetNeedsDisplay(layer)) {
Expand Down Expand Up @@ -1008,9 +997,6 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
if (flags.setRasterizationScale)
layer.rasterizationScale = rasterizationScale;

if (flags.setActions)
layer.actions = actions;

if (flags.setClipsToBounds)
view.clipsToBounds = clipsToBounds;

Expand Down Expand Up @@ -1304,7 +1290,7 @@ + (_ASPendingState *)pendingViewStateFromView:(UIView *)view

- (void)clearChanges
{
_flags = kZeroFlags;
_flags = (ASPendingStateFlags){ 0 };
}

- (BOOL)hasSetNeedsLayout
Expand All @@ -1319,7 +1305,69 @@ - (BOOL)hasSetNeedsDisplay

- (BOOL)hasChanges
{
return memcmp(&_flags, &kZeroFlags, sizeof(ASPendingStateFlags));
ASPendingStateFlags flags = _flags;

return (flags.setAnchorPoint
|| flags.setPosition
|| flags.setZPosition
|| flags.setFrame
|| flags.setBounds
|| flags.setPosition
|| flags.setTransform
|| flags.setSublayerTransform
|| flags.setContents
|| flags.setContentsGravity
|| flags.setContentsRect
|| flags.setContentsCenter
|| flags.setContentsScale
|| flags.setRasterizationScale
|| flags.setClipsToBounds
|| flags.setBackgroundColor
|| flags.setTintColor
|| flags.setHidden
|| flags.setAlpha
|| flags.setCornerRadius
|| flags.setContentMode
|| flags.setUserInteractionEnabled
|| flags.setExclusiveTouch
|| flags.setShadowOpacity
|| flags.setShadowOffset
|| flags.setShadowRadius
|| flags.setShadowColor
|| flags.setBorderWidth
|| flags.setBorderColor
|| flags.setAutoresizingMask
|| flags.setAutoresizesSubviews
|| flags.setNeedsDisplayOnBoundsChange
|| flags.setAllowsGroupOpacity
|| flags.setAllowsEdgeAntialiasing
|| flags.setEdgeAntialiasingMask
|| flags.needsDisplay
|| flags.needsLayout
|| flags.setAsyncTransactionContainer
|| flags.setOpaque
|| flags.setSemanticContentAttribute
|| flags.setLayoutMargins
|| flags.setPreservesSuperviewLayoutMargins
|| flags.setInsetsLayoutMarginsFromSafeArea
|| flags.setIsAccessibilityElement
|| flags.setAccessibilityLabel
|| flags.setAccessibilityAttributedLabel
|| flags.setAccessibilityHint
|| flags.setAccessibilityAttributedHint
|| flags.setAccessibilityValue
|| flags.setAccessibilityAttributedValue
|| flags.setAccessibilityTraits
|| flags.setAccessibilityFrame
|| flags.setAccessibilityLanguage
|| flags.setAccessibilityElementsHidden
|| flags.setAccessibilityViewIsModal
|| flags.setShouldGroupAccessibilityChildren
|| flags.setAccessibilityIdentifier
|| flags.setAccessibilityNavigationStyle
|| flags.setAccessibilityHeaderElements
|| flags.setAccessibilityActivationPoint
|| flags.setAccessibilityPath);
}

- (void)dealloc
Expand Down
14 changes: 0 additions & 14 deletions Tests/ASDisplayNodeTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#import <QuartzCore/QuartzCore.h>
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>

#import <AsyncDisplayKit/_ASDisplayLayer.h>
#import <AsyncDisplayKit/_ASDisplayView.h>
Expand Down Expand Up @@ -2698,17 +2697,4 @@ - (void)testCornerRoundingTypeClippingRoundedCornersIsUsingASDisplayNodeCornerLa
}
}

- (void)testLayerActionForKeyIsCalled
{
UIWindow *window = [[UIWindow alloc] init];
ASDisplayNode *node = [[ASDisplayNode alloc] init];

id mockNode = OCMPartialMock(node);
OCMExpect([mockNode layerActionForKey:kCAOnOrderIn]);
[window.layer addSublayer:node.layer];
OCMExpect([mockNode layerActionForKey:@"position"]);
node.layer.position = CGPointMake(10, 10);
OCMVerifyAll(mockNode);
}

@end

0 comments on commit e750dfc

Please sign in to comment.