From 92ea884d6fd16c5fb01004a4afdb2d22e27cf693 Mon Sep 17 00:00:00 2001 From: Horcrux Date: Wed, 27 Jul 2016 15:54:45 +0800 Subject: [PATCH] native prop trans => matrix --- .../com/horcrux/svg/RNSVGVirtualNode.java | 8 +++---- elements/Image.js | 2 +- ios/Elements/RNSVGGroup.m | 2 +- ios/RNSVGNode.h | 2 +- ios/RNSVGNode.m | 21 +++++++------------ ios/RNSVGRenderable.m | 2 +- ios/ViewManagers/RNSVGNodeManager.m | 2 +- lib/attributes.js | 2 +- lib/extract/extractProps.js | 4 ++-- 9 files changed, 20 insertions(+), 25 deletions(-) diff --git a/android/src/main/java/com/horcrux/svg/RNSVGVirtualNode.java b/android/src/main/java/com/horcrux/svg/RNSVGVirtualNode.java index 0b5a3c77..e3acd2a1 100644 --- a/android/src/main/java/com/horcrux/svg/RNSVGVirtualNode.java +++ b/android/src/main/java/com/horcrux/svg/RNSVGVirtualNode.java @@ -135,10 +135,10 @@ public abstract class RNSVGVirtualNode extends LayoutShadowNode { markUpdated(); } - @ReactProp(name = "trans") - public void setTrans(@Nullable ReadableArray transformArray) { - if (transformArray != null) { - int matrixSize = PropHelper.toFloatArray(transformArray, sMatrixData); + @ReactProp(name = "matrix") + public void setMatrix(@Nullable ReadableArray matrixArray) { + if (matrixArray != null) { + int matrixSize = PropHelper.toFloatArray(matrixArray, sMatrixData); if (matrixSize == 6) { setupMatrix(); } else if (matrixSize != -1) { diff --git a/elements/Image.js b/elements/Image.js index d5e9decd..8f100f77 100644 --- a/elements/Image.js +++ b/elements/Image.js @@ -34,7 +34,7 @@ class Image extends Shape { let {props} = this; return {this.root = ele;}} - {...this.extractProps(props, {responder: true})} + {...this.extractProps({...props, x: null, y: null}, {responder: true, transform: true})} x={props.x.toString()} y={props.y.toString()} width={props.width.toString()} diff --git a/ios/Elements/RNSVGGroup.m b/ios/Elements/RNSVGGroup.m index 5ebfbcbb..ede44aac 100644 --- a/ios/Elements/RNSVGGroup.m +++ b/ios/Elements/RNSVGGroup.m @@ -29,7 +29,7 @@ { CGMutablePathRef path = CGPathCreateMutable(); for (RNSVGNode *node in self.subviews) { - CGAffineTransform transform = node.transform; + CGAffineTransform transform = node.matrix; CGPathAddPath(path, &transform, [node getPath:context]); } return (CGPathRef)CFAutorelease(path); diff --git a/ios/RNSVGNode.h b/ios/RNSVGNode.h index 626dd810..7bf52614 100644 --- a/ios/RNSVGNode.h +++ b/ios/RNSVGNode.h @@ -23,7 +23,7 @@ @property (nonatomic, assign) CGPathRef clipPath; // convert clipPath="M0,0 L0,10 L10,10z" into path @property (nonatomic, strong) NSString *clipPathRef; // use clipPath="url(#clip)" as ClipPath @property (nonatomic, assign) BOOL responsible; -@property (nonatomic, assign) CGAffineTransform trans; +@property (nonatomic, assign) CGAffineTransform matrix; - (void)invalidate; diff --git a/ios/RNSVGNode.m b/ios/RNSVGNode.m index 9da08d04..45add964 100644 --- a/ios/RNSVGNode.m +++ b/ios/RNSVGNode.m @@ -63,21 +63,16 @@ } else if (opacity > 1) { opacity = 1; } - + [self invalidate]; _transparent = opacity < 1; _opacity = opacity; } -- (void)setTrans:(CGAffineTransform)trans -{ - self.transform = trans; -} - -- (void)setTransform:(CGAffineTransform)transform +- (void)setMatrix:(CGAffineTransform)matrix { + _matrix = matrix; [self invalidate]; - super.transform = transform; } - (void)beginTransparencyLayer:(CGContextRef)context @@ -97,17 +92,17 @@ - (void)renderTo:(CGContextRef)context { float opacity = self.opacity; - + // This needs to be painted on a layer before being composited. CGContextSaveGState(context); - CGContextConcatCTM(context, self.transform); + CGContextConcatCTM(context, self.matrix); CGContextSetAlpha(context, opacity); - + [self beginTransparencyLayer:context]; [self renderClip:context]; [self renderLayerTo:context]; [self endTransparencyLayer:context]; - + CGContextRestoreGState(context); } @@ -175,7 +170,7 @@ while (parent && [parent class] != [RNSVGSvgView class]) { parent = parent.superview; } - + return (RNSVGSvgView *)parent; } diff --git a/ios/RNSVGRenderable.m b/ios/RNSVGRenderable.m index b9d64e69..0e8f9419 100644 --- a/ios/RNSVGRenderable.m +++ b/ios/RNSVGRenderable.m @@ -121,7 +121,7 @@ // This is a terminal with only one painting. Therefore we don't need to paint this // off-screen. We can just composite it straight onto the buffer. CGContextSaveGState(context); - CGContextConcatCTM(context, self.transform); + CGContextConcatCTM(context, self.matrix); CGContextSetAlpha(context, self.opacity); [self renderClip:context]; [self renderLayerTo:context]; diff --git a/ios/ViewManagers/RNSVGNodeManager.m b/ios/ViewManagers/RNSVGNodeManager.m index df19e93b..8af8568f 100644 --- a/ios/ViewManagers/RNSVGNodeManager.m +++ b/ios/ViewManagers/RNSVGNodeManager.m @@ -31,7 +31,7 @@ RCT_EXPORT_MODULE() RCT_EXPORT_VIEW_PROPERTY(name, NSString) RCT_EXPORT_VIEW_PROPERTY(opacity, CGFloat) -RCT_EXPORT_VIEW_PROPERTY(trans, CGAffineTransform) +RCT_EXPORT_VIEW_PROPERTY(matrix, CGAffineTransform) RCT_EXPORT_VIEW_PROPERTY(clipPathRef, NSString) RCT_EXPORT_VIEW_PROPERTY(clipPath, CGPath) RCT_EXPORT_VIEW_PROPERTY(clipRule, RNSVGCGFCRule) diff --git a/lib/attributes.js b/lib/attributes.js index ea011431..6c76cb40 100644 --- a/lib/attributes.js +++ b/lib/attributes.js @@ -53,7 +53,7 @@ const ViewBoxAttributes = { const NodeAttributes = { name: true, - trans: { + matrix: { diff: arrayDiffer }, opacity: true, diff --git a/lib/extract/extractProps.js b/lib/extract/extractProps.js index f7b13adf..1a779c67 100644 --- a/lib/extract/extractProps.js +++ b/lib/extract/extractProps.js @@ -46,9 +46,9 @@ export default function(props, options = {stroke: true, transform: true, fill: t } if (options.transform) { - extractedProps.trans = extractTransform(props); + extractedProps.matrix = extractTransform(props); } else if (props.transform) { - extractedProps.trans = extractTransform(props.transform); + extractedProps.matrix = extractTransform(props.transform); } if (options.responder) {