From a3e78d1ceec87005fb92f21daa9d358651a90057 Mon Sep 17 00:00:00 2001 From: Nadine Salter Date: Mon, 3 Nov 2014 17:20:37 -0800 Subject: [PATCH] Support background colour and selection style on ASCellNodes. Most UITableViewCell properties aren't useful in conjunction with ASCellNode -- the system's UIView properties are unsupported for performance reasons, and properties that configure them (e.g., content indentation) don't affect custom node hierarchies. This patch adds support to _ASTableViewCell for the properties that *are* useful. r=scottg --- AsyncDisplayKit/ASCellNode.h | 6 +++++- AsyncDisplayKit/ASCellNode.m | 3 +++ AsyncDisplayKit/ASTableView.m | 2 +- AsyncDisplayKit/Details/ASRangeController.h | 9 +++++++++ AsyncDisplayKit/Details/ASRangeController.mm | 9 +++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/AsyncDisplayKit/ASCellNode.h b/AsyncDisplayKit/ASCellNode.h index 8308502335..41a4dfcbc7 100644 --- a/AsyncDisplayKit/ASCellNode.h +++ b/AsyncDisplayKit/ASCellNode.h @@ -13,7 +13,11 @@ */ @interface ASCellNode : ASDisplayNode -// TODO expose some UITableViewCell properties for configuration, eg, separator style +/* + * ASTableView uses these properties when configuring UITableViewCells that host ASCellNodes. + */ +//@property (atomic, retain) UIColor *backgroundColor; +@property (nonatomic) UITableViewCellSelectionStyle selectionStyle; @end diff --git a/AsyncDisplayKit/ASCellNode.m b/AsyncDisplayKit/ASCellNode.m index dacf04a811..6979336f36 100644 --- a/AsyncDisplayKit/ASCellNode.m +++ b/AsyncDisplayKit/ASCellNode.m @@ -31,6 +31,9 @@ if (!(self = [super init])) return nil; + // use UITableViewCell defaults + _selectionStyle = UITableViewCellSelectionStyleDefault; + return self; } diff --git a/AsyncDisplayKit/ASTableView.m b/AsyncDisplayKit/ASTableView.m index 4502b015ba..ee819acd9f 100644 --- a/AsyncDisplayKit/ASTableView.m +++ b/AsyncDisplayKit/ASTableView.m @@ -261,7 +261,7 @@ static BOOL _isInterceptedSelector(SEL sel) cell = [[_ASTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]; } - [_rangeController configureContentView:cell.contentView forIndexPath:indexPath]; + [_rangeController configureTableViewCell:cell forIndexPath:indexPath]; return cell; } diff --git a/AsyncDisplayKit/Details/ASRangeController.h b/AsyncDisplayKit/Details/ASRangeController.h index 94b8a7187a..22821f430e 100644 --- a/AsyncDisplayKit/Details/ASRangeController.h +++ b/AsyncDisplayKit/Details/ASRangeController.h @@ -50,6 +50,15 @@ typedef struct { - (NSInteger)numberOfSizedSections; - (NSInteger)numberOfSizedRowsInSection:(NSInteger)section; +/** + * Configure the specified UITableViewCell's content view, and apply properties from ASCellNode. + * + * @param cell UITableViewCell to configure. + * + * @param indexPath Index path for the node of interest. + */ +- (void)configureTableViewCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath; + /** * Add the sized node for `indexPath` as a subview of `contentView`. * diff --git a/AsyncDisplayKit/Details/ASRangeController.mm b/AsyncDisplayKit/Details/ASRangeController.mm index fd0464ab8d..c9a9e00fd4 100644 --- a/AsyncDisplayKit/Details/ASRangeController.mm +++ b/AsyncDisplayKit/Details/ASRangeController.mm @@ -351,6 +351,15 @@ static BOOL ASRangeIsValid(NSRange range) } } +- (void)configureTableViewCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath +{ + [self configureContentView:cell.contentView forIndexPath:indexPath]; + + ASCellNode *node = [self sizedNodeForIndexPath:indexPath]; + cell.backgroundColor = node.backgroundColor; + cell.selectionStyle = node.selectionStyle; +} + - (void)configureContentView:(UIView *)contentView forIndexPath:(NSIndexPath *)indexPath { ASCellNode *newNode = [self sizedNodeForIndexPath:indexPath];