mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-03-29 08:39:00 +08:00
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:
@@ -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];
|
||||
|
||||
@@ -14,6 +14,11 @@
|
||||
@interface _ASTablePendingState : NSObject
|
||||
@property (weak, nonatomic) id <ASTableDelegate> delegate;
|
||||
@property (weak, nonatomic) id <ASTableDataSource> 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];
|
||||
|
||||
Reference in New Issue
Block a user