Skip to content

Commit

Permalink
Cleanup Yoga Categories (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
maicki authored Mar 6, 2019
1 parent dd4359d commit 07becd0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
33 changes: 1 addition & 32 deletions Source/ASDisplayNode+Layout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions Source/ASDisplayNode+Yoga.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 36 additions & 1 deletion Source/ASDisplayNode+Yoga.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
#import <AsyncDisplayKit/ASLayout.h>
#import <AsyncDisplayKit/ASLayoutElementStylePrivate.h>
#import <AsyncDisplayKit/ASNodeController+Beta.h>

#import <AsyncDisplayKit/ASDisplayNode+LayoutSpec.h>

#define YOGA_LAYOUT_LOGGING 0

#pragma mark - ASDisplayNode+Yoga

@interface ASDisplayNode (YogaInternal)
@interface ASDisplayNode (YogaPrivate)
@property (nonatomic, weak) ASDisplayNode *yogaParent;
- (ASSizeRange)_locked_constrainedSizeForLayoutPass;
@end
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 07becd0

Please sign in to comment.