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 placeholder #1555

Merged
merged 2 commits into from
Jun 28, 2019
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
12 changes: 12 additions & 0 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,18 @@ - (void)setAutomaticallyRelayoutOnLayoutMarginsChanges:(BOOL)flag
_flags.automaticallyRelayoutOnLayoutMarginsChanges = flag;
}

- (BOOL)placeholderEnabled
{
MutexLocker l(__instanceLock__);
return _flags.placeholderEnabled;
}

- (void)setPlaceholderEnabled:(BOOL)flag
{
MutexLocker l(__instanceLock__);
_flags.placeholderEnabled = flag;
}

- (void)__setNodeController:(ASNodeController *)controller
{
// See docs for why we don't lock.
Expand Down
26 changes: 26 additions & 0 deletions Tests/ASDisplayNodeTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ - (void)displayWillStartAsynchronously:(BOOL)asynchronously
return &self->_clipCornerLayers;
}

+ (UIImage *)displayWithParameters:(id<NSObject>)parameter isCancelled:(NS_NOESCAPE asdisplaynode_iscancelled_block_t)isCancelled
{
return nil;
}

@end

@interface ASSynchronousTestDisplayNodeViaViewClass : ASDisplayNode
Expand Down Expand Up @@ -2726,4 +2731,25 @@ - (void)testLayerActionForKeyIsCalled
OCMVerifyAll(mockNode);
}

- (void)testPlaceholder
{
UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
ASTestDisplayNode *node = [[ASTestDisplayNode alloc] init];
node.placeholderEnabled = YES;
node.frame = window.bounds;
[window addSubnode:node];
[window makeKeyAndVisible];

CALayer *layer = node.layer;
XCTAssertNotNil(layer);
BOOL hasPlaceholderLayer = NO;
for (CALayer *sublayer in layer.sublayers) {
if (sublayer.zPosition == 9999.0) {
hasPlaceholderLayer = YES;
break;
}
}
XCTAssertTrue(hasPlaceholderLayer);
}

@end