From ccb615dbca8bd95b4d6f7e469dfa38135ee64656 Mon Sep 17 00:00:00 2001 From: Mikael Sand Date: Mon, 14 Jan 2019 15:03:28 +0200 Subject: [PATCH] [iOS] Fix Use element spec conformance (x and y interpretation) --- elements/Use.js | 9 +++++++-- ios/Elements/RNSVGUse.h | 2 ++ ios/Elements/RNSVGUse.m | 22 ++++++++++++++++++++++ ios/ViewManagers/RNSVGUseManager.m | 8 ++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/elements/Use.js b/elements/Use.js index 4eeb89e2..e101c3c3 100644 --- a/elements/Use.js +++ b/elements/Use.js @@ -14,7 +14,7 @@ export default class Use extends Shape { render() { const { props } = this; - const { children, width, height, href } = props; + const { children, x, y, width, height, href } = props; // match "url(#pattern)" const matched = href.match(idPattern); @@ -31,8 +31,13 @@ export default class Use extends Shape { return ( diff --git a/ios/Elements/RNSVGUse.h b/ios/Elements/RNSVGUse.h index eb730531..6d0f3dd7 100644 --- a/ios/Elements/RNSVGUse.h +++ b/ios/Elements/RNSVGUse.h @@ -16,6 +16,8 @@ @interface RNSVGUse : RNSVGRenderable @property (nonatomic, strong) NSString *href; +@property (nonatomic, strong) RNSVGLength *x; +@property (nonatomic, strong) RNSVGLength *y; @property (nonatomic, strong) RNSVGLength *usewidth; @property (nonatomic, strong) RNSVGLength *useheight; @end diff --git a/ios/Elements/RNSVGUse.m b/ios/Elements/RNSVGUse.m index 93946bcf..49ba6795 100644 --- a/ios/Elements/RNSVGUse.m +++ b/ios/Elements/RNSVGUse.m @@ -21,6 +21,27 @@ _href = href; } +- (void)setX:(RNSVGLength *)x +{ + if ([x isEqualTo:_x]) { + return; + } + + [self invalidate]; + _x = x; +} + +- (void)setY:(RNSVGLength *)y +{ + if ([y isEqualTo:_y]) { + return; + } + + [self invalidate]; + _y = y; +} + + - (void)setUsewidth:(RNSVGLength *)usewidth { if ([usewidth isEqualTo:_usewidth]) { @@ -43,6 +64,7 @@ - (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect { + CGContextTranslateCTM(context, [self relativeOnWidth:self.x], [self relativeOnWidth:self.y]); RNSVGNode* template = [self.svgView getDefinedTemplate:self.href]; if (template) { [self beginTransparencyLayer:context]; diff --git a/ios/ViewManagers/RNSVGUseManager.m b/ios/ViewManagers/RNSVGUseManager.m index 242e9900..23ddaa0c 100644 --- a/ios/ViewManagers/RNSVGUseManager.m +++ b/ios/ViewManagers/RNSVGUseManager.m @@ -19,6 +19,14 @@ RCT_EXPORT_MODULE() } RCT_EXPORT_VIEW_PROPERTY(href, NSString) +RCT_CUSTOM_VIEW_PROPERTY(x, id, RNSVGUse) +{ + view.x = [RCTConvert RNSVGLength:json]; +} +RCT_CUSTOM_VIEW_PROPERTY(y, id, RNSVGUse) +{ + view.y = [RCTConvert RNSVGLength:json]; +} RCT_EXPORT_VIEW_PROPERTY(useheight, RNSVGLength*) RCT_EXPORT_VIEW_PROPERTY(usewidth, RNSVGLength*) RCT_CUSTOM_VIEW_PROPERTY(height, id, RNSVGUse)