Skip to content

Commit

Permalink
Fix placeholder (#1555)
Browse files Browse the repository at this point in the history
* Fix placeholder

* [Unit Tests] Add Placeholder Test (#1555)
  • Loading branch information
strangeliu authored and Greg Bolsinga committed Jun 28, 2019
1 parent d4c0d74 commit 59ab0e8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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

0 comments on commit 59ab0e8

Please sign in to comment.