From 07becd0fc8a8005e6149ec4c6c55f696e21fb05a Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Wed, 6 Mar 2019 07:37:40 -0800 Subject: [PATCH] Cleanup Yoga Categories (#1364) --- Source/ASDisplayNode+Layout.mm | 33 +----------------------------- Source/ASDisplayNode+Yoga.h | 4 ++++ Source/ASDisplayNode+Yoga.mm | 37 +++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/Source/ASDisplayNode+Layout.mm b/Source/ASDisplayNode+Layout.mm index 0eac1e3ab..35b670828 100644 --- a/Source/ASDisplayNode+Layout.mm +++ b/Source/ASDisplayNode+Layout.mm @@ -1046,10 +1046,7 @@ - (void)_locked_setCalculatedDisplayNodeLayout:(const ASDisplayNodeLayout &)disp #pragma mark - #pragma mark - ASDisplayNode (YogaLayout) -@implementation ASDisplayNode (YogaInternal) - -#pragma mark - -#pragma mark - ASDisplayNode (Yoga) +@implementation ASDisplayNode (YogaLayout) - (BOOL)locked_shouldLayoutFromYogaRoot { #if YOGA @@ -1071,32 +1068,4 @@ - (BOOL)locked_shouldLayoutFromYogaRoot { #endif } -- (ASLockSet)lockToRootIfNeededForLayout { - ASLockSet lockSet = ASLockSequence(^BOOL(ASAddLockBlock addLock) { - if (!addLock(self)) { - return NO; - } -#if YOGA - if (![self locked_shouldLayoutFromYogaRoot]) { - return YES; - } - if (self.nodeController && !addLock(self.nodeController)) { - return NO; - } - ASDisplayNode *parent = _supernode; - while (parent) { - if (!addLock(parent)) { - return NO; - } - if (parent.nodeController && !addLock(parent.nodeController)) { - return NO; - } - parent = parent->_supernode; - } -#endif - return true; - }); - return lockSet; -} - @end diff --git a/Source/ASDisplayNode+Yoga.h b/Source/ASDisplayNode+Yoga.h index fc8d88464..93cbf7a7c 100644 --- a/Source/ASDisplayNode+Yoga.h +++ b/Source/ASDisplayNode+Yoga.h @@ -33,6 +33,10 @@ AS_EXTERN void ASDisplayNodePerformBlockOnEveryYogaChild(ASDisplayNode * _Nullab // Will walk up the Yoga tree and returns the root node - (ASDisplayNode *)yogaRoot; + +@end + +@interface ASDisplayNode (YogaLocking) /** * @discussion Attempts(spinning) to lock all node up to root node when yoga is enabled. * This will lock self when yoga is not enabled; diff --git a/Source/ASDisplayNode+Yoga.mm b/Source/ASDisplayNode+Yoga.mm index 0f975c885..97e7cb56b 100644 --- a/Source/ASDisplayNode+Yoga.mm +++ b/Source/ASDisplayNode+Yoga.mm @@ -20,6 +20,7 @@ #import #import #import +#import #import @@ -27,7 +28,7 @@ #pragma mark - ASDisplayNode+Yoga -@interface ASDisplayNode (YogaInternal) +@interface ASDisplayNode (YogaPrivate) @property (nonatomic, weak) ASDisplayNode *yogaParent; - (ASSizeRange)_locked_constrainedSizeForLayoutPass; @end @@ -409,6 +410,40 @@ - (void)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize @end +#pragma mark - ASDisplayNode (YogaLocking) + +@implementation ASDisplayNode (YogaLocking) + +- (ASLockSet)lockToRootIfNeededForLayout { + ASLockSet lockSet = ASLockSequence(^BOOL(ASAddLockBlock addLock) { + if (!addLock(self)) { + return NO; + } +#if YOGA + if (![self locked_shouldLayoutFromYogaRoot]) { + return YES; + } + if (self.nodeController && !addLock(self.nodeController)) { + return NO; + } + ASDisplayNode *parent = _supernode; + while (parent) { + if (!addLock(parent)) { + return NO; + } + if (parent.nodeController && !addLock(parent.nodeController)) { + return NO; + } + parent = parent->_supernode; + } +#endif + return true; + }); + return lockSet; +} + +@end + @implementation ASDisplayNode (YogaDebugging) - (NSString *)yogaTreeDescription {