refactor Use and Defs element with native code support(iOS)

This commit is contained in:
Horcrux
2016-07-19 23:09:51 +08:00
parent 4eddfc6885
commit dd6cb80e84
37 changed files with 535 additions and 282 deletions
+47 -7
View File
@@ -1,14 +1,54 @@
import React, {Component, PropTypes} from 'react';
import Defs from './Defs';
class Use extends Component{
import {PropTypes} from 'react';
import {pathProps} 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';
class Defs extends Shape {
static displayName = 'Use';
static propType = {
href: PropTypes.string
static propTypes = {
href: PropTypes.string.isRequired,
...pathProps
};
setNativeProps = (...args) => {
this.root.setNativeProps(...args);
};
render() {
return <Defs.Use {...this.props} />;
let {props} = this;
// 尝试匹配 "url(#pattern)"
let matched = props.href.match(patternReg);
let href;
if (matched) {
href = matched[1];
}
if (!href) {
console.warn('Invalid `href` prop for `Use` element, expected a href like `"url(#id)"`, but got: "' + props.href + '"');
}
return <RNSVGUse
ref={ele => this.root = ele}
{...this.extractProps(props, {
stroke: true,
fill: true,
responder: true,
transform: true
})}
href={href}
>{props.children}</RNSVGUse>;
}
}
export default Use;
const RNSVGUse = createReactNativeComponentClass({
validAttributes: UseAttributes,
uiViewClassName: 'RNSVGUse'
});
export default Defs;