From 3555125958968f44b95e43e29672ed65af639d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BD=90=E5=B1=B1?= Date: Fri, 31 Mar 2017 21:03:29 +0800 Subject: [PATCH] + [ios] change to color --- .../Sources/Display/WXComponent+BoxShadow.h | 2 +- .../Sources/Display/WXComponent+BoxShadow.m | 10 ++++---- .../WeexSDK/Sources/Display/WXInnerLayer.h | 2 +- .../WeexSDK/Sources/Display/WXInnerLayer.m | 4 ++-- .../Sources/Layout/WXComponent+Layout.m | 2 +- ios/sdk/WeexSDK/Sources/Utility/WXBoxShadow.h | 2 +- ios/sdk/WeexSDK/Sources/Utility/WXBoxShadow.m | 23 ++----------------- 7 files changed, 13 insertions(+), 32 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Display/WXComponent+BoxShadow.h b/ios/sdk/WeexSDK/Sources/Display/WXComponent+BoxShadow.h index 2c1a645afd..d7fe12e5aa 100644 --- a/ios/sdk/WeexSDK/Sources/Display/WXComponent+BoxShadow.h +++ b/ios/sdk/WeexSDK/Sources/Display/WXComponent+BoxShadow.h @@ -21,7 +21,7 @@ * * @return if not equal return NO, if equal return YES */ -- (BOOL)EqualBoxShadow:(WXBoxShadow *_Nullable)boxShadow withBoxShadow:(WXBoxShadow *_Nullable)compareBoxShadow; +- (BOOL)equalBoxShadow:(WXBoxShadow *_Nullable)boxShadow withBoxShadow:(WXBoxShadow *_Nullable)compareBoxShadow; /** * @abstract config view Layer with boxshadow, lastboxshadow and originalBoxShadow diff --git a/ios/sdk/WeexSDK/Sources/Display/WXComponent+BoxShadow.m b/ios/sdk/WeexSDK/Sources/Display/WXComponent+BoxShadow.m index ba9927be6d..6b8a7a7fda 100644 --- a/ios/sdk/WeexSDK/Sources/Display/WXComponent+BoxShadow.m +++ b/ios/sdk/WeexSDK/Sources/Display/WXComponent+BoxShadow.m @@ -18,7 +18,7 @@ @implementation WXComponent (BoxShadow) - (WXBoxShadow *_Nullable)getViewBoxShadow:(UIView *_Nullable)view { WXBoxShadow *boxShadow = [WXBoxShadow new]; - boxShadow.shadowColor = view.layer.shadowColor; + boxShadow.shadowColor = [UIColor colorWithCGColor:view.layer.shadowColor]; boxShadow.shadowOffset = view.layer.shadowOffset; boxShadow.shadowRadius = view.layer.shadowRadius; boxShadow.shadowOpacity = view.layer.shadowOpacity; @@ -29,7 +29,7 @@ - (void)resetViewLayer { UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds]; self.view.layer.masksToBounds = NO; - self.view.layer.shadowColor = _originalBoxShadow.shadowColor; + self.view.layer.shadowColor = _originalBoxShadow.shadowColor.CGColor; self.view.layer.shadowOffset = _originalBoxShadow.shadowOffset; self.view.layer.shadowRadius = _originalBoxShadow.shadowRadius; self.view.layer.shadowOpacity = _originalBoxShadow.shadowOpacity; @@ -44,11 +44,11 @@ - (void)resetViewLayer } // if not equal return NO, if equal return YES -- (BOOL)EqualBoxShadow:(WXBoxShadow *_Nullable)boxShadow withBoxShadow:(WXBoxShadow *_Nullable)compareBoxShadow +- (BOOL)equalBoxShadow:(WXBoxShadow *_Nullable)boxShadow withBoxShadow:(WXBoxShadow *_Nullable)compareBoxShadow { if(!compareBoxShadow && !boxShadow) { return YES; - } else if (CGColorEqualToColor(boxShadow.shadowColor,compareBoxShadow.shadowColor) && + } else if (CGColorEqualToColor(boxShadow.shadowColor.CGColor,compareBoxShadow.shadowColor.CGColor) && CGSizeEqualToSize(boxShadow.shadowOffset,compareBoxShadow.shadowOffset) && WXFloatEqual(boxShadow.shadowRadius,compareBoxShadow.shadowRadius)&& (boxShadow.isInset == compareBoxShadow.isInset)) { @@ -80,7 +80,7 @@ - (void)configBoxShadow:(WXBoxShadow *_Nullable)boxShadow } else { UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds]; self.view.layer.masksToBounds = NO; - self.view.layer.shadowColor = boxShadow.shadowColor; + self.view.layer.shadowColor = boxShadow.shadowColor.CGColor; self.view.layer.shadowOffset = boxShadow.shadowOffset; self.view.layer.shadowRadius = boxShadow.shadowRadius; self.view.layer.shadowOpacity = boxShadow.shadowOpacity; diff --git a/ios/sdk/WeexSDK/Sources/Display/WXInnerLayer.h b/ios/sdk/WeexSDK/Sources/Display/WXInnerLayer.h index f3b2bf43aa..82337dec60 100644 --- a/ios/sdk/WeexSDK/Sources/Display/WXInnerLayer.h +++ b/ios/sdk/WeexSDK/Sources/Display/WXInnerLayer.h @@ -12,7 +12,7 @@ @interface WXInnerLayer : CAGradientLayer @property CGFloat boxShadowRadius; -@property CGColorRef boxShadowColor; +@property (nonatomic,strong) UIColor *boxShadowColor; @property CGSize boxShadowOffset; @property CGFloat boxShadowOpacity; diff --git a/ios/sdk/WeexSDK/Sources/Display/WXInnerLayer.m b/ios/sdk/WeexSDK/Sources/Display/WXInnerLayer.m index e49c5b6a8c..4029ddb843 100644 --- a/ios/sdk/WeexSDK/Sources/Display/WXInnerLayer.m +++ b/ios/sdk/WeexSDK/Sources/Display/WXInnerLayer.m @@ -50,9 +50,9 @@ - (void)drawInContext:(CGContextRef)context { CGPathAddRect(outer, NULL, CGRectInset(rect, -1*rect.size.width, -1*rect.size.height)); CGPathAddPath(outer, NULL, bezierPath.CGPath); CGPathCloseSubpath(outer); - CGFloat *oldComponents = (CGFloat *)CGColorGetComponents(self.boxShadowColor); + CGFloat *oldComponents = (CGFloat *)CGColorGetComponents(self.boxShadowColor.CGColor); CGFloat newComponents[4]; - NSInteger numberOfComponents = CGColorGetNumberOfComponents(self.boxShadowColor); + NSInteger numberOfComponents = CGColorGetNumberOfComponents(self.boxShadowColor.CGColor); switch (numberOfComponents) { case 2: diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.m b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.m index 350f9e29f3..ca2402657c 100644 --- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.m +++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.m @@ -122,7 +122,7 @@ - (void)_frameDidCalculated:(BOOL)isChanged strongSelf.view.frame = strongSelf.calculatedFrame; [strongSelf configBoxShadow:_boxShadow]; } else { - if (![strongSelf EqualBoxShadow:_boxShadow withBoxShadow:_lastBoxShadow]) { + if (![strongSelf equalBoxShadow:_boxShadow withBoxShadow:_lastBoxShadow]) { [strongSelf configBoxShadow:_boxShadow]; } } diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXBoxShadow.h b/ios/sdk/WeexSDK/Sources/Utility/WXBoxShadow.h index 01dfa5c3e1..5f0faeee07 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXBoxShadow.h +++ b/ios/sdk/WeexSDK/Sources/Utility/WXBoxShadow.h @@ -11,7 +11,7 @@ @interface WXBoxShadow : NSObject -@property(nullable) CGColorRef shadowColor; +@property(nonatomic,strong,nullable) UIColor *shadowColor; @property CGSize shadowOffset; @property CGFloat shadowRadius; @property BOOL isInset; diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXBoxShadow.m b/ios/sdk/WeexSDK/Sources/Utility/WXBoxShadow.m index 454be39e63..4cb9181981 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXBoxShadow.m +++ b/ios/sdk/WeexSDK/Sources/Utility/WXBoxShadow.m @@ -12,11 +12,6 @@ @implementation WXBoxShadow -- (void) dealloc -{ - CGColorRelease(self.shadowColor); -} - - (instancetype)init { self = [super init]; @@ -31,20 +26,6 @@ - (instancetype)init return self; } -- (CGColorRef)shadowColor { - return self.shadowColor; -} - -- (void)setShadowColor: (CGColorRef)shadowColor -{ - if (shadowColor == self.shadowColor) - return; - - CGColorRetain(shadowColor); - CGColorRelease(self.shadowColor); - self.shadowColor = shadowColor; -} - + (NSArray *)getBoxShadowElementsByBlank:(NSString *)string { string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; @@ -77,7 +58,7 @@ +(WXBoxShadow *_Nullable)getBoxShadowFromString:(NSString *_Nullable)string scal NSString *str = [string substringWithRange:range]; UIColor *color = [WXConvert UIColor:str]; if (color && [color isKindOfClass:[UIColor class]]) { - boxShadow.shadowColor = color.CGColor; + boxShadow.shadowColor = color; } string = [string stringByReplacingOccurrencesOfString:str withString:@""];// remove color string } @@ -86,7 +67,7 @@ +(WXBoxShadow *_Nullable)getBoxShadowFromString:(NSString *_Nullable)string scal NSString *str = [boxShadowElements lastObject]; UIColor *color = [WXConvert UIColor:str]; if (color && [color isKindOfClass:[UIColor class]]) { - boxShadow.shadowColor = color.CGColor; + boxShadow.shadowColor = color; } string = [string stringByReplacingOccurrencesOfString:str withString:@""];// remove color string }