Skip to content

Commit a17f394

Browse files
committed
Revert "Add layer-action support to nodes (#1396)"
This reverts commit 34f1621.
1 parent 1726148 commit a17f394

10 files changed

+26
-82
lines changed

Source/ASDisplayNode+Subclasses.h

-7
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,6 @@ AS_CATEGORY_IMPLEMENTABLE
376376
*/
377377
@property (readonly) CGFloat contentsScaleForDisplay;
378378

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

387380
#pragma mark - Touch handling
388381
/** @name Touch handling */

Source/ASDisplayNode.h

-2
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,6 @@ AS_EXTERN NSInteger const ASDefaultDrawingPriority;
694694
@property (getter=isExclusiveTouch) BOOL exclusiveTouch; // default=NO
695695
#endif
696696

697-
@property (nullable, copy) NSDictionary<NSString *, id<CAAction>> *actions; // default = nil
698-
699697
/**
700698
* @abstract The node view's background color.
701699
*

Source/ASDisplayNode.mm

+11-11
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@
6464

6565
static ASDisplayNodeNonFatalErrorBlock _nonFatalErrorBlock = nil;
6666

67-
@interface ASDisplayNode () <UIGestureRecognizerDelegate, _ASDisplayLayerDelegate, ASCATransactionQueueObserving>
67+
// Forward declare CALayerDelegate protocol as the iOS 10 SDK moves CALayerDelegate from an informal delegate to a protocol.
68+
// We have to forward declare the protocol as this place otherwise it will not compile compiling with an Base SDK < iOS 10
69+
@protocol CALayerDelegate;
70+
71+
@interface ASDisplayNode () <UIGestureRecognizerDelegate, CALayerDelegate, _ASDisplayLayerDelegate, ASCATransactionQueueObserving>
6872
/**
6973
* See ASDisplayNodeInternal.h for ivars
7074
*/
@@ -103,13 +107,9 @@ BOOL ASDisplayNodeNeedsSpecialPropertiesHandling(BOOL isSynchronous, BOOL isLaye
103107
return result;
104108
}
105109

106-
void StubImplementationWithNoArgs(id receiver, SEL _cmd) {}
107-
void StubImplementationWithSizeRange(id receiver, SEL _cmd, ASSizeRange sr) {}
108-
void StubImplementationWithTwoInterfaceStates(id receiver, SEL _cmd, ASInterfaceState s0, ASInterfaceState s1) {}
109-
110-
/// Returning nil here won't trigger unwanted default actions, because we override
111-
/// +defaultActionForKey: to return kCFNull.
112-
id StubLayerActionImplementation(id receiver, SEL _cmd, NSString *key) { return nil; }
110+
void StubImplementationWithNoArgs(id receiver) {}
111+
void StubImplementationWithSizeRange(id receiver, ASSizeRange sr) {}
112+
void StubImplementationWithTwoInterfaceStates(id receiver, ASInterfaceState s0, ASInterfaceState s1) {}
113113

114114
/**
115115
* Returns ASDisplayNodeFlags for the given class/instance. instance MAY BE NIL.
@@ -264,8 +264,6 @@ + (void)initialize
264264
auto interfaceStateType = std::string(@encode(ASInterfaceState));
265265
auto type1 = "v@:" + interfaceStateType + interfaceStateType;
266266
class_addMethod(self, @selector(interfaceStateDidChange:fromState:), (IMP)StubImplementationWithTwoInterfaceStates, type1.c_str());
267-
268-
class_addMethod(self, @selector(layerActionForKey:), (IMP)StubLayerActionImplementation, "@@:@");
269267
}
270268
}
271269

@@ -1720,6 +1718,7 @@ - (void)subnodeDisplayDidFinish:(ASDisplayNode *)subnode
17201718

17211719
#pragma mark <CALayerDelegate>
17221720

1721+
// We are only the delegate for the layer when we are layer-backed, as UIView performs this function normally
17231722
- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
17241723
{
17251724
if (event == kCAOnOrderIn) {
@@ -1728,7 +1727,8 @@ - (void)subnodeDisplayDidFinish:(ASDisplayNode *)subnode
17281727
[self __exitHierarchy];
17291728
}
17301729

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

17341734
#pragma mark - Error Handling

Source/Details/UIView+ASConvenience.h

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ NS_ASSUME_NONNULL_BEGIN
4343
@property (nonatomic) BOOL allowsGroupOpacity;
4444
@property (nonatomic) BOOL allowsEdgeAntialiasing;
4545
@property (nonatomic) unsigned int edgeAntialiasingMask;
46-
@property (nonatomic, nullable, copy) NSDictionary<NSString *, id<CAAction>> *actions;
4746

4847
- (void)setNeedsDisplay;
4948
- (void)setNeedsLayout;

Source/Details/_ASDisplayLayer.mm

-7
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,6 @@ - (void)setNeedsDisplay
115115

116116
#pragma mark -
117117

118-
+ (id<CAAction>)defaultActionForKey:(NSString *)event
119-
{
120-
// We never want to run one of CA's root default actions. So if we return nil from actionForLayer:forKey:, and let CA
121-
// dig into the actions dictionary, and it doesn't find it there, it will check here and we need to stop the search.
122-
return (id)kCFNull;
123-
}
124-
125118
+ (dispatch_queue_t)displayQueue
126119
{
127120
static dispatch_queue_t displayQueue = NULL;

Source/Details/_ASDisplayView.mm

+13-10
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,22 @@ - (NSString *)description
8484

8585
#pragma mark - UIView Overrides
8686

87-
- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
87+
- (void)willMoveToWindow:(UIWindow *)newWindow
8888
{
89-
id<CAAction> uikitAction = [super actionForLayer:layer forKey:event];
90-
91-
// Even though the UIKit action will take precedence, we still unconditionally forward to the node so that it can
92-
// track events like kCAOnOrderIn.
93-
id<CAAction> nodeAction = [_asyncdisplaykit_node actionForLayer:layer forKey:event];
89+
ASDisplayNode *node = _asyncdisplaykit_node; // Create strong reference to weak ivar.
90+
BOOL visible = (newWindow != nil);
91+
if (visible && !node.inHierarchy) {
92+
[node __enterHierarchy];
93+
}
94+
}
9495

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

102105
- (void)willMoveToSuperview:(UIView *)newSuperview

Source/Private/ASDisplayNode+UIViewBridge.mm

-12
Original file line numberDiff line numberDiff line change
@@ -986,18 +986,6 @@ - (void)setInsetsLayoutMarginsFromSafeArea:(BOOL)insetsLayoutMarginsFromSafeArea
986986
}
987987
}
988988

989-
- (NSDictionary<NSString *,id<CAAction>> *)actions
990-
{
991-
_bridge_prologue_read;
992-
return _getFromLayer(actions);
993-
}
994-
995-
- (void)setActions:(NSDictionary<NSString *,id<CAAction>> *)actions
996-
{
997-
_bridge_prologue_write;
998-
_setToLayer(actions, actions);
999-
}
1000-
1001989
- (void)safeAreaInsetsDidChange
1002990
{
1003991
ASDisplayNodeAssertMainThread();

Source/Private/ASDisplayNodeInternal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static constexpr CACornerMask kASCACornerAllCorners =
7474

7575
#define NUM_CLIP_CORNER_LAYERS 4
7676

77-
@interface ASDisplayNode () <_ASTransitionContextCompletionDelegate, CALayerDelegate>
77+
@interface ASDisplayNode () <_ASTransitionContextCompletionDelegate>
7878
{
7979
@package
8080
AS::RecursiveMutex __instanceLock__;

Source/Private/_ASPendingState.mm

+1-17
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,9 @@
8787
int setLayoutMargins:1;
8888
int setPreservesSuperviewLayoutMargins:1;
8989
int setInsetsLayoutMarginsFromSafeArea:1;
90-
int setActions:1;
9190
int setMaskedCorners : 1;
9291
} ASPendingStateFlags;
9392

94-
9593
static constexpr ASPendingStateFlags kZeroFlags = {0};
9694

9795
@implementation _ASPendingState
@@ -140,7 +138,6 @@ @implementation _ASPendingState
140138
CGPoint accessibilityActivationPoint;
141139
UIBezierPath *accessibilityPath;
142140
UISemanticContentAttribute semanticContentAttribute API_AVAILABLE(ios(9.0), tvos(9.0));
143-
NSDictionary<NSString *, id<CAAction>> *actions;
144141

145142
ASPendingStateFlags _stateToApplyFlags;
146143
struct {
@@ -221,7 +218,6 @@ ASDISPLAYNODE_INLINE void ASPendingStateApplyMetricsToLayer(_ASPendingState *sta
221218
@synthesize layoutMargins=layoutMargins;
222219
@synthesize preservesSuperviewLayoutMargins=preservesSuperviewLayoutMargins;
223220
@synthesize insetsLayoutMarginsFromSafeArea=insetsLayoutMarginsFromSafeArea;
224-
@synthesize actions=actions;
225221
@synthesize maskedCorners = maskedCorners;
226222

227223
static CGColorRef blackColorRef = NULL;
@@ -667,12 +663,6 @@ - (void)setSemanticContentAttribute:(UISemanticContentAttribute)attribute API_AV
667663
_stateToApplyFlags.setSemanticContentAttribute = YES;
668664
}
669665

670-
- (void)setActions:(NSDictionary<NSString *,id<CAAction>> *)actionsArg
671-
{
672-
actions = [actionsArg copy];
673-
_stateToApplyFlags.setActions = YES;
674-
}
675-
676666
- (BOOL)isAccessibilityElement
677667
{
678668
return _flags.isAccessibilityElement;
@@ -1023,9 +1013,6 @@ - (void)applyToLayer:(CALayer *)layer
10231013
if (flags.setOpaque)
10241014
ASDisplayNodeAssert(layer.opaque == _flags.opaque, @"Didn't set opaque as desired");
10251015

1026-
if (flags.setActions)
1027-
layer.actions = actions;
1028-
10291016
ASPendingStateApplyMetricsToLayer(self, layer);
10301017

10311018
if (flags.needsLayout)
@@ -1045,7 +1032,7 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
10451032
because a different setter would be called.
10461033
*/
10471034

1048-
unowned CALayer *layer = view.layer;
1035+
CALayer *layer = view.layer;
10491036

10501037
ASPendingStateFlags flags = _stateToApplyFlags;
10511038
if (__shouldSetNeedsDisplay(layer)) {
@@ -1088,9 +1075,6 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
10881075
if (flags.setRasterizationScale)
10891076
layer.rasterizationScale = rasterizationScale;
10901077

1091-
if (flags.setActions)
1092-
layer.actions = actions;
1093-
10941078
if (flags.setClipsToBounds)
10951079
view.clipsToBounds = _flags.clipsToBounds;
10961080

Tests/ASDisplayNodeTests.mm

-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#import <QuartzCore/QuartzCore.h>
1111
#import <XCTest/XCTest.h>
12-
#import <OCMock/OCMock.h>
1312

1413
#import <AsyncDisplayKit/_ASDisplayLayer.h>
1514
#import <AsyncDisplayKit/_ASDisplayView.h>
@@ -2713,17 +2712,4 @@ - (void)testCornerRoundingTypeClippingRoundedCornersIsUsingASDisplayNodeCornerLa
27132712
}
27142713
}
27152714

2716-
- (void)testLayerActionForKeyIsCalled
2717-
{
2718-
UIWindow *window = [[UIWindow alloc] init];
2719-
ASDisplayNode *node = [[ASDisplayNode alloc] init];
2720-
2721-
id mockNode = OCMPartialMock(node);
2722-
OCMExpect([mockNode layerActionForKey:kCAOnOrderIn]);
2723-
[window.layer addSublayer:node.layer];
2724-
OCMExpect([mockNode layerActionForKey:@"position"]);
2725-
node.layer.position = CGPointMake(10, 10);
2726-
OCMVerifyAll(mockNode);
2727-
}
2728-
27292715
@end

0 commit comments

Comments
 (0)