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

Commit c0ae709

Browse files
nguyenhuyappleguy
authored andcommitted
[ASDisplayNode][ASImageNode] Small refactorings (#2778)
* Comment out template code and fix another comment in ASDisplayNode * Release instance lock a bit sooner and fix indentation in ASImageNode
1 parent a59a0f0 commit c0ae709

2 files changed

Lines changed: 38 additions & 49 deletions

File tree

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,7 @@ - (void)_addSubnode:(ASDisplayNode *)subnode
20132013

20142014
ASDisplayNodeAssert(subnode, @"Cannot insert a nil subnode");
20152015

2016-
// Don't add subnode if it's already if it's already a subnodes
2016+
// Don't add if it's already a subnode
20172017
ASDisplayNode *oldParent = subnode.supernode;
20182018
if (!subnode || subnode == self || oldParent == self) {
20192019
return;
@@ -3063,10 +3063,10 @@ - (void)setInterfaceState:(ASInterfaceState)newState
30633063
oldState = _interfaceState;
30643064
_interfaceState = newState;
30653065
}
3066-
3067-
if ((newState & ASInterfaceStateMeasureLayout) != (oldState & ASInterfaceStateMeasureLayout)) {
3068-
// Trigger asynchronous measurement if it is not already cached or being calculated.
3069-
}
3066+
3067+
// TODO: Trigger asynchronous measurement if it is not already cached or being calculated.
3068+
// if ((newState & ASInterfaceStateMeasureLayout) != (oldState & ASInterfaceStateMeasureLayout)) {
3069+
// }
30703070

30713071
// For the Preload and Display ranges, we don't want to call -clear* if not being managed by a range controller.
30723072
// Otherwise we get flashing behavior from normal UIKit manipulations like navigation controller push / pop.

AsyncDisplayKit/ASImageNode.mm

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -273,35 +273,24 @@ - (UIImage *)displayWithParameters:(id<NSObject> *)parameter isCancelled:(asdisp
273273
return nil;
274274
}
275275

276-
CGRect drawParameterBounds = CGRectZero;
277-
BOOL forceUpscaling = NO;
278-
CGSize forcedSize = CGSizeZero;
279-
BOOL cropEnabled = YES;
280-
BOOL isOpaque = NO;
281-
UIColor *backgroundColor = nil;
282-
UIViewContentMode contentMode = UIViewContentModeScaleAspectFill;
283-
CGFloat contentsScale = 0.0;
284-
CGRect cropDisplayBounds = CGRectZero;
285-
CGRect cropRect = CGRectZero;
286-
asimagenode_modification_block_t imageModificationBlock;
287-
276+
ASImageNodeDrawParameters drawParameter;
288277
{
289278
ASDN::MutexLocker l(__instanceLock__);
290-
ASImageNodeDrawParameters drawParameter = _drawParameter;
291-
292-
drawParameterBounds = drawParameter.bounds;
293-
forceUpscaling = drawParameter.forceUpscaling;
294-
forcedSize = drawParameter.forcedSize;
295-
cropEnabled = drawParameter.cropEnabled;
296-
isOpaque = drawParameter.opaque;
297-
backgroundColor = drawParameter.backgroundColor;
298-
contentMode = drawParameter.contentMode;
299-
contentsScale = drawParameter.contentsScale;
300-
cropDisplayBounds = drawParameter.cropDisplayBounds;
301-
cropRect = drawParameter.cropRect;
302-
imageModificationBlock = drawParameter.imageModificationBlock;
279+
drawParameter = _drawParameter;
303280
}
304281

282+
CGRect drawParameterBounds = drawParameter.bounds;
283+
BOOL forceUpscaling = drawParameter.forceUpscaling;
284+
CGSize forcedSize = drawParameter.forcedSize;
285+
BOOL cropEnabled = drawParameter.cropEnabled;
286+
BOOL isOpaque = drawParameter.opaque;
287+
UIColor *backgroundColor = drawParameter.backgroundColor;
288+
UIViewContentMode contentMode = drawParameter.contentMode;
289+
CGFloat contentsScale = drawParameter.contentsScale;
290+
CGRect cropDisplayBounds = drawParameter.cropDisplayBounds;
291+
CGRect cropRect = drawParameter.cropRect;
292+
asimagenode_modification_block_t imageModificationBlock = drawParameter.imageModificationBlock;
293+
305294
BOOL hasValidCropBounds = cropEnabled && !CGRectIsEmpty(cropDisplayBounds);
306295
CGRect bounds = (hasValidCropBounds ? cropDisplayBounds : drawParameterBounds);
307296

@@ -374,26 +363,26 @@ - (UIImage *)displayWithParameters:(id<NSObject> *)parameter isCancelled:(asdisp
374363
return nil;
375364
}
376365

377-
ASImageNodeContentsKey *contentsKey = [[ASImageNodeContentsKey alloc] init];
378-
contentsKey.image = image;
379-
contentsKey.backingSize = backingSize;
380-
contentsKey.imageDrawRect = imageDrawRect;
381-
contentsKey.isOpaque = isOpaque;
382-
contentsKey.backgroundColor = backgroundColor;
383-
contentsKey.preContextBlock = preContextBlock;
384-
contentsKey.postContextBlock = postContextBlock;
385-
contentsKey.imageModificationBlock = imageModificationBlock;
386-
387-
if (isCancelled()) {
388-
return nil;
389-
}
366+
ASImageNodeContentsKey *contentsKey = [[ASImageNodeContentsKey alloc] init];
367+
contentsKey.image = image;
368+
contentsKey.backingSize = backingSize;
369+
contentsKey.imageDrawRect = imageDrawRect;
370+
contentsKey.isOpaque = isOpaque;
371+
contentsKey.backgroundColor = backgroundColor;
372+
contentsKey.preContextBlock = preContextBlock;
373+
contentsKey.postContextBlock = postContextBlock;
374+
contentsKey.imageModificationBlock = imageModificationBlock;
390375

391-
ASWeakMapEntry<UIImage *> *entry = [self.class contentsForkey:contentsKey isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled];
392-
if (entry == nil) { // If nil, we were cancelled.
393-
return nil;
394-
}
395-
_weakCacheEntry = entry; // Retain so that the entry remains in the weak cache
396-
return entry.value;
376+
if (isCancelled()) {
377+
return nil;
378+
}
379+
380+
ASWeakMapEntry<UIImage *> *entry = [self.class contentsForkey:contentsKey isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled];
381+
if (entry == nil) { // If nil, we were cancelled.
382+
return nil;
383+
}
384+
_weakCacheEntry = entry; // Retain so that the entry remains in the weak cache
385+
return entry.value;
397386
}
398387

399388
static ASWeakMap<ASImageNodeContentsKey *, UIImage *> *cache = nil;

0 commit comments

Comments
 (0)