Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] Use lock to add mutex for _backgroundColor property usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
qianyuan.wqy committed Sep 30, 2019
1 parent e2ca906 commit ce42fd6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
16 changes: 9 additions & 7 deletions ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,15 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size

CGContextSetAlpha(context, _opacity);
// fill background color
if (_backgroundColor && CGColorGetAlpha(_backgroundColor.CGColor) > 0) {
CGContextSetFillColorWithColor(context, _backgroundColor.CGColor);
UIBezierPath *bezierPath = [UIBezierPath wx_bezierPathWithRoundedRect:rect topLeft:topLeft topRight:topRight bottomLeft:bottomLeft bottomRight:bottomRight];
[bezierPath fill];
WXPerformBlockOnMainThread(^{
_view.backgroundColor = UIColor.clearColor;
});
@synchronized (self) {
if (_backgroundColor && CGColorGetAlpha(_backgroundColor.CGColor) > 0) {
CGContextSetFillColorWithColor(context, _backgroundColor.CGColor);
UIBezierPath *bezierPath = [UIBezierPath wx_bezierPathWithRoundedRect:rect topLeft:topLeft topRight:topRight bottomLeft:bottomLeft bottomRight:bottomRight];
[bezierPath fill];
WXPerformBlockOnMainThread(^{
_view.backgroundColor = UIColor.clearColor;
});
}
}
// Top
if (_borderTopWidth > 0) {
Expand Down
4 changes: 3 additions & 1 deletion ios/sdk/WeexSDK/Sources/Model/WXComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,9 @@ - (void)setGradientLayer
UIColor * endColor = (UIColor*)linearGradient[@"endColor"];
CAGradientLayer * gradientLayer = [WXUtility gradientLayerFromColors:@[startColor, endColor] locations:nil frame:strongSelf.view.bounds gradientType:(WXGradientType)[linearGradient[@"gradientType"] integerValue]];
if (gradientLayer) {
_backgroundColor = [UIColor colorWithPatternImage:[strongSelf imageFromLayer:gradientLayer]];
@synchronized (strongSelf) {
_backgroundColor = [UIColor colorWithPatternImage:[strongSelf imageFromLayer:gradientLayer]];
}
strongSelf.view.backgroundColor = _backgroundColor;
[strongSelf setNeedsDisplay];
}
Expand Down
12 changes: 9 additions & 3 deletions ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ - (void)_transitionUpdateViewProperty:(NSDictionary *)styles
{
WX_CHECK_COMPONENT_TYPE(self.componentType)
if (styles[@"backgroundColor"]) {
_backgroundColor = [WXConvert UIColor:styles[@"backgroundColor"]];
@synchronized (self) {
_backgroundColor = [WXConvert UIColor:styles[@"backgroundColor"]];
}
}
if (styles[@"opacity"]) {
_opacity = [WXConvert CGFloat:styles[@"opacity"]];
Expand All @@ -211,7 +213,9 @@ - (void)_updateViewStyles:(NSDictionary *)styles
}

if (styles[@"backgroundColor"]) {
_backgroundColor = [WXConvert UIColor:styles[@"backgroundColor"]];
@synchronized (self) {
_backgroundColor = [WXConvert UIColor:styles[@"backgroundColor"]];
}
[self setNeedsDisplay];
}

Expand Down Expand Up @@ -307,7 +311,9 @@ - (void)resetBorder:(NSArray *)styles
- (void)_resetStyles:(NSArray *)styles
{
if (styles && [styles containsObject:@"backgroundColor"]) {
_backgroundColor = [UIColor clearColor];
@synchronized (self) {
_backgroundColor = [UIColor clearColor];
}
[self setNeedsDisplay];
}
if (styles && [styles containsObject:@"boxShadow"]) {
Expand Down

0 comments on commit ce42fd6

Please sign in to comment.