weex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acton...@apache.org
Subject [1/6] incubator-weex git commit: * [ios] add perspective support for rotate3d
Date Thu, 03 Aug 2017 09:51:19 GMT
Repository: incubator-weex
Updated Branches:
  refs/heads/0.16-dev e5f560e5c -> 199e4665d


* [ios] add perspective support for rotate3d


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

Branch: refs/heads/0.16-dev
Commit: 22965189432e5289bd96c4b435d3fafea8fa8bfc
Parents: 58aaee6
Author: acton393 <zhangxing610321@gmail.com>
Authored: Tue Jul 25 22:45:58 2017 +0800
Committer: acton393 <zhangxing610321@gmail.com>
Committed: Tue Jul 25 22:45:58 2017 +0800

----------------------------------------------------------------------
 .../Sources/Component/WXComponent_internal.h       |  3 +++
 ios/sdk/WeexSDK/Sources/Component/WXTransform.h    |  1 +
 ios/sdk/WeexSDK/Sources/Component/WXTransform.m    | 14 +++++++++++++-
 ios/sdk/WeexSDK/Sources/Model/WXComponent.m        |  1 +
 ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m |  6 +++++-
 .../Sources/View/WXComponent+ViewManagement.m      | 17 +++++++++++++++++
 6 files changed, 40 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/22965189/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h b/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h
index 7226ced..20fb87b 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h
+++ b/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h
@@ -55,6 +55,9 @@
     WXBoxShadow *_lastBoxShadow;
     WXBoxShadow *_boxShadow;
     
+    // default is parallel projection, so this will be CGFLOAT_MAX
+    CGFloat _perspective;
+    
     /**
      * accessibility support
      */

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/22965189/ios/sdk/WeexSDK/Sources/Component/WXTransform.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTransform.h b/ios/sdk/WeexSDK/Sources/Component/WXTransform.h
index 75db1c7..e9e23c3 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTransform.h
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTransform.h
@@ -32,6 +32,7 @@
 @property (nonatomic, strong, readonly) WXLength *translateY;
 @property (nonatomic, assign, readonly) float scaleX;
 @property (nonatomic, assign, readonly) float scaleY;
+@property (nonatomic, assign) float perspective;
 
 - (instancetype)initWithCSSValue:(NSString *)cssValue origin:(NSString *)origin instance:(WXSDKInstance
*)instance;
 

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/22965189/ios/sdk/WeexSDK/Sources/Component/WXTransform.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTransform.m b/ios/sdk/WeexSDK/Sources/Component/WXTransform.m
index b6287e7..edd3177 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTransform.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTransform.m
@@ -43,6 +43,7 @@
     float _rotateX;
     float _rotateY;
     float _rotateZ;
+    float _perspective;
     
     CATransform3D _nativeTransform;
     BOOL _useNativeTransform;
@@ -59,6 +60,9 @@
         _rotateZ = 0.0;
         _rotateAngle = 0.0;
         
+        // default is parallel projection
+        _perspective = CGFLOAT_MAX;
+        
         [self parseTransform:cssValue];
         [self parseTransformOrigin:origin];
     }
@@ -147,8 +151,8 @@
     if (_useNativeTransform) {
         return _nativeTransform;
     }
-    CATransform3D nativeTransform3d = [self nativeTransformWithoutRotateWithView:view];
     
+    CATransform3D nativeTransform3d = [self nativeTransformWithoutRotateWithView:view];
     if (_rotateX != 0) {
         CATransform3D rotateXTransform = CATransform3DMakeRotation(_rotateX, 1, 0, 0);
         nativeTransform3d = CATransform3DConcat(nativeTransform3d, rotateXTransform);
@@ -169,6 +173,9 @@
 {
     CATransform3D nativeTansform3D = CATransform3DIdentity;
     
+    if (_perspective && !isinf(_perspective)) {
+        nativeTansform3D.m34 = -1.0/_perspective;
+    }
     if (!view || view.bounds.size.width <= 0 || view.bounds.size.height <= 0) {
         return nativeTansform3D;
     }
@@ -224,6 +231,11 @@
     }
     CATransform3D nativeTransform3d = [self nativeTransformWithView:view];
     if (!CATransform3DEqualToTransform(view.layer.transform, nativeTransform3d)){
+        CATransform3D presentationTransform = view.layer.presentationLayer.transform;
+        if (presentationTransform.m34 != 0) {
+            //  just for perspective
+            nativeTransform3d = presentationTransform;
+        }
         view.layer.transform = nativeTransform3d;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/22965189/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.m b/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
index bd5549b..7634918 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
@@ -94,6 +94,7 @@
         _ariaHidden = NO;
         
         _async = NO;
+        _perspective = CGFLOAT_MAX;
         
         //TODO set indicator style 
         if ([type isEqualToString:@"indicator"]) {

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/22965189/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
index ff55ee2..7917d7f 100644
--- a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
+++ b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
@@ -85,7 +85,6 @@
 
 - (void)animationDidStart:(CAAnimation *)anim
 {
-    [self applyTransform];
 }
 
 -(void)applyTransform
@@ -94,7 +93,9 @@
         return;
     }
     if ([_animationInfo.propertyName hasPrefix:@"transform"]) {
+        float perspective = _animationInfo.target->_perspective;
         WXTransform *transform = _animationInfo.target->_transform;
+        transform.perspective = perspective;
         [transform applyTransformForView:_animationInfo.target.view];
     } else if ([_animationInfo.propertyName isEqualToString:@"backgroundColor"]) {
         _animationInfo.target.view.layer.backgroundColor = (__bridge CGColorRef _Nullable)(_animationInfo.toValue);
@@ -117,6 +118,8 @@
         return;
     }
     
+    [self applyTransform];
+    
     if ([_animationInfo.propertyName hasPrefix:@"bounds.size"]) {
         /*
          * http://ronnqvi.st/about-the-anchorpoint/
@@ -193,6 +196,7 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:))
         if ([property isEqualToString:@"transform"]) {
             NSString *transformOrigin = styles[@"transformOrigin"];
             WXTransform *wxTransform = [[WXTransform alloc] initWithCSSValue:value origin:transformOrigin
instance:self.weexInstance];
+            wxTransform.perspective = target->_perspective;
             WXTransform *oldTransform = target->_transform;
             if (wxTransform.rotateAngle != oldTransform.rotateAngle) {
                 WXAnimationInfo *newInfo = [info copy];

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/22965189/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 40e9889..31385de 100644
--- a/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m
+++ b/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m
@@ -169,6 +169,14 @@ do {\
     if (_boxShadow) {
         _lastBoxShadow = _boxShadow;
     }
+    if (styles[@"perspective"]) {
+        _perspective = [WXConvert WXPixelType:styles[@"perspective"] scaleFactor:self.weexInstance.pixelScaleFactor];
+        if (_perspective <= 0) {
+            _perspective = CGFLOAT_MAX;
+        }
+        
+        _transform.perspective = _perspective;
+    }
 }
 
 - (void)_updateViewStyles:(NSDictionary *)styles
@@ -227,6 +235,14 @@ do {\
         });
     }
     
+    if (styles[@"perspective"]) {
+        _perspective = [WXConvert WXPixelType:styles[@"perspective"] scaleFactor:self.weexInstance.pixelScaleFactor];
+        if (_perspective <= 0) {
+            _perspective = CGFLOAT_MAX;
+        }
+         _transform.perspective = _perspective;
+    }
+    
     if (styles[@"visibility"]) {
         _visibility = [WXConvert WXVisibility:styles[@"visibility"]];
         if (_visibility == WXVisibilityShow) {
@@ -238,6 +254,7 @@ do {\
     }
     if (styles[@"transform"]) {
         _transform = [[WXTransform alloc] initWithCSSValue:[WXConvert NSString:styles[@"transform"]]
origin:[WXConvert NSString:self.styles[@"transformOrigin"]] instance:self.weexInstance];
+        _transform.perspective = _perspective;
         if (!CGRectEqualToRect(self.calculatedFrame, CGRectZero)) {
             [_transform applyTransformForView:_view];
             [_layer setNeedsDisplay];


Mime
View raw message