Skip to content

Commit e380322

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

10 files changed

+27
-80
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-8
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,10 +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-
id StubLayerActionImplementation(id receiver, SEL _cmd, NSString *key) { return (id)kCFNull; }
110+
void StubImplementationWithNoArgs(id receiver) {}
111+
void StubImplementationWithSizeRange(id receiver, ASSizeRange sr) {}
112+
void StubImplementationWithTwoInterfaceStates(id receiver, ASInterfaceState s0, ASInterfaceState s1) {}
110113

111114
/**
112115
* Returns ASDisplayNodeFlags for the given class/instance. instance MAY BE NIL.
@@ -278,8 +281,6 @@ + (void)initialize
278281
auto interfaceStateType = std::string(@encode(ASInterfaceState));
279282
auto type1 = "v@:" + interfaceStateType + interfaceStateType;
280283
class_addMethod(self, @selector(interfaceStateDidChange:fromState:), (IMP)StubImplementationWithTwoInterfaceStates, type1.c_str());
281-
282-
class_addMethod(self, @selector(layerActionForKey:), (IMP)StubLayerActionImplementation, "@@:@");
283284
}
284285
}
285286

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

18181819
#pragma mark <CALayerDelegate>
18191820

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

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

18311834
#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
@@ -86,11 +86,9 @@
8686
int setLayoutMargins:1;
8787
int setPreservesSuperviewLayoutMargins:1;
8888
int setInsetsLayoutMarginsFromSafeArea:1;
89-
int setActions:1;
9089
int setMaskedCorners : 1;
9190
} ASPendingStateFlags;
9291

93-
9492
static constexpr ASPendingStateFlags kZeroFlags = {0};
9593

9694
@implementation _ASPendingState
@@ -145,7 +143,6 @@ @implementation _ASPendingState
145143
CGPoint accessibilityActivationPoint;
146144
UIBezierPath *accessibilityPath;
147145
UISemanticContentAttribute semanticContentAttribute API_AVAILABLE(ios(9.0), tvos(9.0));
148-
NSDictionary<NSString *, id<CAAction>> *actions;
149146

150147
ASPendingStateFlags _flags;
151148
}
@@ -215,7 +212,6 @@ ASDISPLAYNODE_INLINE void ASPendingStateApplyMetricsToLayer(_ASPendingState *sta
215212
@synthesize layoutMargins=layoutMargins;
216213
@synthesize preservesSuperviewLayoutMargins=preservesSuperviewLayoutMargins;
217214
@synthesize insetsLayoutMarginsFromSafeArea=insetsLayoutMarginsFromSafeArea;
218-
@synthesize actions=actions;
219215
@synthesize maskedCorners = maskedCorners;
220216

221217
static CGColorRef blackColorRef = NULL;
@@ -600,12 +596,6 @@ - (void)setSemanticContentAttribute:(UISemanticContentAttribute)attribute API_AV
600596
_flags.setSemanticContentAttribute = YES;
601597
}
602598

603-
- (void)setActions:(NSDictionary<NSString *,id<CAAction>> *)actionsArg
604-
{
605-
actions = [actionsArg copy];
606-
_flags.setActions = YES;
607-
}
608-
609599
- (BOOL)isAccessibilityElement
610600
{
611601
return isAccessibilityElement;
@@ -943,9 +933,6 @@ - (void)applyToLayer:(CALayer *)layer
943933
if (flags.setOpaque)
944934
ASDisplayNodeAssert(layer.opaque == opaque, @"Didn't set opaque as desired");
945935

946-
if (flags.setActions)
947-
layer.actions = actions;
948-
949936
ASPendingStateApplyMetricsToLayer(self, layer);
950937

951938
if (flags.needsLayout)
@@ -965,7 +952,7 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
965952
because a different setter would be called.
966953
*/
967954

968-
unowned CALayer *layer = view.layer;
955+
CALayer *layer = view.layer;
969956

970957
ASPendingStateFlags flags = _flags;
971958
if (__shouldSetNeedsDisplay(layer)) {
@@ -1008,9 +995,6 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
1008995
if (flags.setRasterizationScale)
1009996
layer.rasterizationScale = rasterizationScale;
1010997

1011-
if (flags.setActions)
1012-
layer.actions = actions;
1013-
1014998
if (flags.setClipsToBounds)
1015999
view.clipsToBounds = clipsToBounds;
10161000

@@ -1304,7 +1288,7 @@ + (_ASPendingState *)pendingViewStateFromView:(UIView *)view
13041288

13051289
- (void)clearChanges
13061290
{
1307-
_flags = kZeroFlags;
1291+
_flags = (ASPendingStateFlags){ 0 };
13081292
}
13091293

13101294
- (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>
@@ -2698,17 +2697,4 @@ - (void)testCornerRoundingTypeClippingRoundedCornersIsUsingASDisplayNodeCornerLa
26982697
}
26992698
}
27002699

2701-
- (void)testLayerActionForKeyIsCalled
2702-
{
2703-
UIWindow *window = [[UIWindow alloc] init];
2704-
ASDisplayNode *node = [[ASDisplayNode alloc] init];
2705-
2706-
id mockNode = OCMPartialMock(node);
2707-
OCMExpect([mockNode layerActionForKey:kCAOnOrderIn]);
2708-
[window.layer addSublayer:node.layer];
2709-
OCMExpect([mockNode layerActionForKey:@"position"]);
2710-
node.layer.position = CGPointMake(10, 10);
2711-
OCMVerifyAll(mockNode);
2712-
}
2713-
27142700
@end

0 commit comments

Comments
 (0)