mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-05 07:59:28 +00:00
[iOS] Fix Use element spec conformance (x and y interpretation)
This commit is contained in:
+7
-2
@@ -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 (
|
||||
<RNSVGUse
|
||||
ref={this.refMethod}
|
||||
{...extractProps(props, this)}
|
||||
{...extractProps(
|
||||
{ ...props, x: undefined, y: undefined },
|
||||
this,
|
||||
)}
|
||||
href={match}
|
||||
x={x}
|
||||
y={y}
|
||||
width={width}
|
||||
height={height}
|
||||
>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user