diff --git a/Source/ASDisplayNode.mm b/Source/ASDisplayNode.mm index fa2d4c1bc..de18942ed 100644 --- a/Source/ASDisplayNode.mm +++ b/Source/ASDisplayNode.mm @@ -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; + } 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:]). diff --git a/Source/ASExperimentalFeatures.h b/Source/ASExperimentalFeatures.h index 62e7cda26..2a37aa233 100644 --- a/Source/ASExperimentalFeatures.h +++ b/Source/ASExperimentalFeatures.h @@ -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 }; diff --git a/Source/ASExperimentalFeatures.mm b/Source/ASExperimentalFeatures.mm index dd41e0981..d1a0b9431 100644 --- a/Source/ASExperimentalFeatures.mm +++ b/Source/ASExperimentalFeatures.mm @@ -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; diff --git a/Source/Private/ASDisplayNode+UIViewBridge.mm b/Source/Private/ASDisplayNode+UIViewBridge.mm index aa8e0e814..19a656558 100644 --- a/Source/Private/ASDisplayNode+UIViewBridge.mm +++ b/Source/Private/ASDisplayNode+UIViewBridge.mm @@ -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. @@ -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]) {