Skip to content

Commit e750dfc

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

10 files changed

+93
-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-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

+68-20
Original file line numberDiff line numberDiff line change
@@ -86,13 +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-
94-
static constexpr ASPendingStateFlags kZeroFlags = {0};
95-
9692
@implementation _ASPendingState
9793
{
9894
@package //Expose all ivars for ASDisplayNode to bypass getters for efficiency
@@ -145,7 +141,6 @@ @implementation _ASPendingState
145141
CGPoint accessibilityActivationPoint;
146142
UIBezierPath *accessibilityPath;
147143
UISemanticContentAttribute semanticContentAttribute API_AVAILABLE(ios(9.0), tvos(9.0));
148-
NSDictionary<NSString *, id<CAAction>> *actions;
149144

150145
ASPendingStateFlags _flags;
151146
}
@@ -215,8 +210,11 @@ ASDISPLAYNODE_INLINE void ASPendingStateApplyMetricsToLayer(_ASPendingState *sta
215210
@synthesize layoutMargins=layoutMargins;
216211
@synthesize preservesSuperviewLayoutMargins=preservesSuperviewLayoutMargins;
217212
@synthesize insetsLayoutMarginsFromSafeArea=insetsLayoutMarginsFromSafeArea;
213+
<<<<<<< HEAD
218214
@synthesize actions=actions;
219215
@synthesize maskedCorners = maskedCorners;
216+
=======
217+
>>>>>>> parent of 34f16217... Add layer-action support to nodes (#1396)
220218

221219
static CGColorRef blackColorRef = NULL;
222220
static UIColor *defaultTintColor = nil;
@@ -600,12 +598,6 @@ - (void)setSemanticContentAttribute:(UISemanticContentAttribute)attribute API_AV
600598
_flags.setSemanticContentAttribute = YES;
601599
}
602600

603-
- (void)setActions:(NSDictionary<NSString *,id<CAAction>> *)actionsArg
604-
{
605-
actions = [actionsArg copy];
606-
_flags.setActions = YES;
607-
}
608-
609601
- (BOOL)isAccessibilityElement
610602
{
611603
return isAccessibilityElement;
@@ -943,9 +935,6 @@ - (void)applyToLayer:(CALayer *)layer
943935
if (flags.setOpaque)
944936
ASDisplayNodeAssert(layer.opaque == opaque, @"Didn't set opaque as desired");
945937

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

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

968-
unowned CALayer *layer = view.layer;
957+
CALayer *layer = view.layer;
969958

970959
ASPendingStateFlags flags = _flags;
971960
if (__shouldSetNeedsDisplay(layer)) {
@@ -1008,9 +997,6 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr
1008997
if (flags.setRasterizationScale)
1009998
layer.rasterizationScale = rasterizationScale;
1010999

1011-
if (flags.setActions)
1012-
layer.actions = actions;
1013-
10141000
if (flags.setClipsToBounds)
10151001
view.clipsToBounds = clipsToBounds;
10161002

@@ -1304,7 +1290,7 @@ + (_ASPendingState *)pendingViewStateFromView:(UIView *)view
13041290

13051291
- (void)clearChanges
13061292
{
1307-
_flags = kZeroFlags;
1293+
_flags = (ASPendingStateFlags){ 0 };
13081294
}
13091295

13101296
- (BOOL)hasSetNeedsLayout
@@ -1319,7 +1305,69 @@ - (BOOL)hasSetNeedsDisplay
13191305

13201306
- (BOOL)hasChanges
13211307
{
1322-
return memcmp(&_flags, &kZeroFlags, sizeof(ASPendingStateFlags));
1308+
ASPendingStateFlags flags = _flags;
1309+
1310+
return (flags.setAnchorPoint
1311+
|| flags.setPosition
1312+
|| flags.setZPosition
1313+
|| flags.setFrame
1314+
|| flags.setBounds
1315+
|| flags.setPosition
1316+
|| flags.setTransform
1317+
|| flags.setSublayerTransform
1318+
|| flags.setContents
1319+
|| flags.setContentsGravity
1320+
|| flags.setContentsRect
1321+
|| flags.setContentsCenter
1322+
|| flags.setContentsScale
1323+
|| flags.setRasterizationScale
1324+
|| flags.setClipsToBounds
1325+
|| flags.setBackgroundColor
1326+
|| flags.setTintColor
1327+
|| flags.setHidden
1328+
|| flags.setAlpha
1329+
|| flags.setCornerRadius
1330+
|| flags.setContentMode
1331+
|| flags.setUserInteractionEnabled
1332+
|| flags.setExclusiveTouch
1333+
|| flags.setShadowOpacity
1334+
|| flags.setShadowOffset
1335+
|| flags.setShadowRadius
1336+
|| flags.setShadowColor
1337+
|| flags.setBorderWidth
1338+
|| flags.setBorderColor
1339+
|| flags.setAutoresizingMask
1340+
|| flags.setAutoresizesSubviews
1341+
|| flags.setNeedsDisplayOnBoundsChange
1342+
|| flags.setAllowsGroupOpacity
1343+
|| flags.setAllowsEdgeAntialiasing
1344+
|| flags.setEdgeAntialiasingMask
1345+
|| flags.needsDisplay
1346+
|| flags.needsLayout
1347+
|| flags.setAsyncTransactionContainer
1348+
|| flags.setOpaque
1349+
|| flags.setSemanticContentAttribute
1350+
|| flags.setLayoutMargins
1351+
|| flags.setPreservesSuperviewLayoutMargins
1352+
|| flags.setInsetsLayoutMarginsFromSafeArea
1353+
|| flags.setIsAccessibilityElement
1354+
|| flags.setAccessibilityLabel
1355+
|| flags.setAccessibilityAttributedLabel
1356+
|| flags.setAccessibilityHint
1357+
|| flags.setAccessibilityAttributedHint
1358+
|| flags.setAccessibilityValue
1359+
|| flags.setAccessibilityAttributedValue
1360+
|| flags.setAccessibilityTraits
1361+
|| flags.setAccessibilityFrame
1362+
|| flags.setAccessibilityLanguage
1363+
|| flags.setAccessibilityElementsHidden
1364+
|| flags.setAccessibilityViewIsModal
1365+
|| flags.setShouldGroupAccessibilityChildren
1366+
|| flags.setAccessibilityIdentifier
1367+
|| flags.setAccessibilityNavigationStyle
1368+
|| flags.setAccessibilityHeaderElements
1369+
|| flags.setAccessibilityActivationPoint
1370+
|| flags.setAccessibilityPath);
13231371
}
13241372

13251373
- (void)dealloc

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)