mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-20 14:05:09 +00:00
Fix linting, warnings, add noinspection suppression comments.
This commit is contained in:
@@ -80,6 +80,7 @@ Here's a simple example. To render output like this:
|
||||
Use the following code:
|
||||
|
||||
```javascript
|
||||
import 'react';
|
||||
import Svg,{
|
||||
Circle,
|
||||
Ellipse,
|
||||
|
||||
@@ -5,6 +5,7 @@ import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shi
|
||||
import {ImageAttributes} from '../lib/attributes';
|
||||
import {numberProp, touchableProps, responderProps} from '../lib/props';
|
||||
import Shape from './Shape';
|
||||
//noinspection JSUnresolvedVariable
|
||||
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
|
||||
import {meetOrSliceTypes, alignEnum} from '../lib/extract/extractViewBox';
|
||||
import extractProps from '../lib/extract/extractProps';
|
||||
|
||||
@@ -16,6 +16,7 @@ export default class extends Component{
|
||||
};
|
||||
|
||||
setNativeProps = (...args) => {
|
||||
//noinspection JSUnresolvedFunction
|
||||
this.root.getNativeElement().setNativeProps(...args);
|
||||
};
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ export default class extends Component{
|
||||
};
|
||||
|
||||
setNativeProps = (...args) => {
|
||||
//noinspection JSUnresolvedFunction
|
||||
this.root.getNativeElement().setNativeProps(...args);
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ class Shape extends Component {
|
||||
_.forEach(SvgTouchableMixin, (method, key) => {
|
||||
this[key] = method.bind(this);
|
||||
});
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
this.state = this.touchableGetInitialState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//noinspection JSUnresolvedVariable
|
||||
import React, {
|
||||
Component
|
||||
} from 'react';
|
||||
@@ -12,6 +13,7 @@ import {
|
||||
import extractViewBox from '../lib/extract/extractViewBox';
|
||||
import {ViewBoxAttributes} from '../lib/attributes';
|
||||
|
||||
/** @namespace NativeModules.RNSVGSvgViewManager */
|
||||
const RNSVGSvgViewManager = NativeModules.RNSVGSvgViewManager;
|
||||
|
||||
// Svg - Root node of all Svg elements
|
||||
@@ -43,6 +45,7 @@ class Svg extends Component{
|
||||
super(...arguments);
|
||||
id++;
|
||||
this.id = id;
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
this.onDataURLCallbacks = [];
|
||||
}
|
||||
measureInWindow = (...args) => {
|
||||
@@ -61,7 +64,7 @@ class Svg extends Component{
|
||||
this.root.setNativeProps(...args);
|
||||
};
|
||||
|
||||
toDataURL = (callback: Function) => {
|
||||
toDataURL = (callback) => {
|
||||
callback && RNSVGSvgViewManager.toDataURL(findNodeHandle(this.root), callback);
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shims/createReactNativeComponentClass';
|
||||
import extractText from '../lib/extract/extractText';
|
||||
import {numberProp, pathProps, fontProps} from '../lib/props';
|
||||
import {pathProps, fontProps} from '../lib/props';
|
||||
import {TSpanAttibutes} from '../lib/attributes';
|
||||
import extractProps from '../lib/extract/extractProps';
|
||||
import Shape from './Shape';
|
||||
@@ -18,16 +18,19 @@ export default class extends Shape {
|
||||
dy: PropTypes.string,
|
||||
};
|
||||
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
static childContextTypes = {
|
||||
isInAParentText: PropTypes.bool
|
||||
};
|
||||
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
getChildContext() {
|
||||
return {
|
||||
isInAParentText: true
|
||||
};
|
||||
}
|
||||
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
getContextTypes() {
|
||||
return {
|
||||
isInAParentText: PropTypes.bool
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shims/createReactNativeComponentClass';
|
||||
import extractText from '../lib/extract/extractText';
|
||||
import {numberProp, pathProps, fontProps} from '../lib/props';
|
||||
import {pathProps, fontProps} from '../lib/props';
|
||||
import {TextAttributes} from '../lib/attributes';
|
||||
import extractProps from '../lib/extract/extractProps';
|
||||
import Shape from './Shape';
|
||||
@@ -17,16 +17,19 @@ export default class extends Shape {
|
||||
dy: PropTypes.string,
|
||||
};
|
||||
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
static childContextTypes = {
|
||||
isInAParentText: PropTypes.bool
|
||||
};
|
||||
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
getChildContext() {
|
||||
return {
|
||||
isInAParentText: true
|
||||
};
|
||||
}
|
||||
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
getContextTypes() {
|
||||
return {
|
||||
isInAParentText: PropTypes.bool
|
||||
|
||||
@@ -4,7 +4,7 @@ import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shi
|
||||
import {TextPathAttributes} from '../lib/attributes';
|
||||
import extractText from '../lib/extract/extractText';
|
||||
import Shape from './Shape';
|
||||
import {pathProps, fontProps, numberProp} from '../lib/props';
|
||||
import {pathProps, fontProps} from '../lib/props';
|
||||
import extractProps from '../lib/extract/extractProps';
|
||||
import TSpan from './TSpan';
|
||||
|
||||
|
||||
1
index.js
1
index.js
@@ -42,4 +42,5 @@ export {
|
||||
ClipPath
|
||||
};
|
||||
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
export default Svg;
|
||||
|
||||
@@ -79,13 +79,13 @@ export default class Matrix2D {
|
||||
* @return {Matrix2D} This instance. Useful for chaining method calls.
|
||||
*/
|
||||
setTransform = function(a, b, c, d, tx, ty) {
|
||||
/*eslint eqeqeq:0*/
|
||||
this.a = a == null ? 1 : a;
|
||||
this.a = a === null || a === undefined ? 1 : a;
|
||||
this.b = b || 0;
|
||||
this.c = c || 0;
|
||||
this.d = d == null ? 1 : d;
|
||||
this.d = d === null || d === undefined ? 1 : d;
|
||||
this.tx = tx || 0;
|
||||
this.ty = ty || 0;
|
||||
//noinspection JSValidateTypes
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -97,6 +97,7 @@ export default class Matrix2D {
|
||||
reset = function() {
|
||||
this.a = this.d = 1;
|
||||
this.b = this.c = this.tx = this.ty = 0;
|
||||
//noinspection JSValidateTypes
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -109,6 +110,7 @@ export default class Matrix2D {
|
||||
return [this.a, this.b, this.c, this.d, this.tx, this.ty];
|
||||
};
|
||||
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
/**
|
||||
* Copies all properties from the specified matrix to this matrix.
|
||||
* @method copy
|
||||
@@ -116,9 +118,11 @@ export default class Matrix2D {
|
||||
* @return {Matrix2D} This matrix. Useful for chaining method calls.
|
||||
*/
|
||||
copy = function(matrix) {
|
||||
//noinspection JSUnresolvedVariable
|
||||
return this.setTransform(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty);
|
||||
};
|
||||
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
/**
|
||||
* Clones current instance and returning a new matrix.
|
||||
* @method clone
|
||||
@@ -142,9 +146,9 @@ export default class Matrix2D {
|
||||
* @return {Matrix2D} This matrix. Useful for chaining method calls.
|
||||
**/
|
||||
prepend = function(a, b, c, d, tx, ty) {
|
||||
var a1 = this.a;
|
||||
var c1 = this.c;
|
||||
var tx1 = this.tx;
|
||||
const a1 = this.a;
|
||||
const c1 = this.c;
|
||||
const tx1 = this.tx;
|
||||
|
||||
this.a = a * a1 + c * this.b;
|
||||
this.b = b * a1 + d * this.b;
|
||||
@@ -152,6 +156,7 @@ export default class Matrix2D {
|
||||
this.d = b * c1 + d * this.d;
|
||||
this.tx = a * tx1 + c * this.ty + tx;
|
||||
this.ty = b * tx1 + d * this.ty + ty;
|
||||
//noinspection JSValidateTypes
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -168,10 +173,10 @@ export default class Matrix2D {
|
||||
* @return {Matrix2D} This matrix. Useful for chaining method calls.
|
||||
**/
|
||||
append = function(a, b, c, d, tx, ty) {
|
||||
var a1 = this.a;
|
||||
var b1 = this.b;
|
||||
var c1 = this.c;
|
||||
var d1 = this.d;
|
||||
const a1 = this.a;
|
||||
const b1 = this.b;
|
||||
const c1 = this.c;
|
||||
const d1 = this.d;
|
||||
if (a !== 1 || b !== 0 || c !== 0 || d !== 1) {
|
||||
this.a = a1 * a + c1 * b;
|
||||
this.b = b1 * a + d1 * b;
|
||||
@@ -180,6 +185,7 @@ export default class Matrix2D {
|
||||
}
|
||||
this.tx = a1 * tx + c1 * ty + this.tx;
|
||||
this.ty = b1 * tx + d1 * ty + this.ty;
|
||||
//noinspection JSValidateTypes
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -202,10 +208,11 @@ export default class Matrix2D {
|
||||
* @return {Matrix2D} This matrix. Useful for chaining method calls.
|
||||
**/
|
||||
appendTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) {
|
||||
let cos, sin;
|
||||
if (rotation % 360) {
|
||||
var r = rotation * DEG_TO_RAD;
|
||||
var cos = Math.cos(r);
|
||||
var sin = Math.sin(r);
|
||||
const r = rotation * DEG_TO_RAD;
|
||||
cos = Math.cos(r);
|
||||
sin = Math.sin(r);
|
||||
} else {
|
||||
cos = 1;
|
||||
sin = 0;
|
||||
@@ -226,9 +233,11 @@ export default class Matrix2D {
|
||||
this.tx -= regX * this.a + regY * this.c;
|
||||
this.ty -= regX * this.b + regY * this.d;
|
||||
}
|
||||
//noinspection JSValidateTypes
|
||||
return this;
|
||||
};
|
||||
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
/**
|
||||
* Generates matrix properties from the specified display object transform properties, and prepends them to this matrix.
|
||||
* For example, you could calculate the combined transformation for a child object using:
|
||||
@@ -255,10 +264,11 @@ export default class Matrix2D {
|
||||
* @return {Matrix2D} This matrix. Useful for chaining method calls.
|
||||
**/
|
||||
prependTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) {
|
||||
let cos, sin;
|
||||
if (rotation % 360) {
|
||||
var r = rotation * DEG_TO_RAD;
|
||||
var cos = Math.cos(r);
|
||||
var sin = Math.sin(r);
|
||||
const r = rotation * DEG_TO_RAD;
|
||||
cos = Math.cos(r);
|
||||
sin = Math.sin(r);
|
||||
} else {
|
||||
cos = 1;
|
||||
sin = 0;
|
||||
@@ -277,6 +287,7 @@ export default class Matrix2D {
|
||||
} else {
|
||||
this.prepend(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, x, y);
|
||||
}
|
||||
//noinspection JSValidateTypes
|
||||
return this;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Touchable from 'react-native/Libraries/Components/Touchable/Touchable';
|
||||
const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
|
||||
|
||||
//noinspection JSUnusedGlobalSymbols
|
||||
export default {
|
||||
...Touchable.Mixin,
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
|
||||
function arrayDiffer(a, b) {
|
||||
/*eslint eqeqeq:0*/
|
||||
if (a == null || b == null) {
|
||||
if (!a || !b) {
|
||||
return true;
|
||||
}
|
||||
if (a.length !== b.length) {
|
||||
return true;
|
||||
}
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ import Color from 'color';
|
||||
import patternReg from './patternReg';
|
||||
|
||||
export default function (colorOrBrush) {
|
||||
/*eslint eqeqeq:0*/
|
||||
if (colorOrBrush === 'none' || colorOrBrush == null) {
|
||||
if (colorOrBrush === 'none' || !colorOrBrush) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@ export default function(props, styleProperties) {
|
||||
|
||||
return {
|
||||
// default fill is black
|
||||
/*eslint eqeqeq:0*/
|
||||
fill: extractBrush(props.fill == null ? '#000' : props.fill),
|
||||
fill: extractBrush(props.fill || '#000'),
|
||||
fillOpacity: extractOpacity(props.fillOpacity),
|
||||
fillRule: fillRules[props.fillRule] === 0 ? 0 : 1
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@ export default function(props) {
|
||||
let offset = percentToFloat(child.props.offset);
|
||||
|
||||
// add stop
|
||||
//noinspection JSUnresolvedFunction
|
||||
stops[offset] = Color(child.props.stopColor).alpha(extractOpacity(child.props.stopOpacity));
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -30,7 +30,7 @@ export default function(props, ref) {
|
||||
let transform = props.transform;
|
||||
if (transform) {
|
||||
if (typeof transform === 'string') {
|
||||
var transformParsed = tp.parse(transform);
|
||||
const transformParsed = tp.parse(transform);
|
||||
if (transformParsed.matrix) {
|
||||
// TODO: Extract scaling values for coordinate system
|
||||
// Especially scaleY for calculating scaling of fontSize
|
||||
|
||||
@@ -44,7 +44,7 @@ export default function(props, styleProperties) {
|
||||
strokeLinecap: caps[props.strokeLinecap] || 0,
|
||||
strokeLinejoin: joins[props.strokeLinejoin] || 0,
|
||||
strokeDasharray: strokeDasharray || null,
|
||||
strokeWidth: strokeWidth || "1",
|
||||
strokeWidth: strokeWidth || '1',
|
||||
strokeDashoffset: strokeDasharray ? (+props.strokeDashoffset || 0) : null,
|
||||
strokeMiterlimit: props.strokeMiterlimit || 4
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import _ from 'lodash';
|
||||
//noinspection JSUnresolvedVariable
|
||||
import React, {Children} from 'react';
|
||||
import TSpan from '../../elements/TSpan';
|
||||
|
||||
@@ -28,7 +29,7 @@ function parseFontString(font) {
|
||||
return null;
|
||||
}
|
||||
const fontFamily = extractSingleFontFamily(match[3]);
|
||||
const fontSize = match[2] || "12";
|
||||
const fontSize = match[2] || '12';
|
||||
const isBold = /bold/.exec(match[1]);
|
||||
const isItalic = /italic/.exec(match[1]);
|
||||
const fontWeight = isBold ? 'bold' : 'normal';
|
||||
|
||||
@@ -15,11 +15,11 @@ function transformToMatrix(props, transform) {
|
||||
|
||||
class TransformParser {
|
||||
constructor() {
|
||||
var floating = '(\\-?[\\d\\.e]+)';
|
||||
var commaSpace = '\\,?\\s*';
|
||||
const floating = '(\\-?[\\d\\.e]+)';
|
||||
const commaSpace = '\\,?\\s*';
|
||||
|
||||
this.regex = {
|
||||
split: /[\s*(\s*|\s*)\s*|\s*,\s*]/,
|
||||
split: /[\s*()|,]/,
|
||||
matrix: new RegExp(
|
||||
'^matrix\\(' +
|
||||
floating + commaSpace +
|
||||
@@ -33,7 +33,7 @@ class TransformParser {
|
||||
|
||||
parse(transform) {
|
||||
if (transform) {
|
||||
var retval = {};
|
||||
const retval = {};
|
||||
let transLst = _.filter(
|
||||
transform.split(this.regex.split),
|
||||
(ele) => {
|
||||
@@ -50,11 +50,11 @@ class TransformParser {
|
||||
break;
|
||||
case 'translate':
|
||||
retval.translateX = transLst[i + 1];
|
||||
retval.translateY = (3 === transLst.length) ? transLst[i + 2] : 0;
|
||||
retval.translateY = (transLst.length === 3) ? transLst[i + 2] : 0;
|
||||
break;
|
||||
case 'scale':
|
||||
retval.scaleX = transLst[i + 1];
|
||||
retval.scaleY = (3 === transLst.length) ? transLst[i + 2] : retval.scaleX;
|
||||
retval.scaleY = (transLst.length === 3) ? transLst[i + 2] : retval.scaleX;
|
||||
break;
|
||||
case 'rotate':
|
||||
retval.rotation = transLst[i + 1];
|
||||
@@ -72,17 +72,6 @@ class TransformParser {
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
parseMatrix(transform) {
|
||||
var matrix = this.regex.matrix.exec(transform);
|
||||
if (matrix) {
|
||||
matrix.shift();
|
||||
for (var i = matrix.length - 1; i >= 0; i--) {
|
||||
matrix[i] = parseFloat(matrix[i]);
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
}
|
||||
|
||||
export const tp = new TransformParser();
|
||||
@@ -91,7 +80,7 @@ export const tp = new TransformParser();
|
||||
function appendTransform(transform) {
|
||||
if (transform) {
|
||||
if (typeof transform === 'string') {
|
||||
var transformParsed = tp.parse(transform);
|
||||
const transformParsed = tp.parse(transform);
|
||||
if (transformParsed.matrix) {
|
||||
pooledMatrix.append(...transformParsed.matrix);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
"babel-eslint": "^6.1.2",
|
||||
"eslint": "^2.13.1",
|
||||
"eslint-plugin-react": "^4.3.0",
|
||||
"react-native": "^0.46.0"
|
||||
"prop-types": "^15.5.10",
|
||||
"react": "^16.0.0-alpha.12",
|
||||
"react-native": ">=0.46.0"
|
||||
},
|
||||
"nativePackage": true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user