Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix synchronous state of node if +viewClass or +layerClass is overwritten #trivial #776

Merged
merged 3 commits into from
Jan 31, 2018
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
5 changes: 5 additions & 0 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ - (void)_initializeInstance

_viewClass = [self.class viewClass];
_layerClass = [self.class layerClass];
BOOL isSynchronous = ![_viewClass isSubclassOfClass:[_ASDisplayView class]]
|| ![_layerClass isSubclassOfClass:[_ASDisplayLayer class]];
setFlag(Synchronous, isSynchronous);


_contentsScaleForDisplay = ASScreenScale();
_drawingPriority = ASDefaultDrawingPriority;

Expand Down
34 changes: 34 additions & 0 deletions Tests/ASDisplayNodeTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,28 @@ - (void)displayWillStartAsynchronously:(BOOL)asynchronously

@end

@interface ASSynchronousTestDisplayNodeViaViewClass : ASDisplayNode
@end

@implementation ASSynchronousTestDisplayNodeViaViewClass

+ (Class)viewClass {
return [UIView class];
}

@end

@interface ASSynchronousTestDisplayNodeViaLayerClass : ASDisplayNode
@end

@implementation ASSynchronousTestDisplayNodeViaLayerClass

+ (Class)layerClass {
return [CALayer class];
}

@end

@interface UIDisplayNodeTestView : UIView
@end

Expand Down Expand Up @@ -2354,4 +2376,16 @@ - (void)testScreenScale
XCTAssertEqual(ASScreenScale(), UIScreen.mainScreen.scale);
}

- (void)testThatIfViewClassIsOverwrittenItsSynchronous
{
ASSynchronousTestDisplayNodeViaViewClass *node = [[ASSynchronousTestDisplayNodeViaViewClass alloc] init];
XCTAssertTrue([node isSynchronous], @"Node should be synchronous if viewClass is ovewritten and not a subclass of _ASDisplayView");
}

- (void)testThatIfLayerClassIsOverwrittenItsSynchronous
{
ASSynchronousTestDisplayNodeViaLayerClass *node = [[ASSynchronousTestDisplayNodeViaLayerClass alloc] init];
XCTAssertTrue([node isSynchronous], @"Node should be synchronous if viewClass is ovewritten and not a subclass of _ASDisplayView");
}

@end