[iOS] Fix Use element spec conformance (x and y interpretation)

This commit is contained in:
Mikael Sand
2019-01-14 15:03:28 +02:00
parent e183478466
commit ccb615dbca
4 changed files with 39 additions and 2 deletions
+7 -2
View File
@@ -14,7 +14,7 @@ export default class Use extends Shape {
render() { render() {
const { props } = this; const { props } = this;
const { children, width, height, href } = props; const { children, x, y, width, height, href } = props;
// match "url(#pattern)" // match "url(#pattern)"
const matched = href.match(idPattern); const matched = href.match(idPattern);
@@ -31,8 +31,13 @@ export default class Use extends Shape {
return ( return (
<RNSVGUse <RNSVGUse
ref={this.refMethod} ref={this.refMethod}
{...extractProps(props, this)} {...extractProps(
{ ...props, x: undefined, y: undefined },
this,
)}
href={match} href={match}
x={x}
y={y}
width={width} width={width}
height={height} height={height}
> >
+2
View File
@@ -16,6 +16,8 @@
@interface RNSVGUse : RNSVGRenderable @interface RNSVGUse : RNSVGRenderable
@property (nonatomic, strong) NSString *href; @property (nonatomic, strong) NSString *href;
@property (nonatomic, strong) RNSVGLength *x;
@property (nonatomic, strong) RNSVGLength *y;
@property (nonatomic, strong) RNSVGLength *usewidth; @property (nonatomic, strong) RNSVGLength *usewidth;
@property (nonatomic, strong) RNSVGLength *useheight; @property (nonatomic, strong) RNSVGLength *useheight;
@end @end
+22
View File
@@ -21,6 +21,27 @@
_href = href; _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 - (void)setUsewidth:(RNSVGLength *)usewidth
{ {
if ([usewidth isEqualTo:_usewidth]) { if ([usewidth isEqualTo:_usewidth]) {
@@ -43,6 +64,7 @@
- (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect - (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
{ {
CGContextTranslateCTM(context, [self relativeOnWidth:self.x], [self relativeOnWidth:self.y]);
RNSVGNode* template = [self.svgView getDefinedTemplate:self.href]; RNSVGNode* template = [self.svgView getDefinedTemplate:self.href];
if (template) { if (template) {
[self beginTransparencyLayer:context]; [self beginTransparencyLayer:context];
+8
View File
@@ -19,6 +19,14 @@ RCT_EXPORT_MODULE()
} }
RCT_EXPORT_VIEW_PROPERTY(href, NSString) 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(useheight, RNSVGLength*)
RCT_EXPORT_VIEW_PROPERTY(usewidth, RNSVGLength*) RCT_EXPORT_VIEW_PROPERTY(usewidth, RNSVGLength*)
RCT_CUSTOM_VIEW_PROPERTY(height, id, RNSVGUse) RCT_CUSTOM_VIEW_PROPERTY(height, id, RNSVGUse)