diff --git a/AsyncDisplayKit/ASCollectionNode.mm b/AsyncDisplayKit/ASCollectionNode.mm index d33ef7bb0d..605f0defaa 100644 --- a/AsyncDisplayKit/ASCollectionNode.mm +++ b/AsyncDisplayKit/ASCollectionNode.mm @@ -16,6 +16,11 @@ @interface _ASCollectionPendingState : NSObject @property (weak, nonatomic) id delegate; @property (weak, nonatomic) id dataSource; + +// If the background color is applied via the pending state it's applied to the layer of the UICollectionView. +// Unfortunately UICollectionView does not consider using the layer backgroundColor property as it's background color, +// so it needs to be applied to the view after the ASCollectionNode did load and the view is available +@property (strong, nonatomic) UIColor *backgroundColor; @end @implementation _ASCollectionPendingState @@ -162,6 +167,25 @@ } } +- (void)setBackgroundColor:(UIColor *)backgroundColor +{ + if ([self pendingState]) { + _pendingState.backgroundColor = backgroundColor; + } else { + ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist"); + self.view.backgroundColor = backgroundColor; + } +} + +- (UIColor *)backgroundColor +{ + if ([self pendingState]) { + return _pendingState.backgroundColor; + } else { + return self.view.backgroundColor; + } +} + - (ASCollectionView *)view { return (ASCollectionView *)[super view]; diff --git a/AsyncDisplayKit/ASTableNode.m b/AsyncDisplayKit/ASTableNode.m index 366209bf15..9906acb5c4 100644 --- a/AsyncDisplayKit/ASTableNode.m +++ b/AsyncDisplayKit/ASTableNode.m @@ -14,6 +14,11 @@ @interface _ASTablePendingState : NSObject @property (weak, nonatomic) id delegate; @property (weak, nonatomic) id dataSource; + +// If the background color is applied via the pending state it's applied to the layer of the UITableView. +// Unfortunately UITableView does not consider using the layer backgroundColor property as it's background color, +// so it needs to be applied to the view after the ASTableNode did load and the view is available +@property (strong, nonatomic) UIColor *backgroundColor; @end @implementation _ASTablePendingState @@ -68,12 +73,13 @@ ASTableView *view = self.view; view.tableNode = self; - + if (_pendingState) { _ASTablePendingState *pendingState = _pendingState; self.pendingState = nil; view.asyncDelegate = pendingState.delegate; view.asyncDataSource = pendingState.dataSource; + view.backgroundColor = pendingState.backgroundColor; } } @@ -133,6 +139,25 @@ } } +- (void)setBackgroundColor:(UIColor *)backgroundColor +{ + if ([self pendingState]) { + _pendingState.backgroundColor = backgroundColor; + } else { + ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist"); + self.view.backgroundColor = backgroundColor; + } +} + +- (UIColor *)backgroundColor +{ + if ([self pendingState]) { + return _pendingState.backgroundColor; + } else { + return self.view.backgroundColor; + } +} + - (ASTableView *)view { return (ASTableView *)[super view];