You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by mo...@apache.org on 2019/09/30 08:44:32 UTC

[incubator-weex] 04/04: [iOS] Use lock to add mutex for _backgroundColor property usage.

This is an automated email from the ASF dual-hosted git repository.

moshen pushed a commit to branch revert-backgroundcolor
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git

commit ce42fd61096c05184097681292502dcc3dc146aa
Author: qianyuan.wqy <qi...@taobao.com>
AuthorDate: Mon Sep 30 16:44:16 2019 +0800

    [iOS] Use lock to add mutex for _backgroundColor property usage.
---
 ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m    | 16 +++++++++-------
 ios/sdk/WeexSDK/Sources/Model/WXComponent.mm             |  4 +++-
 .../WeexSDK/Sources/View/WXComponent+ViewManagement.mm   | 12 +++++++++---
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
index 9acb010..021bf07 100644
--- a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
+++ b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
@@ -349,13 +349,15 @@ typedef NS_ENUM(NSInteger, WXComponentBorderRecord) {
     
     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) {
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm
index a60251c..9e44231 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm
@@ -857,7 +857,9 @@ static BOOL bNeedRemoveEvents = YES;
             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];
             }
diff --git a/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm b/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm
index 3d97548..4c184a0 100644
--- a/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm
+++ b/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm
@@ -193,7 +193,9 @@ do {\
 {
     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"]];
@@ -211,7 +213,9 @@ do {\
     }
     
     if (styles[@"backgroundColor"]) {
-        _backgroundColor = [WXConvert UIColor:styles[@"backgroundColor"]];
+        @synchronized (self) {
+            _backgroundColor = [WXConvert UIColor:styles[@"backgroundColor"]];
+        }
         [self setNeedsDisplay];
     }
     
@@ -307,7 +311,9 @@ do {\
 - (void)_resetStyles:(NSArray *)styles
 {
     if (styles && [styles containsObject:@"backgroundColor"]) {
-        _backgroundColor = [UIColor clearColor];
+        @synchronized (self) {
+            _backgroundColor = [UIColor clearColor];
+        }
         [self setNeedsDisplay];
     }
     if (styles && [styles containsObject:@"boxShadow"]) {