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

Commit ce42fd6

Browse files
author
qianyuan.wqy
committed
[iOS] Use lock to add mutex for _backgroundColor property usage.
1 parent e2ca906 commit ce42fd6

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,15 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size
349349

350350
CGContextSetAlpha(context, _opacity);
351351
// fill background color
352-
if (_backgroundColor && CGColorGetAlpha(_backgroundColor.CGColor) > 0) {
353-
CGContextSetFillColorWithColor(context, _backgroundColor.CGColor);
354-
UIBezierPath *bezierPath = [UIBezierPath wx_bezierPathWithRoundedRect:rect topLeft:topLeft topRight:topRight bottomLeft:bottomLeft bottomRight:bottomRight];
355-
[bezierPath fill];
356-
WXPerformBlockOnMainThread(^{
357-
_view.backgroundColor = UIColor.clearColor;
358-
});
352+
@synchronized (self) {
353+
if (_backgroundColor && CGColorGetAlpha(_backgroundColor.CGColor) > 0) {
354+
CGContextSetFillColorWithColor(context, _backgroundColor.CGColor);
355+
UIBezierPath *bezierPath = [UIBezierPath wx_bezierPathWithRoundedRect:rect topLeft:topLeft topRight:topRight bottomLeft:bottomLeft bottomRight:bottomRight];
356+
[bezierPath fill];
357+
WXPerformBlockOnMainThread(^{
358+
_view.backgroundColor = UIColor.clearColor;
359+
});
360+
}
359361
}
360362
// Top
361363
if (_borderTopWidth > 0) {

ios/sdk/WeexSDK/Sources/Model/WXComponent.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,9 @@ - (void)setGradientLayer
857857
UIColor * endColor = (UIColor*)linearGradient[@"endColor"];
858858
CAGradientLayer * gradientLayer = [WXUtility gradientLayerFromColors:@[startColor, endColor] locations:nil frame:strongSelf.view.bounds gradientType:(WXGradientType)[linearGradient[@"gradientType"] integerValue]];
859859
if (gradientLayer) {
860-
_backgroundColor = [UIColor colorWithPatternImage:[strongSelf imageFromLayer:gradientLayer]];
860+
@synchronized (strongSelf) {
861+
_backgroundColor = [UIColor colorWithPatternImage:[strongSelf imageFromLayer:gradientLayer]];
862+
}
861863
strongSelf.view.backgroundColor = _backgroundColor;
862864
[strongSelf setNeedsDisplay];
863865
}

ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ - (void)_transitionUpdateViewProperty:(NSDictionary *)styles
193193
{
194194
WX_CHECK_COMPONENT_TYPE(self.componentType)
195195
if (styles[@"backgroundColor"]) {
196-
_backgroundColor = [WXConvert UIColor:styles[@"backgroundColor"]];
196+
@synchronized (self) {
197+
_backgroundColor = [WXConvert UIColor:styles[@"backgroundColor"]];
198+
}
197199
}
198200
if (styles[@"opacity"]) {
199201
_opacity = [WXConvert CGFloat:styles[@"opacity"]];
@@ -211,7 +213,9 @@ - (void)_updateViewStyles:(NSDictionary *)styles
211213
}
212214

213215
if (styles[@"backgroundColor"]) {
214-
_backgroundColor = [WXConvert UIColor:styles[@"backgroundColor"]];
216+
@synchronized (self) {
217+
_backgroundColor = [WXConvert UIColor:styles[@"backgroundColor"]];
218+
}
215219
[self setNeedsDisplay];
216220
}
217221

@@ -307,7 +311,9 @@ - (void)resetBorder:(NSArray *)styles
307311
- (void)_resetStyles:(NSArray *)styles
308312
{
309313
if (styles && [styles containsObject:@"backgroundColor"]) {
310-
_backgroundColor = [UIColor clearColor];
314+
@synchronized (self) {
315+
_backgroundColor = [UIColor clearColor];
316+
}
311317
[self setNeedsDisplay];
312318
}
313319
if (styles && [styles containsObject:@"boxShadow"]) {

0 commit comments

Comments
 (0)