From 4b82cc4051c5c26d25a7f4eb451e50b202c05482 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Wed, 2 Sep 2015 15:01:22 +0300 Subject: [PATCH] While adjusting position of a node, use getters and setters. Those methods already check thread affinity and layer readiness. --- AsyncDisplayKit/ASDisplayNode.mm | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index 59d0b7833a..13e74b9d7f 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -601,25 +601,20 @@ void ASDisplayNodeRespectThreadAffinityOfNode(ASDisplayNode *node, void (^block) // This is the root node. Trigger a full measurement pass on *current* thread. Old constrained size is re-used. [self measureWithSizeRange:oldConstrainedSize]; - CGSize oldSize = self.bounds.size; + CGRect oldBounds = self.bounds; + CGSize oldSize = oldBounds.size; CGSize newSize = _layout.size; if (! CGSizeEqualToSize(oldSize, newSize)) { - CGRect bounds = self.bounds; - bounds.size = newSize; - self.bounds = bounds; + self.bounds = (CGRect){ oldBounds.origin, newSize }; // Frame's origin must be preserved. Since it is computed from bounds size, anchorPoint // and position (see frame setter in ASDisplayNode+UIViewBridge), position needs to be adjusted. - BOOL useLayer = (_layer && ASDisplayNodeThreadIsMain()); - CGPoint anchorPoint = (useLayer ? _layer.anchorPoint : self.anchorPoint); - CGPoint oldPosition = (useLayer ? _layer.position : self.position); - + CGPoint anchorPoint = self.anchorPoint; + CGPoint oldPosition = self.position; CGFloat xDelta = (newSize.width - oldSize.width) * anchorPoint.x; CGFloat yDelta = (newSize.height - oldSize.height) * anchorPoint.y; - CGPoint newPosition = CGPointMake(oldPosition.x + xDelta, oldPosition.y + yDelta); - - useLayer ? _layer.position = newPosition : self.position = newPosition; + self.position = CGPointMake(oldPosition.x + xDelta, oldPosition.y + yDelta); } } }