Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,17 @@ - (void)asyncTraitCollectionDidChangeWithPreviousTraitCollection:(ASPrimitiveTra
CGFloat cornerRadius = self->_cornerRadius;
ASCornerRoundingType cornerRoundingType = self->_cornerRoundingType;
UIColor *backgroundColor = self->_backgroundColor;
ASPrimitiveTraitCollection currentPrimitiveTraitCollection = self->_primitiveTraitCollection;
self->__instanceLock__.unlock();
// TODO: we should resolve color using node's trait collection
// but Texture changes it from many places, so we may receive the wrong one.
CGColorRef cgBackgroundColor = backgroundColor.CGColor;
CGColorRef cgBackgroundColor;
if (ASActivateExperimentalFeature(ASExperimentalResolveBackgroundColorWithNodeTraits)) {
UITraitCollection *traitCollection = ASPrimitiveTraitCollectionToUITraitCollection(currentPrimitiveTraitCollection);
cgBackgroundColor = [backgroundColor resolvedColorWithTraitCollection:traitCollection].CGColor;
} else {
// TODO: we should resolve color using node's trait collection
// but Texture changes it from many places, so we may receive the wrong one.
cgBackgroundColor = backgroundColor.CGColor;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to be a revert of 70f61e9, did the way nodes receive trait collections change?

if (!CGColorEqualToColor(self->_layer.backgroundColor, cgBackgroundColor)) {
// Background colors do not dynamically update for layer backed nodes since they utilize CGColorRef
// instead of UIColor. Non layer backed node also receive color to the layer (see [_ASPendingState -applyToView:withSpecialPropertiesHandling:]).
Expand Down
1 change: 1 addition & 0 deletions Source/ASExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) {
ASExperimentalLockTextRendererCache = 1 << 14, // exp_lock_text_renderer_cache
ASExperimentalHierarchyDisplayDidFinishIsRecursive = 1 << 15, // exp_hierarchy_display_did_finish_is_recursive
ASExperimentalCheckBatchFetchingOnScroll = 1 << 16, // exp_check_batch_fetching_on_scroll
ASExperimentalResolveBackgroundColorWithNodeTraits = 1 << 17, // exp_resolve_background_color_with_node_traits
ASExperimentalFeatureAll = 0xFFFFFFFF
};

Expand Down
3 changes: 2 additions & 1 deletion Source/ASExperimentalFeatures.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
@"exp_no_text_renderer_cache",
@"exp_lock_text_renderer_cache",
@"exp_hierarchy_display_did_finish_is_recursive",
@"exp_check_batch_fetching_on_scroll"]));
@"exp_check_batch_fetching_on_scroll",
@"exp_resolve_background_color_with_node_traits"]));

if (flags == ASExperimentalFeatureAll) {
return allNames;
Expand Down
6 changes: 4 additions & 2 deletions Source/Private/ASDisplayNode+UIViewBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,10 @@ - (void)setBackgroundColor:(UIColor *)newBackgroundColor
if (shouldApply) {
UIColor *oldBackgroundColor = _backgroundColor;
_backgroundColor = newBackgroundColor;
BOOL resolveWithNodeTraits = ASActivateExperimentalFeature(ASExperimentalResolveBackgroundColorWithNodeTraits);
UITraitCollection *traitCollection = resolveWithNodeTraits ? ASPrimitiveTraitCollectionToUITraitCollection(_primitiveTraitCollection) : nil;
if (_flags.layerBacked) {
_layer.backgroundColor = _backgroundColor.CGColor;
_layer.backgroundColor = resolveWithNodeTraits ? [_backgroundColor resolvedColorWithTraitCollection:traitCollection].CGColor : _backgroundColor.CGColor;
} else {
/*
NOTE: Setting to the view and layer individually is necessary.
Expand All @@ -775,7 +777,7 @@ - (void)setBackgroundColor:(UIColor *)newBackgroundColor
*/
_view.backgroundColor = _backgroundColor;
// Gather the CGColorRef from the view incase there are any changes it might apply to which CGColorRef is returned for dynamic colors
_layer.backgroundColor = _view.backgroundColor.CGColor;
_layer.backgroundColor = resolveWithNodeTraits ? [_backgroundColor resolvedColorWithTraitCollection:traitCollection].CGColor : _view.backgroundColor.CGColor;
}

if (![oldBackgroundColor isEqual:newBackgroundColor]) {
Expand Down
Loading