chore: refactor props and styles extraction

This commit is contained in:
Mikael Sand
2019-12-09 21:26:14 +02:00
parent 353eddc43c
commit c0ffc65609
11 changed files with 31 additions and 41 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
import React from 'react';
import { requireNativeComponent } from 'react-native';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { extract } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
@@ -23,7 +23,7 @@ export default class Circle extends Shape<{
return (
<RNSVGCircle
ref={this.refMethod}
{...extractProps(propsAndStyles(props), this)}
{...extract(this, props)}
cx={cx}
cy={cy}
r={r}
+2 -5
View File
@@ -1,6 +1,6 @@
import React from 'react';
import { requireNativeComponent } from 'react-native';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { extract } from '../lib/extract/extractProps';
import Shape from './Shape';
export default class ClipPath extends Shape<{}> {
@@ -9,10 +9,7 @@ export default class ClipPath extends Shape<{}> {
render() {
const { props } = this;
return (
<RNSVGClipPath
ref={this.refMethod}
{...extractProps(propsAndStyles(props), this)}
>
<RNSVGClipPath ref={this.refMethod} {...extract(this, props)}>
{props.children}
</RNSVGClipPath>
);
+2 -2
View File
@@ -1,6 +1,6 @@
import React from 'react';
import { requireNativeComponent } from 'react-native';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { extract } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
@@ -25,7 +25,7 @@ export default class Ellipse extends Shape<{
return (
<RNSVGEllipse
ref={this.refMethod}
{...extractProps(propsAndStyles(props), this)}
{...extract(this, props)}
cx={cx}
cy={cy}
rx={rx}
+2 -2
View File
@@ -5,7 +5,7 @@ import {
requireNativeComponent,
} from 'react-native';
import { meetOrSliceTypes, alignEnum } from '../lib/extract/extractViewBox';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { withoutXY } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
@@ -50,7 +50,7 @@ export default class SvgImage extends Shape<{
return (
<RNSVGImage
ref={this.refMethod}
{...extractProps({ ...propsAndStyles(props), x: null, y: null }, this)}
{...withoutXY(this, props)}
x={x}
y={y}
width={width}
+2 -2
View File
@@ -1,6 +1,6 @@
import React from 'react';
import { requireNativeComponent } from 'react-native';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { extract } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
@@ -25,7 +25,7 @@ export default class Line extends Shape<{
return (
<RNSVGLine
ref={this.refMethod}
{...extractProps(propsAndStyles(props), this)}
{...extract(this, props)}
x1={x1}
y1={y1}
x2={x2}
+2 -2
View File
@@ -1,7 +1,7 @@
import React from 'react';
import { requireNativeComponent } from 'react-native';
import extractTransform from '../lib/extract/extractTransform';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { withoutXY } from '../lib/extract/extractProps';
import { NumberProp, TransformProps } from '../lib/extract/types';
import units from '../lib/units';
import Shape from './Shape';
@@ -41,7 +41,7 @@ export default class Mask extends Shape<{
return (
<RNSVGMask
ref={this.refMethod}
{...extractProps({ ...propsAndStyles(props), x: null, y: null }, this)}
{...withoutXY(this, props)}
x={x}
y={y}
width={width}
+2 -6
View File
@@ -1,6 +1,6 @@
import React from 'react';
import { requireNativeComponent } from 'react-native';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { extract } from '../lib/extract/extractProps';
import Shape from './Shape';
export default class Path extends Shape<{
@@ -11,11 +11,7 @@ export default class Path extends Shape<{
render() {
const { props } = this;
return (
<RNSVGPath
ref={this.refMethod}
{...extractProps(propsAndStyles(props), this)}
d={props.d}
/>
<RNSVGPath ref={this.refMethod} {...extract(this, props)} d={props.d} />
);
}
}
+2 -9
View File
@@ -1,6 +1,6 @@
import React from 'react';
import { requireNativeComponent } from 'react-native';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { withoutXY } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
@@ -27,14 +27,7 @@ export default class Rect extends Shape<{
return (
<RNSVGRect
ref={this.refMethod}
{...extractProps(
{
...propsAndStyles(props),
x: null,
y: null,
},
this,
)}
{...withoutXY(this, props)}
x={x}
y={y}
width={width}
+2 -9
View File
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import { requireNativeComponent } from 'react-native';
import extractTransform from '../lib/extract/extractTransform';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { withoutXY } from '../lib/extract/extractProps';
import { NumberProp, TransformProps } from '../lib/extract/types';
import extractText from '../lib/extract/extractText';
import { idPattern, pickNotNil } from '../lib/util';
@@ -51,14 +51,7 @@ export default class TextPath extends Shape<{
const matched = href && href.match(idPattern);
const match = matched && matched[1];
if (match) {
const props = extractProps(
{
...propsAndStyles(prop),
x: null,
y: null,
},
this,
);
const props = withoutXY(this, prop);
Object.assign(
props,
extractText(
+2 -2
View File
@@ -1,6 +1,6 @@
import React from 'react';
import { requireNativeComponent } from 'react-native';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { withoutXY } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import { idPattern } from '../lib/util';
import Shape from './Shape';
@@ -48,7 +48,7 @@ export default class Use extends Shape<{
return (
<RNSVGUse
ref={this.refMethod}
{...extractProps({ ...propsAndStyles(props), x: null, y: null }, this)}
{...withoutXY(this, props)}
href={match}
x={x}
y={y}
+11
View File
@@ -149,3 +149,14 @@ export default function extractProps(
return extracted;
}
export function extract(instance: Object, props: Object & { style?: [] | {} }) {
return extractProps(propsAndStyles(props), instance);
}
export function withoutXY(
instance: Object,
props: Object & { style?: [] | {} },
) {
return extractProps({ ...propsAndStyles(props), x: null, y: null }, instance);
}