Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 19e949e

Browse files
author
Levi McCallum
committed
[ASDisplayNode] Move constrainedSize to layout
1 parent a004cc7 commit 19e949e

4 files changed

Lines changed: 13 additions & 37 deletions

File tree

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -616,25 +616,20 @@ - (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
616616
[self cancelLayoutTransitionsInProgress];
617617

618618
ASLayout *previousLayout = _layout;
619-
ASSizeRange previousConstrainedSize = _constrainedSize;
620619
ASLayout *newLayout = [self calculateLayoutThatFits:constrainedSize];
621620

622621
if (ASHierarchyStateIncludesLayoutPending(_hierarchyState)) {
623622
_pendingLayoutTransition = [[ASLayoutTransition alloc] initWithNode:self
624623
pendingLayout:newLayout
625-
pendingConstrainedSize:constrainedSize
626-
previousLayout:previousLayout
627-
previousConstrainedSize:previousConstrainedSize];
624+
previousLayout:previousLayout];
628625
} else {
629626
ASLayoutTransition *layoutContext;
630627
if (self.usesImplicitHierarchyManagement) {
631628
layoutContext = [[ASLayoutTransition alloc] initWithNode:self
632629
pendingLayout:newLayout
633-
pendingConstrainedSize:constrainedSize
634-
previousLayout:previousLayout
635-
previousConstrainedSize:previousConstrainedSize];
630+
previousLayout:previousLayout];
636631
}
637-
[self applyLayout:newLayout constrainedSize:constrainedSize layoutContext:layoutContext];
632+
[self applyLayout:newLayout layoutContext:layoutContext];
638633
[self _completeLayoutCalculation];
639634
}
640635

@@ -658,7 +653,7 @@ - (BOOL)shouldMeasureWithSizeRange:(ASSizeRange)constrainedSize
658653
// only calculate the size if
659654
// - we haven't already
660655
// - the constrained size range is different
661-
return (!_flags.isMeasured || !ASSizeRangeEqualToSizeRange(constrainedSize, _constrainedSize));
656+
return (!_flags.isMeasured || !ASSizeRangeEqualToSizeRange(constrainedSize, _layout.constrainedSizeRange));
662657
}
663658

664659
#pragma mark - Layout Transition
@@ -667,9 +662,8 @@ - (void)transitionLayoutWithAnimation:(BOOL)animated
667662
shouldMeasureAsync:(BOOL)shouldMeasureAsync
668663
measurementCompletion:(void(^)())completion
669664
{
670-
ASSizeRange currentConstrainedSize = _constrainedSize;
671665
[self invalidateCalculatedLayout];
672-
[self transitionLayoutWithSizeRange:currentConstrainedSize
666+
[self transitionLayoutWithSizeRange:_layout.constrainedSizeRange
673667
animated:animated
674668
shouldMeasureAsync:shouldMeasureAsync
675669
measurementCompletion:completion];
@@ -732,8 +726,7 @@ - (void)transitionLayoutWithSizeRange:(ASSizeRange)constrainedSize
732726
}
733727

734728
ASLayout *previousLayout = _layout;
735-
ASSizeRange previousConstrainedSize = _constrainedSize;
736-
[self applyLayout:newLayout constrainedSize:constrainedSize layoutContext:nil];
729+
[self applyLayout:newLayout layoutContext:nil];
737730

738731
ASDisplayNodePerformBlockOnEverySubnode(self, ^(ASDisplayNode * _Nonnull node) {
739732
[node applyPendingLayoutContext];
@@ -749,9 +742,7 @@ - (void)transitionLayoutWithSizeRange:(ASSizeRange)constrainedSize
749742

750743
_pendingLayoutTransition = [[ASLayoutTransition alloc] initWithNode:self
751744
pendingLayout:newLayout
752-
pendingConstrainedSize:constrainedSize
753-
previousLayout:previousLayout
754-
previousConstrainedSize:previousConstrainedSize];
745+
previousLayout:previousLayout];
755746
[_pendingLayoutTransition applySubnodeInsertions];
756747

757748
_transitionContext = [[_ASTransitionContext alloc] initWithAnimation:animated
@@ -1032,7 +1023,6 @@ - (void)__setNeedsLayout
10321023
return;
10331024
}
10341025

1035-
ASSizeRange oldConstrainedSize = _constrainedSize;
10361026
[self invalidateCalculatedLayout];
10371027

10381028
if (_supernode) {
@@ -1045,7 +1035,7 @@ - (void)__setNeedsLayout
10451035
}
10461036

10471037
// This is the root node. Trigger a full measurement pass on *current* thread. Old constrained size is re-used.
1048-
[self measureWithSizeRange:oldConstrainedSize];
1038+
[self measureWithSizeRange:_layout.constrainedSizeRange];
10491039

10501040
CGRect oldBounds = self.bounds;
10511041
CGSize oldSize = oldBounds.size;
@@ -2014,7 +2004,7 @@ - (CGSize)calculatedSize
20142004
- (ASSizeRange)constrainedSizeForCalculatedLayout
20152005
{
20162006
ASDN::MutexLocker l(_propertyLock);
2017-
return _constrainedSize;
2007+
return _layout.constrainedSizeRange;
20182008
}
20192009

20202010
- (void)setLayoutSpecBlock:(ASLayoutSpecBlock)layoutSpecBlock
@@ -2400,15 +2390,12 @@ - (void)applyPendingLayoutContext
24002390
{
24012391
ASDN::MutexLocker l(_propertyLock);
24022392
if (_pendingLayoutTransition) {
2403-
[self applyLayout:_pendingLayoutTransition.pendingLayout
2404-
constrainedSize:_pendingLayoutTransition.pendingConstrainedSize
2405-
layoutContext:_pendingLayoutTransition];
2393+
[self applyLayout:_pendingLayoutTransition.pendingLayout layoutContext:_pendingLayoutTransition];
24062394
_pendingLayoutTransition = nil;
24072395
}
24082396
}
24092397

24102398
- (void)applyLayout:(ASLayout *)layout
2411-
constrainedSize:(ASSizeRange)constrainedSize
24122399
layoutContext:(ASLayoutTransition *)layoutContext
24132400
{
24142401
ASDN::MutexLocker l(_propertyLock);
@@ -2418,7 +2405,6 @@ - (void)applyLayout:(ASLayout *)layout
24182405
ASDisplayNodeAssertTrue(layout.size.width >= 0.0);
24192406
ASDisplayNodeAssertTrue(layout.size.height >= 0.0);
24202407

2421-
_constrainedSize = constrainedSize;
24222408
_flags.isMeasured = YES;
24232409

24242410
if (self.usesImplicitHierarchyManagement && layoutContext != nil) {

AsyncDisplayKit/Private/ASDisplayNodeInternal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo
103103
ASEnvironmentState _environmentState;
104104
ASLayout *_layout;
105105

106-
ASSizeRange _constrainedSize;
107-
108106
UIEdgeInsets _hitTestSlop;
109107
NSMutableArray *_subnodes;
110108

AsyncDisplayKit/Private/ASLayoutTransition.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616

1717
@property (nonatomic, readonly, weak) ASDisplayNode *node;
1818
@property (nonatomic, readonly, strong) ASLayout *pendingLayout;
19-
@property (nonatomic, readonly, assign) ASSizeRange pendingConstrainedSize;
2019
@property (nonatomic, readonly, strong) ASLayout *previousLayout;
21-
@property (nonatomic, readonly, assign) ASSizeRange previousConstrainedSize;
2220

2321
- (instancetype)initWithNode:(ASDisplayNode *)node
2422
pendingLayout:(ASLayout *)pendingLayout
25-
pendingConstrainedSize:(ASSizeRange)pendingConstrainedSize
26-
previousLayout:(ASLayout *)previousLayout
27-
previousConstrainedSize:(ASSizeRange)previousConstrainedSize;
23+
previousLayout:(ASLayout *)previousLayout;
2824

2925
- (void)applySubnodeInsertions;
3026

AsyncDisplayKit/Private/ASLayoutTransition.mm

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,13 @@ @implementation ASLayoutTransition {
2929

3030
- (instancetype)initWithNode:(ASDisplayNode *)node
3131
pendingLayout:(ASLayout *)pendingLayout
32-
pendingConstrainedSize:(ASSizeRange)pendingConstrainedSize
3332
previousLayout:(ASLayout *)previousLayout
34-
previousConstrainedSize:(ASSizeRange)previousConstrainedSize
3533
{
3634
self = [super init];
3735
if (self) {
3836
_node = node;
3937
_pendingLayout = pendingLayout;
40-
_pendingConstrainedSize = pendingConstrainedSize;
4138
_previousLayout = previousLayout;
42-
_previousConstrainedSize = previousConstrainedSize;
4339
}
4440
return self;
4541
}
@@ -129,9 +125,9 @@ - (ASSizeRange)transitionContext:(_ASTransitionContext *)context constrainedSize
129125
{
130126
ASDN::MutexLocker l(_propertyLock);
131127
if ([key isEqualToString:ASTransitionContextFromLayoutKey]) {
132-
return _previousConstrainedSize;
128+
return _previousLayout.constrainedSizeRange;
133129
} else if ([key isEqualToString:ASTransitionContextToLayoutKey]) {
134-
return _pendingConstrainedSize;
130+
return _pendingLayout.constrainedSizeRange;
135131
} else {
136132
return ASSizeRangeMake(CGSizeZero, CGSizeZero);
137133
}

0 commit comments

Comments
 (0)