mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-08 01:00:43 +00:00
chore: refactor props and styles extraction
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { requireNativeComponent } from 'react-native';
|
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 { NumberProp } from '../lib/extract/types';
|
||||||
import Shape from './Shape';
|
import Shape from './Shape';
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ export default class Circle extends Shape<{
|
|||||||
return (
|
return (
|
||||||
<RNSVGCircle
|
<RNSVGCircle
|
||||||
ref={this.refMethod}
|
ref={this.refMethod}
|
||||||
{...extractProps(propsAndStyles(props), this)}
|
{...extract(this, props)}
|
||||||
cx={cx}
|
cx={cx}
|
||||||
cy={cy}
|
cy={cy}
|
||||||
r={r}
|
r={r}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { requireNativeComponent } from 'react-native';
|
import { requireNativeComponent } from 'react-native';
|
||||||
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
|
import { extract } from '../lib/extract/extractProps';
|
||||||
import Shape from './Shape';
|
import Shape from './Shape';
|
||||||
|
|
||||||
export default class ClipPath extends Shape<{}> {
|
export default class ClipPath extends Shape<{}> {
|
||||||
@@ -9,10 +9,7 @@ export default class ClipPath extends Shape<{}> {
|
|||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
return (
|
return (
|
||||||
<RNSVGClipPath
|
<RNSVGClipPath ref={this.refMethod} {...extract(this, props)}>
|
||||||
ref={this.refMethod}
|
|
||||||
{...extractProps(propsAndStyles(props), this)}
|
|
||||||
>
|
|
||||||
{props.children}
|
{props.children}
|
||||||
</RNSVGClipPath>
|
</RNSVGClipPath>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { requireNativeComponent } from 'react-native';
|
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 { NumberProp } from '../lib/extract/types';
|
||||||
import Shape from './Shape';
|
import Shape from './Shape';
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export default class Ellipse extends Shape<{
|
|||||||
return (
|
return (
|
||||||
<RNSVGEllipse
|
<RNSVGEllipse
|
||||||
ref={this.refMethod}
|
ref={this.refMethod}
|
||||||
{...extractProps(propsAndStyles(props), this)}
|
{...extract(this, props)}
|
||||||
cx={cx}
|
cx={cx}
|
||||||
cy={cy}
|
cy={cy}
|
||||||
rx={rx}
|
rx={rx}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
requireNativeComponent,
|
requireNativeComponent,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { meetOrSliceTypes, alignEnum } from '../lib/extract/extractViewBox';
|
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 { NumberProp } from '../lib/extract/types';
|
||||||
import Shape from './Shape';
|
import Shape from './Shape';
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ export default class SvgImage extends Shape<{
|
|||||||
return (
|
return (
|
||||||
<RNSVGImage
|
<RNSVGImage
|
||||||
ref={this.refMethod}
|
ref={this.refMethod}
|
||||||
{...extractProps({ ...propsAndStyles(props), x: null, y: null }, this)}
|
{...withoutXY(this, props)}
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
width={width}
|
width={width}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { requireNativeComponent } from 'react-native';
|
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 { NumberProp } from '../lib/extract/types';
|
||||||
import Shape from './Shape';
|
import Shape from './Shape';
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export default class Line extends Shape<{
|
|||||||
return (
|
return (
|
||||||
<RNSVGLine
|
<RNSVGLine
|
||||||
ref={this.refMethod}
|
ref={this.refMethod}
|
||||||
{...extractProps(propsAndStyles(props), this)}
|
{...extract(this, props)}
|
||||||
x1={x1}
|
x1={x1}
|
||||||
y1={y1}
|
y1={y1}
|
||||||
x2={x2}
|
x2={x2}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { requireNativeComponent } from 'react-native';
|
import { requireNativeComponent } from 'react-native';
|
||||||
import extractTransform from '../lib/extract/extractTransform';
|
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 { NumberProp, TransformProps } from '../lib/extract/types';
|
||||||
import units from '../lib/units';
|
import units from '../lib/units';
|
||||||
import Shape from './Shape';
|
import Shape from './Shape';
|
||||||
@@ -41,7 +41,7 @@ export default class Mask extends Shape<{
|
|||||||
return (
|
return (
|
||||||
<RNSVGMask
|
<RNSVGMask
|
||||||
ref={this.refMethod}
|
ref={this.refMethod}
|
||||||
{...extractProps({ ...propsAndStyles(props), x: null, y: null }, this)}
|
{...withoutXY(this, props)}
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
width={width}
|
width={width}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { requireNativeComponent } from 'react-native';
|
import { requireNativeComponent } from 'react-native';
|
||||||
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
|
import { extract } from '../lib/extract/extractProps';
|
||||||
import Shape from './Shape';
|
import Shape from './Shape';
|
||||||
|
|
||||||
export default class Path extends Shape<{
|
export default class Path extends Shape<{
|
||||||
@@ -11,11 +11,7 @@ export default class Path extends Shape<{
|
|||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
return (
|
return (
|
||||||
<RNSVGPath
|
<RNSVGPath ref={this.refMethod} {...extract(this, props)} d={props.d} />
|
||||||
ref={this.refMethod}
|
|
||||||
{...extractProps(propsAndStyles(props), this)}
|
|
||||||
d={props.d}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { requireNativeComponent } from 'react-native';
|
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 { NumberProp } from '../lib/extract/types';
|
||||||
import Shape from './Shape';
|
import Shape from './Shape';
|
||||||
|
|
||||||
@@ -27,14 +27,7 @@ export default class Rect extends Shape<{
|
|||||||
return (
|
return (
|
||||||
<RNSVGRect
|
<RNSVGRect
|
||||||
ref={this.refMethod}
|
ref={this.refMethod}
|
||||||
{...extractProps(
|
{...withoutXY(this, props)}
|
||||||
{
|
|
||||||
...propsAndStyles(props),
|
|
||||||
x: null,
|
|
||||||
y: null,
|
|
||||||
},
|
|
||||||
this,
|
|
||||||
)}
|
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
width={width}
|
width={width}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { requireNativeComponent } from 'react-native';
|
import { requireNativeComponent } from 'react-native';
|
||||||
import extractTransform from '../lib/extract/extractTransform';
|
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 { NumberProp, TransformProps } from '../lib/extract/types';
|
||||||
import extractText from '../lib/extract/extractText';
|
import extractText from '../lib/extract/extractText';
|
||||||
import { idPattern, pickNotNil } from '../lib/util';
|
import { idPattern, pickNotNil } from '../lib/util';
|
||||||
@@ -51,14 +51,7 @@ export default class TextPath extends Shape<{
|
|||||||
const matched = href && href.match(idPattern);
|
const matched = href && href.match(idPattern);
|
||||||
const match = matched && matched[1];
|
const match = matched && matched[1];
|
||||||
if (match) {
|
if (match) {
|
||||||
const props = extractProps(
|
const props = withoutXY(this, prop);
|
||||||
{
|
|
||||||
...propsAndStyles(prop),
|
|
||||||
x: null,
|
|
||||||
y: null,
|
|
||||||
},
|
|
||||||
this,
|
|
||||||
);
|
|
||||||
Object.assign(
|
Object.assign(
|
||||||
props,
|
props,
|
||||||
extractText(
|
extractText(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { requireNativeComponent } from 'react-native';
|
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 { NumberProp } from '../lib/extract/types';
|
||||||
import { idPattern } from '../lib/util';
|
import { idPattern } from '../lib/util';
|
||||||
import Shape from './Shape';
|
import Shape from './Shape';
|
||||||
@@ -48,7 +48,7 @@ export default class Use extends Shape<{
|
|||||||
return (
|
return (
|
||||||
<RNSVGUse
|
<RNSVGUse
|
||||||
ref={this.refMethod}
|
ref={this.refMethod}
|
||||||
{...extractProps({ ...propsAndStyles(props), x: null, y: null }, this)}
|
{...withoutXY(this, props)}
|
||||||
href={match}
|
href={match}
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
|
|||||||
@@ -149,3 +149,14 @@ export default function extractProps(
|
|||||||
|
|
||||||
return extracted;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user