-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for tinting layer-backed ASDisplayNode #1617
Changes from 3 commits
e04c8dc
2095488
5533b88
d7ebd8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,11 @@ - (ASTextNode *)titleNode | |
ASLockScopeSelf(); | ||
if (!_titleNode) { | ||
_titleNode = [[ASTextNode alloc] init]; | ||
// Intentionally not layer-backing the image node since tintColor may be applied | ||
#if TARGET_OS_IOS | ||
// tvOS needs access to the underlying view | ||
// of the button node to add a touch handler. | ||
[_titleNode setLayerBacked:YES]; | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Thanks for fixing this. |
||
_titleNode.style.flexShrink = 1.0; | ||
_titleNode.textColorFollowsTintColor = YES; | ||
} | ||
|
@@ -66,7 +70,7 @@ - (ASImageNode *)imageNode | |
ASLockScopeSelf(); | ||
if (!_imageNode) { | ||
_imageNode = [[ASImageNode alloc] init]; | ||
// Intentionally not layer-backing the image node since tintColor may be applied | ||
[_imageNode setLayerBacked:YES]; | ||
} | ||
return _imageNode; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -796,15 +796,44 @@ - (void)setBackgroundColor:(UIColor *)newBackgroundColor | |
- (UIColor *)tintColor | ||
{ | ||
_bridge_prologue_read; | ||
ASDisplayNodeAssert(!_flags.layerBacked, @"Danger: this property is undefined on layer-backed nodes."); | ||
return _getFromViewOnly(tintColor); | ||
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. | ||
return _tintColor ?: self.supernode.tintColor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our locking principles don't allow walking up the hierarchy while holding the node's lock. So you'd need to do it after releasing the lock. |
||
} else { | ||
return _getFromViewOnly(tintColor); | ||
} | ||
} else { | ||
if (_flags.layerBacked) { | ||
return _tintColor; | ||
} else { | ||
return ASDisplayNodeGetPendingState(self).tintColor; | ||
} | ||
} | ||
} | ||
|
||
- (void)setTintColor:(UIColor *)color | ||
{ | ||
_bridge_prologue_write; | ||
ASDisplayNodeAssert(!_flags.layerBacked, @"Danger: this property is undefined on layer-backed nodes."); | ||
_setToViewOnly(tintColor, color); | ||
if (_loaded(self)) { | ||
if (_flags.layerBacked) { | ||
if (![_tintColor isEqual:color]) { | ||
_tintColor = color; | ||
// Tint color has changed. Unlock here before calling subclasses and exit-early | ||
AS::MutexLocker unlock(__instanceLock__); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might not be safe because the |
||
[self tintColorDidChange]; | ||
return; | ||
} | ||
} else { | ||
_setToViewOnly(tintColor, color); | ||
} | ||
} else { | ||
if (_flags.layerBacked) { | ||
_tintColor = color; | ||
} else { | ||
ASDisplayNodeGetPendingState(self).tintColor = color; | ||
} | ||
} | ||
} | ||
|
||
- (void)tintColorDidChange | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is from the original impl, but the comment and the code don't add up. If the view is needed under tvOS, then this node should not be layer-backed under it (and can be layer-backed otherwise)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment might be misleading here, I think the intention was to gate this layer backing only for iOS and by doing nothing in tvOS it will automatically be view backed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can make this clearer at least