Expose the layout's immediate sublayouts as the accessing nodes

This commit is contained in:
Levi McCallum 2016-02-09 14:12:05 -08:00
parent 4361c3bbb4
commit 1513ee8ca5
4 changed files with 68 additions and 60 deletions

View File

@ -15,10 +15,21 @@
*/
- (BOOL)isAnimated;
/**
* @abstract The destination layout being transitioned to
*/
- (ASLayout *)layout;
/**
* @abstrat The destination constrainedSize being transitioned to
*/
- (ASSizeRange)constrainedSize;
/**
* @abstract Subnodes in the new layout
*/
- (NSArray<ASDisplayNode *> *)subnodes;
/**
@abstract The frame for the given node before the transition began.
@discussion Returns CGRectNull if the node was not in the hierarchy before the transition.

View File

@ -652,11 +652,10 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
{
ASDisplayNodeAssertThreadAffinity(self);
ASDN::MutexLocker l(_propertyLock);
ASLayout *newLayout;
if (![self __shouldSize])
return nil;
ASLayout *newLayout;
return newLayout;
// only calculate the size if
// - we haven't already
@ -664,32 +663,29 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
if (!_flags.isMeasured || !ASSizeRangeEqualToSizeRange(constrainedSize, _constrainedSize)) {
newLayout = [self calculateLayoutThatFits:constrainedSize];
if ([[self class] usesImplicitHierarchyManagement]) {
if (_layout) {
NSIndexSet *insertions, *deletions;
[_layout.immediateSublayouts asdk_diffWithArray:newLayout.immediateSublayouts
insertions:&insertions
deletions:&deletions
compareBlock:^BOOL(ASLayout *lhs, ASLayout *rhs) {
return ASObjectIsEqual(lhs.layoutableObject, rhs.layoutableObject);
}];
_insertedSubnodes = [self _nodesInLayout:newLayout atIndexes:insertions];
_deletedSubnodes = [self _nodesInLayout:_layout atIndexes:deletions filterNodes:_insertedSubnodes];
} else {
NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [newLayout.immediateSublayouts count])];
_insertedSubnodes = [self _nodesInLayout:newLayout atIndexes:indexes];
_deletedSubnodes = nil;
}
if (animated) {
[self __transitionToLayout:newLayout constrainedSize:constrainedSize animated:animated];
} else {
if (_layout) {
NSIndexSet *insertions, *deletions;
[_layout.immediateSublayouts asdk_diffWithArray:newLayout.immediateSublayouts
insertions:&insertions
deletions:&deletions
compareBlock:^BOOL(ASLayout *lhs, ASLayout *rhs) {
return ASObjectIsEqual(lhs.layoutableObject, rhs.layoutableObject);
}];
_insertedSubnodes = [self _nodesInLayout:newLayout atIndexes:insertions];
_deletedSubnodes = [self _nodesInLayout:_layout atIndexes:deletions filterNodes:_insertedSubnodes];
} else {
NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [newLayout.immediateSublayouts count])];
_insertedSubnodes = [self _nodesInLayout:newLayout atIndexes:indexes];
_deletedSubnodes = nil;
}
if (animated) {
[self __transitionToLayout:newLayout constrainedSize:constrainedSize animated:animated];
} else {
if ([[self class] usesImplicitHierarchyManagement]) {
[self __implicitlyInsertSubnodes];
[self __implicitlyRemoveSubnodes];
[self __updateLayout:newLayout constrainedSize:constrainedSize];
}
} else {
// 1.9.x code path
[self __updateLayout:newLayout constrainedSize:constrainedSize];
}
}
@ -1079,52 +1075,33 @@ static inline CATransform3D _calculateTransformFromReferenceToTarget(ASDisplayNo
- (void)__implicitlyInsertSubnodes
{
if ([_insertedSubnodes count]) {
for (_ASDisplayNodePosition *position in _insertedSubnodes) {
[self insertSubnode:position.node atIndex:position.index];
}
_insertedSubnodes = nil;
for (_ASDisplayNodePosition *position in _insertedSubnodes) {
[self insertSubnode:position.node atIndex:position.index];
}
_insertedSubnodes = nil;
}
- (void)__implicitlyRemoveSubnodes
{
if ([_deletedSubnodes count]) {
for (_ASDisplayNodePosition *position in _deletedSubnodes) {
[position.node removeFromSupernode];
}
_deletedSubnodes = nil;
for (_ASDisplayNodePosition *position in _deletedSubnodes) {
[position.node removeFromSupernode];
}
_deletedSubnodes = nil;
}
#pragma mark - _ASTransitionContextDelegate
- (NSArray<ASDisplayNode *> *)currentSubnodesWithTransitionContext:(_ASTransitionContext *)context
{
return _subnodes;
}
- (void)transitionContext:(_ASTransitionContext *)context didComplete:(BOOL)didComplete
{
[self didCompleteTransitionLayout:context];
_transitionContext = nil;
}
- (CGRect)transitionContext:(_ASTransitionContext *)context initialFrameForNode:(ASDisplayNode *)node
{
for (ASDisplayNode *subnode in _subnodes) {
if (ASObjectIsEqual(node, subnode)) {
return node.frame;
}
}
return CGRectNull;
}
- (CGRect)transitionContext:(_ASTransitionContext *)context finalFrameForNode:(ASDisplayNode *)node
{
for (ASLayout *layout in _layout.sublayouts) {
if (ASObjectIsEqual(node, layout.layoutableObject)) {
return [self _adjustedFrameForLayout:layout];
}
}
return CGRectNull;
}
#pragma mark - _ASDisplayLayerDelegate
- (void)willDisplayAsyncLayer:(_ASDisplayLayer *)layer

View File

@ -15,9 +15,8 @@
@protocol _ASTransitionContextDelegate <NSObject>
- (NSArray<ASDisplayNode *> *)currentSubnodesWithTransitionContext:(_ASTransitionContext *)context;
- (void)transitionContext:(_ASTransitionContext *)context didComplete:(BOOL)didComplete;
- (CGRect)transitionContext:(_ASTransitionContext *)context initialFrameForNode:(ASDisplayNode *)node;
- (CGRect)transitionContext:(_ASTransitionContext *)context finalFrameForNode:(ASDisplayNode *)node;
@end

View File

@ -8,6 +8,8 @@
#import "_ASTransitionContext.h"
#import "ASLayout.h"
@interface _ASTransitionContext ()
@property (weak, nonatomic) id<_ASTransitionContextDelegate> delegate;
@ -30,12 +32,31 @@
- (CGRect)initialFrameForNode:(ASDisplayNode *)node
{
return [_delegate transitionContext:self initialFrameForNode:node];
for (ASDisplayNode *subnode in [_delegate currentSubnodesWithTransitionContext:self]) {
if (node == subnode) {
return node.frame;
}
}
return CGRectZero;
}
- (CGRect)finalFrameForNode:(ASDisplayNode *)node
{
return [_delegate transitionContext:self finalFrameForNode:node];
for (ASLayout *layout in _layout.immediateSublayouts) {
if (layout.layoutableObject == node) {
return [layout frame];
}
}
return CGRectZero;
}
- (NSArray<ASDisplayNode *> *)subnodes
{
NSMutableArray<ASDisplayNode *> *subnodes = [NSMutableArray array];
for (ASLayout *sublayout in _layout.immediateSublayouts) {
[subnodes addObject:(ASDisplayNode *)sublayout.layoutableObject];
}
return subnodes;
}
- (void)completeTransition:(BOOL)didComplete