Skip to content

Commit

Permalink
Minor changes to tint color support
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhuy committed Aug 15, 2019
1 parent b9903a4 commit e08a240
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
6 changes: 5 additions & 1 deletion Source/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,11 @@ AS_EXTERN NSInteger const ASDefaultDrawingPriority;
@property (nullable, copy) UIColor *backgroundColor; // default=nil

@property (null_resettable, copy) UIColor *tintColor; // default=Blue
- (void)tintColorDidChange; // Notifies the node when the tintColor has changed.

/**
* Notifies the node when it loaded and the tintColor has changed.
*/
- (void)tintColorDidChange;

/**
* @abstract A flag used to determine how a node lays out its content when its bounds change.
Expand Down
40 changes: 15 additions & 25 deletions Source/Private/ASDisplayNode+UIViewBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -795,47 +795,37 @@ - (void)setBackgroundColor:(UIColor *)newBackgroundColor
- (UIColor *)tintColor
{
__instanceLock__.lock();
UIColor *retVal;
if (_loaded(self)) {
if (_flags.layerBacked) {
// The first nondefault tint color value in the view’s hierarchy, ascending from and starting with the view itself.
retVal = _tintColor;
} else {
retVal = _getFromViewOnly(tintColor);
}
UIColor *retVal = nil;
BOOL shouldAscend = NO;
if (_flags.layerBacked) {
retVal = _tintColor;
// The first nondefault tint color value in the node’s hierarchy, ascending from and starting with the node itself.
shouldAscend = (retVal == nil);
} else {
if (_flags.layerBacked) {
retVal = _tintColor;
} else {
retVal = ASDisplayNodeGetPendingState(self).tintColor;
}
ASDisplayNodeAssertThreadAffinity(self);
retVal = _getFromViewOnly(tintColor);
}
__instanceLock__.unlock();
return retVal ?: self.supernode.tintColor;
return shouldAscend ? self.supernode.tintColor : retVal;
}

- (void)setTintColor:(UIColor *)color
{
// Handle locking manually since we unlock to notify subclasses when tint color changes
__instanceLock__.lock();
if (_loaded(self)) {
if (_flags.layerBacked) {
if (![_tintColor isEqual:color]) {
_tintColor = color;
if (_flags.layerBacked) {
if (![_tintColor isEqual:color]) {
_tintColor = color;

if (_loaded(self)) {
// Tint color has changed. Unlock here before calling subclasses and exit-early
__instanceLock__.unlock();
[self tintColorDidChange];
return;
}
} else {
_setToViewOnly(tintColor, color);
}
} else {
if (_flags.layerBacked) {
_tintColor = color;
} else {
ASDisplayNodeGetPendingState(self).tintColor = color;
}
_setToViewOnly(tintColor, color);
}
__instanceLock__.unlock();
}
Expand Down

0 comments on commit e08a240

Please sign in to comment.