You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by cx...@apache.org on 2017/04/10 05:54:01 UTC
[11/15] incubator-weex git commit: * [ios] support border-x-x-radius
in image.
* [ios] support border-x-x-radius in image.
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/aab1eefb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/aab1eefb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/aab1eefb
Branch: refs/heads/0.12-dev
Commit: aab1eefbbce4dbe3b47c555afe834a85a5b16cd7
Parents: 29a47f8
Author: \u9690\u98ce <cx...@apache.org>
Authored: Sun Apr 9 21:43:23 2017 +0800
Committer: \u9690\u98ce <cx...@apache.org>
Committed: Sun Apr 9 21:43:23 2017 +0800
----------------------------------------------------------------------
.../Sources/Component/WXImageComponent.m | 44 +++++++++++++++++++-
.../Sources/Display/WXComponent+Display.m | 2 +-
ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.h | 2 +
.../WeexSDK/Sources/Display/WXRoundedRect.mm | 5 +++
4 files changed, 50 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/aab1eefb/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
index 73696fd..974bd65 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
@@ -14,6 +14,8 @@
#import "WXType.h"
#import "WXConvert.h"
#import "WXURLRewriteProtocol.h"
+#import "WXRoundedRect.h"
+#import "UIBezierPath+Weex.h"
@interface WXImageView : UIImageView
@@ -154,6 +156,8 @@ static dispatch_queue_t WXImageUpdateQueue;
imageView.clipsToBounds = YES;
imageView.exclusiveTouch = YES;
+ [self _clipsToBounds];
+
[self updateImage];
}
@@ -171,6 +175,16 @@ static dispatch_queue_t WXImageUpdateQueue;
{
if (!self.image) {
[self updateImage];
+ return nil;
+ }
+
+ WXRoundedRect *borderRect = [[WXRoundedRect alloc] initWithRect:rect topLeft:_borderTopLeftRadius topRight:_borderTopRightRadius bottomLeft:_borderBottomLeftRadius bottomRight:_borderBottomRightRadius];
+
+ WXRadii *radii = borderRect.radii;
+ if ([radii hasBorderRadius]) {
+ CGFloat topLeft = radii.topLeft, topRight = radii.topRight, bottomLeft = radii.bottomLeft, bottomRight = radii.bottomRight;
+ UIBezierPath *bezierPath = [UIBezierPath wx_bezierPathWithRoundedRect:rect topLeft:topLeft topRight:topRight bottomLeft:bottomLeft bottomRight:bottomRight];
+ [bezierPath addClip];
}
return self.image;
}
@@ -182,6 +196,13 @@ static dispatch_queue_t WXImageUpdateQueue;
_image = nil;
}
+- (void)_frameDidCalculated:(BOOL)isChanged
+{
+ if ([self isViewLoaded] && isChanged) {
+ [self _clipsToBounds];
+ }
+}
+
- (void)setImageSrc:(NSString*)src
{
if (![src isEqualToString:_imageSrc]) {
@@ -325,9 +346,28 @@ static dispatch_queue_t WXImageUpdateQueue;
return imageLoader;
}
-- (BOOL)_needsDrawBorder
+- (void)_clipsToBounds
{
- return NO;
+ if (!_clipToBounds) {
+ return;
+ }
+
+ WXRoundedRect *borderRect = [[WXRoundedRect alloc] initWithRect:self.view.bounds topLeft:_borderTopLeftRadius topRight:_borderTopRightRadius bottomLeft:_borderBottomLeftRadius bottomRight:_borderBottomRightRadius];
+ // here is computed radii, do not use original style
+ WXRadii *radii = borderRect.radii;
+
+ if ([radii radiusesAreEqual]) {
+ return;
+ }
+
+ CGFloat topLeft = radii.topLeft, topRight = radii.topRight, bottomLeft = radii.bottomLeft, bottomRight = radii.bottomRight;
+
+ // clip to border radius
+ UIBezierPath *bezierPath = [UIBezierPath wx_bezierPathWithRoundedRect:self.view.bounds topLeft:topLeft topRight:topRight bottomLeft:bottomLeft bottomRight:bottomRight];
+
+ CAShapeLayer *shapeLayer = [CAShapeLayer layer];
+ shapeLayer.path = bezierPath.CGPath;
+ self.layer.mask = shapeLayer;
}
#ifdef UITEST
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/aab1eefb/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
index 9dbe63a..a02f53a 100644
--- a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
+++ b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
@@ -555,7 +555,7 @@ do {\
WXRoundedRect *borderRect = [[WXRoundedRect alloc] initWithRect:rect topLeft:_borderTopLeftRadius topRight:_borderTopRightRadius bottomLeft:_borderBottomLeftRadius bottomRight:_borderBottomRightRadius];
WXRadii *radii = borderRect.radii;
BOOL hasBorderRadius = [radii hasBorderRadius];
- return (!hasBorderRadius) && CGColorGetAlpha(_backgroundColor.CGColor) == 1.0;
+ return (!hasBorderRadius) && _opacity == 1.0 && CGColorGetAlpha(_backgroundColor.CGColor) == 1.0;
}
#pragma mark - Deprecated
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/aab1eefb/ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.h b/ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.h
index 4cde88a..a90099e 100644
--- a/ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.h
+++ b/ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.h
@@ -19,6 +19,8 @@
- (BOOL)hasBorderRadius;
+- (BOOL)radiusesAreEqual;
+
@end
@interface WXRoundedRect : NSObject
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/aab1eefb/ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.mm
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.mm b/ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.mm
index fb62465..e02c5e1 100644
--- a/ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.mm
+++ b/ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.mm
@@ -31,6 +31,11 @@
return _topLeft > 0.001 || _topRight > 0.001 || _bottomLeft > 0.001 || _bottomRight > 0.001;
}
+- (BOOL)radiusesAreEqual
+{
+ return _topLeft == _topRight && _topRight == _bottomRight && _bottomRight == _bottomLeft;
+}
+
- (void)scale:(float)factor
{
if (factor == 1) {