Simplify and optimize property handling logic

Remove redundant toString calls / type transforms.
The view managers handle the different types natively.
This commit is contained in:
Mikael Sand
2018-10-12 18:52:23 +03:00
parent 1eaa3d73b9
commit 1e25870f5d
31 changed files with 231 additions and 261 deletions
+14 -23
View File
@@ -14,40 +14,31 @@ export default class extends Shape {
href: PropTypes.string.isRequired,
width: numberProp, // Just for reusing `Symbol`
height: numberProp, // Just for reusing `Symbol`
...pathProps
...pathProps,
};
static defaultProps = {
width: 0,
height: 0
height: 0,
};
setNativeProps = (props) => {
if (props.width) {
props.usewidth = `${props.width}`;
}
if (props.height) {
props.useheight = `${props.height}`;
}
setNativeProps = props => {
this.root.setNativeProps(props);
};
render() {
const { props } = this;
const { children, width, height } = props;
const { children, width, height, href } = props;
// match "url(#pattern)"
const matched = props.href.match(idExpReg);
let href;
const matched = href.match(idExpReg);
const match = matched && matched[1];
if (matched) {
href = matched[1];
}
if (!href) {
if (!match) {
console.warn(
'Invalid `href` prop for `Use` element, expected a href like `"#id"`, but got: "' +
props.href +
'"'
href +
'"',
);
}
@@ -57,9 +48,9 @@ export default class extends Shape {
this.root = ele;
}}
{...extractProps(props, this)}
href={href}
usewidth={width !== undefined ? width.toString() : ""}
useheight={height !== undefined ? height.toString() : ""}
href={match}
width={width}
height={height}
>
{children}
</RNSVGUse>
@@ -68,5 +59,5 @@ export default class extends Shape {
}
const RNSVGUse = requireNativeComponent("RNSVGUse", null, {
nativeOnly: UseAttributes
nativeOnly: UseAttributes,
});