From 71ee5172abe3ce407b47a8adb3b0f5dd6545f902 Mon Sep 17 00:00:00 2001 From: yingchenw Date: Fri, 19 Feb 2021 01:35:20 +0000 Subject: [PATCH] Fix the bug of incorrect ELMContainerNode background color. The background of ELMContainerNode is created using a stretchable image, whose center 1x1 area will be later stretched to fit the entire content area. However, the color of the center area may be affected by its nearby pixels. This can cause the ELMContainerNode background area to have an incorrect background color. This fix repaints the center 1x1 area with the fillColor specified by the user. Fix some scuba tests. PRESUBMIT=passed BUG=179428110 FIXED=179428110 R=ganjam,konnork,rdarquea,siyusong,wiseoldduck,xpingzhou CC=jaceks,jayklub,yt-backstage+cl,yt-elements-eng+cl,yt-innertube-auto+changes,yt-ios-auto+cl,yt-ios-mainapp+cl,yt-reviewlog APPROVED=ganjam,konnork,siyusong,wiseoldduck,xpingzhou REQUIRED_REVIEW=1 DELTA_INCOMPLETE=9 (9 added, 0 deleted, 0 changed) DELTA_BY_EXTENSION=mm=9 OCL=356320759 FIG_CHANGESET=48007cddc301578950ddb29df65e18635e753b51 FIG_WORKSPACE=yingchenw/1362: P4 change: 358302665 --- Source/UIImage+ASConvenience.mm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/UIImage+ASConvenience.mm b/Source/UIImage+ASConvenience.mm index cc5896b4f..524ab5d17 100644 --- a/Source/UIImage+ASConvenience.mm +++ b/Source/UIImage+ASConvenience.mm @@ -214,6 +214,15 @@ + (UIImage *)as_resizableRoundedImageWithCornerRadius:(CGFloat)cornerRadius BOOL canUseCopy = (CGColorGetAlpha(borderColor.CGColor) == 1); [strokePath strokeWithBlendMode:(canUseCopy ? kCGBlendModeCopy : kCGBlendModeNormal) alpha:1]; } + // Refill the center area with fillColor since it may be contaminated by the sub pixel + // rendering. + if (borderWidth > 0) { + CGRect rect = CGRectMake(capInset, capInset, 1, 1); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextClearRect(context, rect); + CGContextSetFillColorWithColor(context, [fillColor CGColor]); + CGContextFillRect(context, rect); + } }); UIEdgeInsets capInsets = UIEdgeInsetsMake(cornerRadius, cornerRadius, cornerRadius, cornerRadius);