fix lint warnings

This commit is contained in:
Horcrux
2016-07-27 12:10:12 +08:00
parent f2ee72bb76
commit 7d09dcde29
19 changed files with 54 additions and 61 deletions

View File

@@ -1,4 +1,4 @@
import React, {PropTypes} from 'react'; import React from 'react';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import Shape from './Shape'; import Shape from './Shape';
import {CircleAttributes} from '../lib/attributes'; import {CircleAttributes} from '../lib/attributes';
@@ -27,7 +27,7 @@ class Circle extends Shape {
render() { render() {
let props = this.props; let props = this.props;
return <RNSVGCircle return <RNSVGCircle
ref={ele => this.root = ele} ref={ele => {this.root = ele;}}
{...this.extractProps(props)} {...this.extractProps(props)}
cx={props.cx.toString()} cx={props.cx.toString()}
cy={props.cy.toString()} cy={props.cy.toString()}

View File

@@ -1,6 +1,6 @@
import React, { import React, {
Component, Component,
} from 'react' } from 'react';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
class Defs extends Component { class Defs extends Component {

View File

@@ -1,4 +1,4 @@
import React, {PropTypes} from 'react'; import React from 'react';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import Shape from './Shape'; import Shape from './Shape';
import {pathProps, numberProp} from '../lib/props'; import {pathProps, numberProp} from '../lib/props';
@@ -30,7 +30,7 @@ class Ellipse extends Shape{
let props = this.props; let props = this.props;
return <RNSVGEllipse return <RNSVGEllipse
ref={ele => this.root = ele} ref={ele => {this.root = ele;}}
{...this.extractProps(props)} {...this.extractProps(props)}
cx={props.cx.toString()} cx={props.cx.toString()}
cy={props.cy.toString()} cy={props.cy.toString()}

View File

@@ -1,5 +1,4 @@
import React, {Component, PropTypes} from 'react'; import React, {Component} from 'react';
import _ from 'lodash';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import {transformProps} from '../lib/props'; import {transformProps} from '../lib/props';
import {GroupAttributes} from '../lib/attributes'; import {GroupAttributes} from '../lib/attributes';
@@ -25,9 +24,7 @@ class G extends Component{
return <RNSVGGroup return <RNSVGGroup
{...extractedProps} {...extractedProps}
ref={ele => { ref={ele => {this.root = ele;}}
this.root = ele;
}}
> >
{this.props.children} {this.props.children}
</RNSVGGroup>; </RNSVGGroup>;

View File

@@ -1,4 +1,4 @@
import React, {Children, Component} from 'react'; import {Children, Component} from 'react';
import percentToFloat from '../lib/percentToFloat'; import percentToFloat from '../lib/percentToFloat';
import Stop from './Stop'; import Stop from './Stop';
import Color from 'color'; import Color from 'color';
@@ -20,7 +20,7 @@ class Gradient extends Component{
stops[offset] = Color(child.props.stopColor).alpha(extractOpacity(child.props.stopOpacity)); stops[offset] = Color(child.props.stopColor).alpha(extractOpacity(child.props.stopOpacity));
} }
} else { } else {
console.warn(`'Gradient' can only receive 'Stop' elements as children`); console.warn('\'Gradient\' can only receive \'Stop\' elements as children');
} }
}); });

View File

@@ -33,7 +33,7 @@ class Image extends Shape {
render() { render() {
let {props} = this; let {props} = this;
return <RNSVGImage return <RNSVGImage
ref={ele => this.root = ele} ref={ele => {this.root = ele;}}
{...this.extractProps(props, {responder: true})} {...this.extractProps(props, {responder: true})}
x={props.x.toString()} x={props.x.toString()}
y={props.y.toString()} y={props.y.toString()}

View File

@@ -1,4 +1,4 @@
import React, {PropTypes} from 'react'; import React from 'react';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import {LineAttributes} from '../lib/attributes'; import {LineAttributes} from '../lib/attributes';
import Shape from './Shape'; import Shape from './Shape';
@@ -29,7 +29,7 @@ class Line extends Shape {
render() { render() {
let props = this.props; let props = this.props;
return <RNSVGLine return <RNSVGLine
ref={ele => this.root = ele} ref={ele => {this.root = ele;}}
{...this.extractProps(props)} {...this.extractProps(props)}
x1={props.x1.toString()} x1={props.x1.toString()}
y1={props.y1.toString()} y1={props.y1.toString()}

View File

@@ -3,7 +3,7 @@ import SerializablePath from '../lib/SerializablePath';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import {PathAttributes} from '../lib/attributes'; import {PathAttributes} from '../lib/attributes';
import Shape from './Shape'; import Shape from './Shape';
import {pathProps, numberProp} from '../lib/props'; import {pathProps} from '../lib/props';
class Path extends Shape { class Path extends Shape {
static displayName = 'Path'; static displayName = 'Path';
@@ -23,7 +23,7 @@ class Path extends Shape {
let d = new SerializablePath(props.d).toJSON(); let d = new SerializablePath(props.d).toJSON();
return ( return (
<RNSVGPath <RNSVGPath
ref={ele => this.root = ele} ref={ele => {this.root = ele;}}
{...this.extractProps(props)} {...this.extractProps(props)}
d={d} d={d}
/> />

View File

@@ -25,7 +25,7 @@ class Polygon extends Component{
} }
return <Path return <Path
ref={ele => this.root = ele} ref={ele => {this.root = ele;}}
{...this.props} {...this.props}
d={`M${points.trim().replace(/\s+/g, 'L')}z`} d={`M${points.trim().replace(/\s+/g, 'L')}z`}
/>; />;

View File

@@ -25,7 +25,7 @@ class Polyline extends Component{
} }
return <Path return <Path
ref={ele => this.root = ele} ref={ele => {this.root = ele;}}
{...this.props} {...this.props}
d={`M${points.trim().replace(/\s+/g, 'L')}`} d={`M${points.trim().replace(/\s+/g, 'L')}`}
/>; />;

View File

@@ -1,4 +1,4 @@
import React, {PropTypes} from 'react'; import React from 'react';
import './Path'; // must import Path first, don`t know why. without this will throw an `Super expression must either be null or a function, not undefined` import './Path'; // must import Path first, don`t know why. without this will throw an `Super expression must either be null or a function, not undefined`
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import {pathProps, numberProp} from '../lib/props'; import {pathProps, numberProp} from '../lib/props';
@@ -35,7 +35,7 @@ class Rect extends Shape {
let props = this.props; let props = this.props;
return <RNSVGRect return <RNSVGRect
ref={ele => this.root = ele} ref={ele => {this.root = ele;}}
{...this.extractProps({ {...this.extractProps({
...props, ...props,
x: null, x: null,

View File

@@ -1,4 +1,4 @@
import React, {Children, Component, cloneElement, PropTypes} from 'react'; import React, {Component, PropTypes} from 'react';
import {View, requireNativeComponent, StyleSheet} from 'react-native'; import {View, requireNativeComponent, StyleSheet} from 'react-native';
import ViewBox from './ViewBox'; import ViewBox from './ViewBox';
@@ -57,7 +57,7 @@ class Svg extends Component{
width, width,
height, height,
flex: 0 flex: 0
} };
} }
if (props.viewbox) { if (props.viewbox) {
@@ -78,7 +78,7 @@ class Svg extends Component{
height={null} height={null}
viewBox={null} viewBox={null}
preserveAspectRatio={null} preserveAspectRatio={null}
ref={ele => this.root = ele} ref={ele => {this.root = ele;}}
style={[ style={[
styles.svg, styles.svg,
props.style, props.style,

View File

@@ -1,6 +1,5 @@
import React, {PropTypes} from 'react'; import React, {PropTypes} from 'react';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import Defs from './Defs';
import extractProps from '../lib/extract/extractProps'; import extractProps from '../lib/extract/extractProps';
import extractText from '../lib/extract/extractText'; import extractText from '../lib/extract/extractText';
import {numberProp, pathProps} from '../lib/props'; import {numberProp, pathProps} from '../lib/props';
@@ -47,7 +46,7 @@ class Text extends Shape {
return ( return (
<RNSVGText <RNSVGText
ref={ele => this.root = ele} ref={ele => {this.root = ele;}}
{...extractProps({...props, x, y})} {...extractProps({...props, x, y})}
{...extractText(props)} {...extractText(props)}
/> />

View File

@@ -4,7 +4,6 @@ import {UseAttributes} from '../lib/attributes';
import Shape from './Shape'; import Shape from './Shape';
import React from 'react'; import React from 'react';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import _ from 'lodash';
const idExpReg = /^#(.+)$/; const idExpReg = /^#(.+)$/;
class Use extends Shape { class Use extends Shape {
@@ -43,7 +42,7 @@ class Use extends Shape {
}); });
return <RNSVGUse return <RNSVGUse
ref={ele => this.root = ele} ref={ele => {this.root = ele;}}
{...extractedProps} {...extractedProps}
href={href} href={href}
width={props.width} width={props.width}

View File

@@ -44,7 +44,7 @@ class ViewBox extends Component{
console.warn('`viewBox` expected a string like `minX minY width height`, but got:' + viewBox); console.warn('`viewBox` expected a string like `minX minY width height`, but got:' + viewBox);
return <G> return <G>
{this.props.children} {this.props.children}
</G> </G>;
} }
let modes = preserveAspectRatio.trim().split(spacesRegExp); let modes = preserveAspectRatio.trim().split(spacesRegExp);
@@ -62,7 +62,7 @@ class ViewBox extends Component{
meetOrSlice={meetOrSlice} meetOrSlice={meetOrSlice}
> >
{this.props.children} {this.props.children}
</RNSVGViewBox> </RNSVGViewBox>;
} }
} }

View File

@@ -2,8 +2,8 @@
* based on * based on
* https://github.com/CreateJS/EaselJS/blob/631cdffb85eff9413dab43b4676f059b4232d291/src/easeljs/geom/Matrix2D.js * https://github.com/CreateJS/EaselJS/blob/631cdffb85eff9413dab43b4676f059b4232d291/src/easeljs/geom/Matrix2D.js
*/ */
import _ from 'lodash';
const DEG_TO_RAD = Math.PI/180; const DEG_TO_RAD = Math.PI / 180;
/** /**
* Represents an affine transformation matrix, and provides tools for constructing and concatenating matrices. * Represents an affine transformation matrix, and provides tools for constructing and concatenating matrices.
@@ -81,10 +81,10 @@ class Matrix2D {
*/ */
setTransform = function(a, b, c, d, tx, ty) { setTransform = function(a, b, c, d, tx, ty) {
// don't forget to update docs in the constructor if these change: // don't forget to update docs in the constructor if these change:
this.a = (a == null) ? 1 : a; this.a = _.isNil(a) ? 1 : a;
this.b = b || 0; this.b = b || 0;
this.c = c || 0; this.c = c || 0;
this.d = (d == null) ? 1 : d; this.d = _.isNil(d) ? 1 : d;
this.tx = tx || 0; this.tx = tx || 0;
this.ty = ty || 0; this.ty = ty || 0;
return this; return this;
@@ -147,12 +147,12 @@ class Matrix2D {
var c1 = this.c; var c1 = this.c;
var tx1 = this.tx; var tx1 = this.tx;
this.a = a*a1+c*this.b; this.a = a * a1 + c * this.b;
this.b = b*a1+d*this.b; this.b = b * a1 + d * this.b;
this.c = a*c1+c*this.d; this.c = a * c1 + c * this.d;
this.d = b*c1+d*this.d; this.d = b * c1 + d * this.d;
this.tx = a*tx1+c*this.ty+tx; this.tx = a * tx1 + c * this.ty + tx;
this.ty = b*tx1+d*this.ty+ty; this.ty = b * tx1 + d * this.ty + ty;
return this; return this;
}; };
@@ -173,14 +173,14 @@ class Matrix2D {
var b1 = this.b; var b1 = this.b;
var c1 = this.c; var c1 = this.c;
var d1 = this.d; var d1 = this.d;
if (a != 1 || b != 0 || c != 0 || d != 1) { if (a !== 1 || b !== 0 || c !== 0 || d !== 1) {
this.a = a1*a+c1*b; this.a = a1 * a + c1 * b;
this.b = b1*a+d1*b; this.b = b1 * a + d1 * b;
this.c = a1*c+c1*d; this.c = a1 * c + c1 * d;
this.d = b1*c+d1*d; this.d = b1 * c + d1 * d;
} }
this.tx = a1*tx+c1*ty+this.tx; this.tx = a1 * tx + c1 * ty + this.tx;
this.ty = b1*tx+d1*ty+this.ty; this.ty = b1 * tx + d1 * ty + this.ty;
return this; return this;
}; };
@@ -203,8 +203,8 @@ class Matrix2D {
* @return {Matrix2D} This matrix. Useful for chaining method calls. * @return {Matrix2D} This matrix. Useful for chaining method calls.
**/ **/
appendTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) { appendTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) {
if (rotation%360) { if (rotation % 360) {
var r = rotation*DEG_TO_RAD; var r = rotation * DEG_TO_RAD;
var cos = Math.cos(r); var cos = Math.cos(r);
var sin = Math.sin(r); var sin = Math.sin(r);
} else { } else {
@@ -217,15 +217,15 @@ class Matrix2D {
skewX *= DEG_TO_RAD; skewX *= DEG_TO_RAD;
skewY *= DEG_TO_RAD; skewY *= DEG_TO_RAD;
this.append(Math.cos(skewY), Math.sin(skewY), -Math.sin(skewX), Math.cos(skewX), x, y); this.append(Math.cos(skewY), Math.sin(skewY), -Math.sin(skewX), Math.cos(skewX), x, y);
this.append(cos*scaleX, sin*scaleX, -sin*scaleY, cos*scaleY, 0, 0); this.append(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, 0, 0);
} else { } else {
this.append(cos*scaleX, sin*scaleX, -sin*scaleY, cos*scaleY, x, y); this.append(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, x, y);
} }
if (regX || regY) { if (regX || regY) {
// append the registration offset: // append the registration offset:
this.tx -= regX*this.a+regY*this.c; this.tx -= regX * this.a + regY * this.c;
this.ty -= regX*this.b+regY*this.d; this.ty -= regX * this.b + regY * this.d;
} }
return this; return this;
}; };
@@ -256,8 +256,8 @@ class Matrix2D {
* @return {Matrix2D} This matrix. Useful for chaining method calls. * @return {Matrix2D} This matrix. Useful for chaining method calls.
**/ **/
prependTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) { prependTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) {
if (rotation%360) { if (rotation % 360) {
var r = rotation*DEG_TO_RAD; var r = rotation * DEG_TO_RAD;
var cos = Math.cos(r); var cos = Math.cos(r);
var sin = Math.sin(r); var sin = Math.sin(r);
} else { } else {
@@ -273,10 +273,10 @@ class Matrix2D {
// TODO: can this be combined into a single prepend operation? // TODO: can this be combined into a single prepend operation?
skewX *= DEG_TO_RAD; skewX *= DEG_TO_RAD;
skewY *= DEG_TO_RAD; skewY *= DEG_TO_RAD;
this.prepend(cos*scaleX, sin*scaleX, -sin*scaleY, cos*scaleY, 0, 0); this.prepend(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, 0, 0);
this.prepend(Math.cos(skewY), Math.sin(skewY), -Math.sin(skewX), Math.cos(skewX), x, y); this.prepend(Math.cos(skewY), Math.sin(skewY), -Math.sin(skewX), Math.cos(skewX), x, y);
} else { } else {
this.prepend(cos*scaleX, sin*scaleX, -sin*scaleY, cos*scaleY, x, y); this.prepend(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, x, y);
} }
return this; return this;
}; };

View File

@@ -3,8 +3,6 @@ const MOVE_TO = 0;
const CLOSE = 1; const CLOSE = 1;
const LINE_TO = 2; const LINE_TO = 2;
const CURVE_TO = 3; const CURVE_TO = 3;
const ARC = 4;
export default class SerializablePath { export default class SerializablePath {
constructor(path) { constructor(path) {

View File

@@ -17,7 +17,7 @@ export default function (colorOrBrush) {
let c = new Color(colorOrBrush).rgbaArray(); let c = new Color(colorOrBrush).rgbaArray();
return [0, c[0] / 255, c[1] / 255, c[2] / 255, c[3]]; return [0, c[0] / 255, c[1] / 255, c[2] / 255, c[3]];
} }
} catch(err) { } catch (err) {
console.warn(`"${colorOrBrush}" is not a valid color or brush`); console.warn(`"${colorOrBrush}" is not a valid color or brush`);
return null; return null;
} }

View File

@@ -1,7 +1,7 @@
{ {
"version": "4.0.0", "version": "4.0.0",
"name": "react-native-svg", "name": "react-native-svg",
"description": "react native svg library", "description": "SVG library for react-native",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/magicismight/react-native-svg" "url": "https://github.com/magicismight/react-native-svg"