You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2017/08/22 08:26:59 UTC

[7/9] incubator-weex git commit: * [ios] add UIColor test function

* [ios] add UIColor test function


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/1d87ab3e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/1d87ab3e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/1d87ab3e

Branch: refs/heads/0.16-dev
Commit: 1d87ab3e9078cbaa4ee25d35ec23177d96df4d80
Parents: 2474c2d
Author: doumafang <do...@gmail.com>
Authored: Tue Aug 22 15:05:44 2017 +0800
Committer: doumafang <do...@gmail.com>
Committed: Tue Aug 22 15:05:44 2017 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK/Sources/Module/WXTransition.m   | 24 +++-----------------
 ios/sdk/WeexSDK/Sources/Utility/WXConvert.h     |  1 +
 ios/sdk/WeexSDK/Sources/Utility/WXConvert.m     | 17 ++++++++++++++
 .../Sources/View/WXComponent+ViewManagement.m   |  1 -
 ios/sdk/WeexSDKTests/WXConvertTests.m           | 17 +++++++++++---
 5 files changed, 35 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1d87ab3e/ios/sdk/WeexSDK/Sources/Module/WXTransition.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Module/WXTransition.m b/ios/sdk/WeexSDK/Sources/Module/WXTransition.m
index 9bb903b..be963ae 100644
--- a/ios/sdk/WeexSDK/Sources/Module/WXTransition.m
+++ b/ios/sdk/WeexSDK/Sources/Module/WXTransition.m
@@ -259,23 +259,6 @@
     return @[@(R),@(G),@(B),@(A)];
 }
 
-- (NSString *)_hexWithColor:(UIColor *)color
-{
-    uint hex;
-    CGFloat red, green, blue, alpha;
-    if (![color getRed:&red green:&green blue:&blue alpha:&alpha]) {
-        [color getWhite:&red alpha:&alpha];
-        green = red;
-        blue = red;
-    }
-    red = roundf(red * 255.f);
-    green = roundf(green * 255.f);
-    blue = roundf(blue * 255.f);
-    alpha = roundf(alpha * 255.f);
-    hex =  ((uint)red << 16) | ((uint)green << 8) | ((uint)blue);
-    return [NSString stringWithFormat:@"#%02x", hex];
-}
-
 - (void)_calculateLayoutAnimationProcessingStyle
 {
     if (_propertyArray.count == 0) {
@@ -297,7 +280,7 @@
                 _targetComponent.view.backgroundColor = color;
                 [_targetComponent.view setNeedsDisplay];
             });
-            NSString *colorString = [self _hexWithColor:color];
+            NSString *colorString = [WXConvert HexWithColor:color];
             [_fromStyles setObject:colorString forKey:info.propertyName];
         }
         else if ([info.propertyName hasPrefix:@"transform"])
@@ -313,7 +296,7 @@
             if ([info.propertyName isEqualToString:@"transform.rotation.y"]) {
                 transformString = [NSString stringWithFormat:@"rotateY(%lfdeg)",currentValue * 180.0 / M_PI];
             }
-            if ([info.propertyName isEqualToString:@"transform.rotation.z"]) {
+            if ([info.propertyName isEqualToString:@"transform.rotation.z"]) {
                 transformString = [NSString stringWithFormat:@"rotateZ(%lfdeg)",currentValue * 180.0 / M_PI];
             }
             if ([info.propertyName isEqualToString:@"transform.scale.x"]) {
@@ -379,8 +362,7 @@
 - (void)_suspendLayoutAnimationDisplayLink
 {
     WXAssertComponentThread();
-    if(_layoutAnimationDisplayLink && !_layoutAnimationDisplayLink.paused)
-    {
+    if(_layoutAnimationDisplayLink && !_layoutAnimationDisplayLink.paused){
         _layoutAnimationDisplayLink.paused = YES;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1d87ab3e/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h
index eedcbbf..25c6430 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h
@@ -53,6 +53,7 @@ typedef CGFloat WXPixelType;
 
 + (UIColor *)UIColor:(id)value;
 + (CGColorRef)CGColor:(id)value;
++ (NSString *)HexWithColor:(UIColor *)color;
 + (WXBorderStyle)WXBorderStyle:(id)value;
 typedef BOOL WXClipType;
 + (WXClipType)WXClipType:(id)value;

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1d87ab3e/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m
index 18892e6..24458e4 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m
@@ -421,6 +421,23 @@ WX_NUMBER_CONVERT(NSUInteger, unsignedIntegerValue)
     return [color CGColor];
 }
 
++ (NSString *)HexWithColor:(UIColor *)color
+{
+    uint hex;
+    CGFloat red, green, blue, alpha;
+    if (![color getRed:&red green:&green blue:&blue alpha:&alpha]) {
+        [color getWhite:&red alpha:&alpha];
+        green = red;
+        blue = red;
+    }
+    red = roundf(red * 255.f);
+    green = roundf(green * 255.f);
+    blue = roundf(blue * 255.f);
+    alpha = roundf(alpha * 255.f);
+    hex =  ((uint)red << 16) | ((uint)green << 8) | ((uint)blue);
+    return [NSString stringWithFormat:@"#%02x", hex];
+}
+
 + (WXBorderStyle)WXBorderStyle:(id)value
 {
     if([value isKindOfClass:[NSString class]]){

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1d87ab3e/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m b/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m
index 9a3cf6d..ef00f9a 100644
--- a/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m
+++ b/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m
@@ -197,7 +197,6 @@ do {\
     
     if (styles[@"backgroundImage"]) {
         _backgroundImage = styles[@"backgroundImage"] ? [WXConvert NSString:styles[@"backgroundImage"]]: nil;
-        
         if (_backgroundImage) {
             [self setGradientLayer];
         }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1d87ab3e/ios/sdk/WeexSDKTests/WXConvertTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXConvertTests.m b/ios/sdk/WeexSDKTests/WXConvertTests.m
index f3ed6a2..d5874bd 100644
--- a/ios/sdk/WeexSDKTests/WXConvertTests.m
+++ b/ios/sdk/WeexSDKTests/WXConvertTests.m
@@ -53,7 +53,6 @@
     NSUInteger val= [WXConvert NSUInteger:@"x"];
     XCTAssertTrue(0==val);
     
-    
     val= [WXConvert NSUInteger:@"9"];
     XCTAssertTrue(9);
     
@@ -62,8 +61,6 @@
     val= [WXConvert NSUInteger:unsignedIntMax];
     XCTAssertTrue(val==NSUIntegerMax);
     
-    
-    
     //test overflow
     unsigned long long uio = NSUIntegerMax;
     uio++;
@@ -71,7 +68,21 @@
     NSString * ulval  = [NSString stringWithFormat:@"%llu", uio ];
     val = [WXConvert NSUInteger:ulval];
     XCTAssertTrue(0==val);//overflowed
+
+}
+
+- (void) testColor{
+    
+    UIColor *redColor = [UIColor redColor];
+    NSString *redString = @"#ff0000";
+    
+    //color2hex
+    NSString *hexString = [WXConvert HexWithColor:redColor];
+    XCTAssertTrue([redString isEqualToString:hexString]);
     
+    //hex2color
+    UIColor *redTestColor = [WXConvert UIColor:redString];
+    XCTAssertTrue(CGColorEqualToColor(redTestColor.CGColor, redColor.CGColor));
 }
 
 @end