Fix ASTableNode / ASCollectionNode backgroundColor does not work

If the background color is applied via the pending state it's applied to the layer of the UICollectionView / UITableview. Unfortunately UITableView / 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 / ASTableNode did load and the view is available
This commit is contained in:
Michael Schneider
2016-04-15 10:50:10 -07:00
parent 103506beec
commit 8d20321d67
2 changed files with 50 additions and 1 deletions

View File

@@ -16,6 +16,11 @@
@interface _ASCollectionPendingState : NSObject
@property (weak, nonatomic) id <ASCollectionDelegate> delegate;
@property (weak, nonatomic) id <ASCollectionDataSource> 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];