Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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