Skip to content

Commit

Permalink
Only call -layout and -layoutDidFinish if the node is already loaded (T…
Browse files Browse the repository at this point in the history
…extureGroup#285)

* Only call -layout and -layoutDidFinish if the node is already loaded

* Minor change

* Update CHANGELOG
  • Loading branch information
nguyenhuy authored and bernieperez committed Apr 25, 2018
1 parent 9ec3aaf commit b6e5d32
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
- [Fix] Fix a major regression in our image node contents caching. [Adlai Holler](https://github.com/Adlai-Holler) [#287](https://github.com/TextureGroup/Texture/pull/287)
- [Fix] Fixed a bug where ASVideoNodeDelegate error reporting callback would crash an app because of not responding to selector. [Sergey Petrachkov](https://github.com/Petrachkov) [#291](https://github.com/TextureGroup/Texture/issues/291)
- [IGListKit] Add IGListKit headers to public section of Xcode project [Michael Schneider] (https://github.com/maicki)[#286](https://github.com/TextureGroup/Texture/pull/286)
- [Layout] Ensure -layout and -layoutDidFinish are called only if a node is loaded. [Huy Nguyen](https://github.com/nguyenhuy) [#285](https://github.com/TextureGroup/Texture/pull/285)
1 change: 0 additions & 1 deletion Source/ASDisplayNode+Layout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ - (void)displayNodeDidInvalidateSizeNewSize:(CGSize)size
}
}

/// Needs to be called with lock held
- (void)_locked_measureNodeWithBoundsIfNecessary:(CGRect)bounds
{
// Check if we are a subnode in a layout transition.
Expand Down
18 changes: 13 additions & 5 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,10 @@ - (void)__layout
ASDisplayNodeAssertThreadAffinity(self);
ASDisplayNodeAssertLockUnownedByCurrentThread(__instanceLock__);

BOOL loaded = NO;
{
ASDN::MutexLocker l(__instanceLock__);
loaded = [self _locked_isNodeLoaded];
CGRect bounds = _threadSafeBounds;

if (CGRectEqualToRect(bounds, CGRectZero)) {
Expand All @@ -930,17 +932,21 @@ - (void)__layout

[self _layoutSublayouts];

ASPerformBlockOnMainThread(^{
[self layout];
[self layoutDidFinish];
});
// Per API contract, `-layout` and `-layoutDidFinish` are called only if the node is loaded.
if (loaded) {
ASPerformBlockOnMainThread(^{
[self layout];
[self layoutDidFinish];
});
}
}

- (void)layoutDidFinish
{
// Hook for subclasses
ASDisplayNodeAssertMainThread();
ASDisplayNodeAssertLockUnownedByCurrentThread(__instanceLock__);
ASDisplayNodeAssertTrue(self.isNodeLoaded);
}

#pragma mark Calculation
Expand Down Expand Up @@ -1082,8 +1088,10 @@ - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize

- (void)layout
{
// Hook for subclasses
ASDisplayNodeAssertMainThread();
// Subclass hook
ASDisplayNodeAssertLockUnownedByCurrentThread(__instanceLock__);
ASDisplayNodeAssertTrue(self.isNodeLoaded);
}

#pragma mark Layout Transition
Expand Down
4 changes: 3 additions & 1 deletion Source/Private/ASDisplayNodeInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo
- (void)__setNeedsDisplay;

/**
* Called from [CALayer layoutSublayers:]. Executes the layout pass for the node
* Called whenever the node needs to layout its subnodes and, if it's already loaded, its subviews. Executes the layout pass for the node
*
* This method is thread-safe but asserts thread affinity.
*/
- (void)__layout;

Expand Down

0 comments on commit b6e5d32

Please sign in to comment.