mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-08 01:00:43 +00:00
finish Symbol refactor
finish Symbol refactor finish all reusable elements refactor (iOS)
This commit is contained in:
+10
-6
@@ -1,17 +1,19 @@
|
||||
import {PropTypes} from 'react';
|
||||
import {pathProps} from '../lib/props';
|
||||
import {pathProps, numberProp} from '../lib/props';
|
||||
import {UseAttributes} from '../lib/attributes';
|
||||
import Shape from './Shape';
|
||||
import React from 'react';
|
||||
import patternReg from '../lib/extract/patternReg';
|
||||
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
|
||||
import _ from 'lodash';
|
||||
|
||||
class Defs extends Shape {
|
||||
const idExpReg = /^#(.+)$/;
|
||||
class Use extends Shape {
|
||||
static displayName = 'Use';
|
||||
|
||||
static propTypes = {
|
||||
href: PropTypes.string.isRequired,
|
||||
width: numberProp, // Just for reusing `Symbol`
|
||||
height: numberProp, // Just for reusing `Symbol`
|
||||
...pathProps
|
||||
};
|
||||
|
||||
@@ -22,7 +24,7 @@ class Defs extends Shape {
|
||||
render() {
|
||||
let {props} = this;
|
||||
// 尝试匹配 "url(#pattern)"
|
||||
let matched = props.href.match(patternReg);
|
||||
let matched = props.href.match(idExpReg);
|
||||
let href;
|
||||
|
||||
if (matched) {
|
||||
@@ -30,7 +32,7 @@ class Defs extends Shape {
|
||||
}
|
||||
|
||||
if (!href) {
|
||||
console.warn('Invalid `href` prop for `Use` element, expected a href like `"url(#id)"`, but got: "' + props.href + '"');
|
||||
console.warn('Invalid `href` prop for `Use` element, expected a href like `"#id"`, but got: "' + props.href + '"');
|
||||
}
|
||||
|
||||
let extractedProps = this.extractProps(props, {
|
||||
@@ -44,6 +46,8 @@ class Defs extends Shape {
|
||||
ref={ele => this.root = ele}
|
||||
{...extractedProps}
|
||||
href={href}
|
||||
width={props.width}
|
||||
height={props.height}
|
||||
>{props.children}</RNSVGUse>;
|
||||
}
|
||||
}
|
||||
@@ -53,5 +57,5 @@ const RNSVGUse = createReactNativeComponentClass({
|
||||
uiViewClassName: 'RNSVGUse'
|
||||
});
|
||||
|
||||
export default Defs;
|
||||
export default Use;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user