From 2f513504d21a8138ac851784b3b110ccb8cceb3a Mon Sep 17 00:00:00 2001 From: Mikael Sand Date: Sat, 8 Dec 2018 03:03:49 +0200 Subject: [PATCH] [ios] Fix gesture responder, onPress/In/Out, onLayout --- elements/Svg.js | 21 ++++++++++++++++++++- ios/Elements/RNSVGGroup.m | 11 ++++++++++- ios/RNSVGRenderable.m | 13 ++++++++++--- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/elements/Svg.js b/elements/Svg.js index 41fedf7b..b61e0726 100644 --- a/elements/Svg.js +++ b/elements/Svg.js @@ -10,6 +10,7 @@ import extractResponder from "../lib/extract/extractResponder"; import extractViewBox from "../lib/extract/extractViewBox"; import Shape from "./Shape"; import G from "./G"; +import _ from "lodash"; /** @namespace NativeModules.RNSVGSvgViewManager */ const RNSVGSvgViewManager = NativeModules.RNSVGSvgViewManager; @@ -24,6 +25,22 @@ const styles = StyleSheet.create({ }, }); +const gProps = [ + "font", + "transform", + "fill", + "fillOpacity", + "fillRule", + "stroke", + "strokeWidth", + "strokeOpacity", + "strokeDasharray", + "strokeDashoffset", + "strokeLinecap", + "strokeLinejoin", + "strokeMiterlimit", +]; + class Svg extends Shape { static displayName = "Svg"; @@ -69,6 +86,7 @@ class Svg extends Shape { preserveAspectRatio, style, children, + onLayout, ...props } = this.props; const stylesAndProps = { ...(style && style.length ? Object.assign({}, ...style) : style), ...props }; @@ -92,6 +110,7 @@ class Svg extends Shape { bbWidth={w} bbHeight={h} tintColor={color} + onLayout={onLayout} {...extractResponder(props, this)} {...extractViewBox({ viewBox, preserveAspectRatio })} ref={ele => { @@ -106,7 +125,7 @@ class Svg extends Shape { dimensions, ]} > - + {children} diff --git a/ios/Elements/RNSVGGroup.m b/ios/Elements/RNSVGGroup.m index 72944021..418cd0bb 100644 --- a/ios/Elements/RNSVGGroup.m +++ b/ios/Elements/RNSVGGroup.m @@ -73,7 +73,16 @@ }]; [self setHitArea:[self getPath:context]]; self.clientRect = groupRect; - self.bounds = groupRect; + + const CGAffineTransform matrix = self.matrix; + const CGAffineTransform current = CGContextGetCTM(context); + const CGAffineTransform svgToClientTransform = CGAffineTransformConcat(current, self.svgView.invInitialCTM); + const CGRect clientRect = CGRectApplyAffineTransform(groupRect, svgToClientTransform); + const CGSize clientSize = clientRect.size; + + self.bounds = CGRectMake(0, 0, clientSize.width, clientSize.height); + self.frame = CGRectMake(matrix.tx, matrix.ty, clientSize.width, clientSize.height); + [self popGlyphContext]; } diff --git a/ios/RNSVGRenderable.m b/ios/RNSVGRenderable.m index 7425ade7..a748af88 100644 --- a/ios/RNSVGRenderable.m +++ b/ios/RNSVGRenderable.m @@ -296,9 +296,16 @@ UInt32 saturate(CGFloat value) { } const CGRect pathBounding = CGPathGetBoundingBox(self.path); - const CGAffineTransform svgToClientTransform = CGAffineTransformConcat(CGContextGetCTM(context), self.svgView.invInitialCTM); - self.clientRect = CGRectApplyAffineTransform(pathBounding, svgToClientTransform); - self.bounds = self.clientRect; + + const CGAffineTransform matrix = self.matrix; + const CGAffineTransform current = CGContextGetCTM(context); + const CGAffineTransform svgToClientTransform = CGAffineTransformConcat(current, self.svgView.invInitialCTM); + const CGRect clientRect = CGRectApplyAffineTransform(pathBounding, svgToClientTransform); + const CGSize clientSize = clientRect.size; + + self.clientRect = clientRect; + self.bounds = CGRectMake(0, 0, clientSize.width, clientSize.height); + self.frame = CGRectMake(matrix.tx, matrix.ty, clientSize.width, clientSize.height); CGPathDrawingMode mode = kCGPathStroke; BOOL fillColor = NO;