From 4ed2120cfa132d78cffaa4b8e38f1039e39b8db1 Mon Sep 17 00:00:00 2001 From: David Beck Date: Thu, 23 Oct 2014 19:51:10 -0700 Subject: [PATCH] Added tintColor convenience methods tintColor is now forwarded to the underlying view, and much more importantly, the node is notified when the tintColor changes on the view. --- AsyncDisplayKit/ASDisplayNode.h | 3 +++ .../Details/UIView+ASConvenience.h | 1 + AsyncDisplayKit/Details/_ASDisplayView.mm | 7 +++++++ .../Private/ASDisplayNode+UIViewBridge.mm | 19 +++++++++++++++++++ AsyncDisplayKit/Private/_ASPendingState.m | 12 ++++++++++++ 5 files changed, 42 insertions(+) diff --git a/AsyncDisplayKit/ASDisplayNode.h b/AsyncDisplayKit/ASDisplayNode.h index ad445c9b91..5b4121e533 100644 --- a/AsyncDisplayKit/ASDisplayNode.h +++ b/AsyncDisplayKit/ASDisplayNode.h @@ -474,6 +474,9 @@ */ @property (atomic, retain) UIColor *backgroundColor; // default=nil +@property (atomic, retain) UIColor *tintColor; // default=Blue +- (void)tintColorDidChange; // Notifies the node when the tintColor has changed. + /** * @abstract A flag used to determine how a node lays out its content when its bounds change. * diff --git a/AsyncDisplayKit/Details/UIView+ASConvenience.h b/AsyncDisplayKit/Details/UIView+ASConvenience.h index efbd8d8b25..f75fdbafd6 100644 --- a/AsyncDisplayKit/Details/UIView+ASConvenience.h +++ b/AsyncDisplayKit/Details/UIView+ASConvenience.h @@ -48,6 +48,7 @@ @property (nonatomic, getter=isHidden) BOOL hidden; @property (nonatomic, assign) BOOL autoresizesSubviews; @property (nonatomic, assign) UIViewAutoresizing autoresizingMask; +@property (nonatomic, retain) UIColor *tintColor; @property (nonatomic, assign) CGFloat alpha; @property (nonatomic, assign) CGRect bounds; @property (nonatomic, assign) UIViewContentMode contentMode; diff --git a/AsyncDisplayKit/Details/_ASDisplayView.mm b/AsyncDisplayKit/Details/_ASDisplayView.mm index 0d10bfeb6d..86f1f8e8fa 100644 --- a/AsyncDisplayKit/Details/_ASDisplayView.mm +++ b/AsyncDisplayKit/Details/_ASDisplayView.mm @@ -213,4 +213,11 @@ [_node asyncdisplaykit_asyncTransactionContainerStateDidChange]; } +- (void)tintColorDidChange +{ + [super tintColorDidChange]; + + [_node tintColorDidChange]; +} + @end diff --git a/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm b/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm index b22554e04e..578e3a2880 100644 --- a/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm +++ b/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm @@ -364,6 +364,25 @@ _setToLayer(backgroundColor, backgroundColor.CGColor); } +- (UIColor *)tintColor +{ + _bridge_prologue; + ASDisplayNodeAssert(!_flags.isLayerBacked, @"Danger: this property is undefined on layer-backed nodes."); + return _getFromViewOnly(tintColor); +} + +- (void)setTintColor:(UIColor *)color +{ + _bridge_prologue; + ASDisplayNodeAssert(!_flags.isLayerBacked, @"Danger: this property is undefined on layer-backed nodes."); + _setToViewOnly(tintColor, color); +} + +- (void)tintColorDidChange +{ + // ignore this, allow subclasses to be notified +} + - (CGColorRef)shadowColor { _bridge_prologue; diff --git a/AsyncDisplayKit/Private/_ASPendingState.m b/AsyncDisplayKit/Private/_ASPendingState.m index 94312fad6c..2a35a7908b 100644 --- a/AsyncDisplayKit/Private/_ASPendingState.m +++ b/AsyncDisplayKit/Private/_ASPendingState.m @@ -61,6 +61,7 @@ int setAutoresizingMask:1; int setBounds:1; int setBackgroundColor:1; + int setTintColor:1; int setContents:1; int setHidden:1; int setAlpha:1; @@ -109,6 +110,7 @@ @synthesize edgeAntialiasingMask=edgeAntialiasingMask; @synthesize autoresizesSubviews=autoresizesSubviews; @synthesize autoresizingMask=autoresizingMask; +@synthesize tintColor=tintColor; @synthesize alpha=alpha; @synthesize contentMode=contentMode; @synthesize anchorPoint=anchorPoint; @@ -148,6 +150,7 @@ opaque = YES; bounds = CGRectZero; backgroundColor = nil; + tintColor = [UIColor colorWithRed:0.0 green:0.478 blue:1.0 alpha:1.0]; contents = nil; isHidden = NO; needsDisplayOnBoundsChange = NO; @@ -265,6 +268,12 @@ _flags.setBackgroundColor = YES; } +- (void)setTintColor:(UIColor *)newTintColor +{ + tintColor = newTintColor; + _flags.setTintColor = YES; +} + - (void)setContents:(id)newContents { if (contents == newContents) { @@ -652,6 +661,9 @@ if (_flags.setBackgroundColor) layer.backgroundColor = backgroundColor; + if (_flags.setTintColor) + view.tintColor = self.tintColor; + if (_flags.setOpaque) view.layer.opaque = opaque;