Skip to content

Commit a9366b1

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

10 files changed

+27
-83
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
@@ -63,7 +63,11 @@
6363

6464
static ASDisplayNodeNonFatalErrorBlock _nonFatalErrorBlock = nil;
6565

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

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

113113
/**
114114
* Returns ASDisplayNodeFlags for the given class/instance. instance MAY BE NIL.
@@ -280,8 +280,6 @@ + (void)initialize
280280
auto interfaceStateType = std::string(@encode(ASInterfaceState));
281281
auto type1 = "v@:" + interfaceStateType + interfaceStateType;
282282
class_addMethod(self, @selector(interfaceStateDidChange:fromState:), (IMP)StubImplementationWithTwoInterfaceStates, type1.c_str());
283-
284-
class_addMethod(self, @selector(layerActionForKey:), (IMP)StubLayerActionImplementation, "@@:@");
285283
}
286284
}
287285

@@ -1810,6 +1808,7 @@ - (void)subnodeDisplayDidFinish:(ASDisplayNode *)subnode
18101808

18111809
#pragma mark <CALayerDelegate>
18121810

1811+
// We are only the delegate for the layer when we are layer-backed, as UIView performs this function normally
18131812
- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
18141813
{
18151814
if (event == kCAOnOrderIn) {
@@ -1818,7 +1817,8 @@ - (void)subnodeDisplayDidFinish:(ASDisplayNode *)subnode
18181817
[self __exitHierarchy];
18191818
}
18201819

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

18241824
#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
@@ -153,19 +153,22 @@ - (NSString *)description
153153

154154
#pragma mark - UIView Overrides
155155

156-
- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
156+
- (void)willMoveToWindow:(UIWindow *)newWindow
157157
{
158-
id<CAAction> uikitAction = [super actionForLayer:layer forKey:event];
159-
160-
// Even though the UIKit action will take precedence, we still unconditionally forward to the node so that it can
161-
// track events like kCAOnOrderIn.
162-
id<CAAction> nodeAction = [_asyncdisplaykit_node actionForLayer:layer forKey:event];
158+
ASDisplayNode *node = _asyncdisplaykit_node; // Create strong reference to weak ivar.
159+
BOOL visible = (newWindow != nil);
160+
if (visible && !node.inHierarchy) {
161+
[node __enterHierarchy];
162+
}
163+
}
163164

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

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

Source/Private/ASDisplayNode+UIViewBridge.mm

-12
Original file line numberDiff line numberDiff line change
@@ -959,18 +959,6 @@ - (void)setInsetsLayoutMarginsFromSafeArea:(BOOL)insetsLayoutMarginsFromSafeArea
959959
}
960960
}
961961

962-
- (NSDictionary<NSString *,id<CAAction>> *)actions
963-
{
964-
_bridge_prologue_read;
965-
return _getFromLayer(actions);
966-
}
967-
968-
- (void)setActions:(NSDictionary<NSString *,id<CAAction>> *)actions
969-
{
970-
_bridge_prologue_write;
971-
_setToLayer(actions, actions);
972-
}
973-
974962
- (void)safeAreaInsetsDidChange
975963
{
976964
ASDisplayNodeAssertMainThread();

Source/Private/ASDisplayNodeInternal.h

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

7979
#define NUM_CLIP_CORNER_LAYERS 4
8080

81-
@interface ASDisplayNode () <_ASTransitionContextCompletionDelegate, CALayerDelegate>
81+
@interface ASDisplayNode () <_ASTransitionContextCompletionDelegate>
8282
{
8383
@package
8484
AS::RecursiveMutex __instanceLock__;

Source/Private/_ASPendingState.mm

+2-18
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
@@ -147,7 +145,6 @@ @implementation _ASPendingState
147145
CGPoint accessibilityActivationPoint;
148146
UIBezierPath *accessibilityPath;
149147
UISemanticContentAttribute semanticContentAttribute API_AVAILABLE(ios(9.0), tvos(9.0));
150-
NSDictionary<NSString *, id<CAAction>> *actions;
151148

152149
ASPendingStateFlags _flags;
153150
}
@@ -217,7 +214,6 @@ ASDISPLAYNODE_INLINE void ASPendingStateApplyMetricsToLayer(_ASPendingState *sta
217214
@synthesize layoutMargins=layoutMargins;
218215
@synthesize preservesSuperviewLayoutMargins=preservesSuperviewLayoutMargins;
219216
@synthesize insetsLayoutMarginsFromSafeArea=insetsLayoutMarginsFromSafeArea;
220-
@synthesize actions=actions;
221217
@synthesize maskedCorners = maskedCorners;
222218

223219
static CGColorRef blackColorRef = NULL;
@@ -603,12 +599,6 @@ - (void)setSemanticContentAttribute:(UISemanticContentAttribute)attribute API_AV
603599
_flags.setSemanticContentAttribute = YES;
604600
}
605601

606-
- (void)setActions:(NSDictionary<NSString *,id<CAAction>> *)actionsArg
607-
{
608-
actions = [actionsArg copy];
609-
_flags.setActions = YES;
610-
}
611-
612602
- (BOOL)isAccessibilityElement
613603
{
614604
return isAccessibilityElement;
@@ -959,9 +949,6 @@ - (void)applyToLayer:(CALayer *)layer
959949
if (flags.setOpaque)
960950
ASDisplayNodeAssert(layer.opaque == opaque, @"Didn't set opaque as desired");
961951

962-
if (flags.setActions)
963-
layer.actions = actions;
964-
965952
ASPendingStateApplyMetricsToLayer(self, layer);
966953

967954
if (flags.needsLayout)
@@ -981,7 +968,7 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
981968
because a different setter would be called.
982969
*/
983970

984-
unowned CALayer *layer = view.layer;
971+
CALayer *layer = view.layer;
985972

986973
ASPendingStateFlags flags = _flags;
987974
if (__shouldSetNeedsDisplay(layer)) {
@@ -1024,9 +1011,6 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
10241011
if (flags.setRasterizationScale)
10251012
layer.rasterizationScale = rasterizationScale;
10261013

1027-
if (flags.setActions)
1028-
layer.actions = actions;
1029-
10301014
if (flags.setClipsToBounds)
10311015
view.clipsToBounds = clipsToBounds;
10321016

@@ -1323,7 +1307,7 @@ + (_ASPendingState *)pendingViewStateFromView:(UIView *)view
13231307

13241308
- (void)clearChanges
13251309
{
1326-
_flags = kZeroFlags;
1310+
_flags = (ASPendingStateFlags){ 0 };
13271311
}
13281312

13291313
- (BOOL)hasSetNeedsLayout

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)