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 24, 2019
1 parent bb6c89e commit a9366b1
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 83 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
22 changes: 11 additions & 11 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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 @@ -102,13 +106,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) {}

/// Returning nil here won't trigger unwanted default actions, because we override
/// +defaultActionForKey: to return kCFNull.
id StubLayerActionImplementation(id receiver, SEL _cmd, NSString *key) { return nil; }
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 @@ -280,8 +280,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 @@ -1810,6 +1808,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 @@ -1818,7 +1817,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
20 changes: 2 additions & 18 deletions Source/Private/_ASPendingState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@
int setLayoutMargins:1;
int setPreservesSuperviewLayoutMargins:1;
int setInsetsLayoutMarginsFromSafeArea:1;
int setActions:1;
int setMaskedCorners : 1;
} ASPendingStateFlags;


static constexpr ASPendingStateFlags kZeroFlags = {0};

@implementation _ASPendingState
Expand Down Expand Up @@ -147,7 +145,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 @@ -217,7 +214,6 @@ ASDISPLAYNODE_INLINE void ASPendingStateApplyMetricsToLayer(_ASPendingState *sta
@synthesize layoutMargins=layoutMargins;
@synthesize preservesSuperviewLayoutMargins=preservesSuperviewLayoutMargins;
@synthesize insetsLayoutMarginsFromSafeArea=insetsLayoutMarginsFromSafeArea;
@synthesize actions=actions;
@synthesize maskedCorners = maskedCorners;

static CGColorRef blackColorRef = NULL;
Expand Down Expand Up @@ -603,12 +599,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 @@ -959,9 +949,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 @@ -981,7 +968,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 @@ -1024,9 +1011,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 @@ -1323,7 +1307,7 @@ + (_ASPendingState *)pendingViewStateFromView:(UIView *)view

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

- (BOOL)hasSetNeedsLayout
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 @@ -2713,17 +2712,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 a9366b1

Please sign in to comment.