Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove index.d.ts and flow #1708

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ cn-doc.md
experimental/

/lib/
/flow-typed/

# VS Code
.vscode/
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ https://github.com/react-native-svg/react-native-svg/issues/1554

Install the JavaScript with:

```bash
expo install react-native-svg
```
```bash
expo install react-native-svg
```

📚 See the [**Expo docs**](https://docs.expo.io/versions/latest/sdk/svg/) for more info or jump ahead to [Usage](#Usage).

Expand All @@ -79,10 +79,13 @@ Install the JavaScript with:
1. Install library

from npm

```bash
npm install react-native-svg
```

from yarn

```bash
yarn add react-native-svg
```
Expand Down
15 changes: 4 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "lib/commonjs/index.js",
"module": "lib/module/index.js",
"react-native": "src/index.ts",
"types": "src/index.d.ts",
"types": "lib/typescript/index",
"files": [
"__tests__",
"android",
Expand Down Expand Up @@ -42,16 +42,13 @@
],
"scripts": {
"bob": "bob build",
"flow": "flow src",
"flowgen": "flowgen src/index.d.ts -o src/index.js.flow",
"flowtyped": "flow-typed install",
"format": "prettier README.md CONTRIBUTING.md CODE_OF_CONDUCT.md './src/**/*.{ts,tsx}' src/index.d.ts --write",
"format": "prettier README.md CONTRIBUTING.md CODE_OF_CONDUCT.md './src/**/*.{ts,tsx}' --write",
"jest": "jest",
"lint": "eslint --ext .ts,.tsx src",
"peg": "pegjs -o src/lib/extract/transform.js ./src/lib/extract/transform.peg",
"prepare": "npm run flowgen && npm run bob",
"prepare": " npm run bob",
"test": "npm run lint && npm run tsc && npm run jest",
"release": "npm login && release-it",
"test": "npm run lint && npm run tsc && npm run flow && npm run jest",
"tsc": "tsc --noEmit"
},
"peerDependencies": {
Expand All @@ -72,12 +69,8 @@
"babel-eslint": "^10.1.0",
"babel-jest": "^25.1.0",
"eslint": "^6.8.0",
"eslint-plugin-flowtype": "^4.6.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.3",
"flow-bin": "^0.119.1",
"flow-typed": "^3.0.0",
"flowgen": "^1.10.0",
"jest": "^25.1.0",
"pegjs": "^0.10.0",
"prettier": "^1.19.1",
Expand Down
1 change: 1 addition & 0 deletions src/ReactNativeSVG.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const prepare = <T extends BaseProps>(
...rest
} = props;
const hasTouchableProperty = getHasTouchableProperty(props);
// @ts-ignore for some reason it throws error
const clean: {
onStartShouldSetResponder?: (e: GestureResponderEvent) => boolean;
onResponderMove?: (e: GestureResponderEvent) => void;
Expand Down
8 changes: 5 additions & 3 deletions src/css.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function hasAttrib(elem: XmlAST, name: string): boolean {
// finds the first node in the array that matches the test predicate, or one
// of its children
function findOne(
predicate: (v: XmlAST)=> boolean,
predicate: (v: XmlAST) => boolean,
elems: Array<XmlAST | string>,
): XmlAST | null {
let elem: XmlAST | null = null;
Expand Down Expand Up @@ -637,8 +637,10 @@ export const inlineStyles: Middleware = function inlineStyles(
const selectorStr = csstree.generate(item.data);
try {
// apply <style/> to matched elements
const matched = cssSelect(selectorStr, document, cssSelectOpts).map(initStyle);

const matched = cssSelect(selectorStr, document, cssSelectOpts).map(
initStyle,
);

if (matched.length === 0) {
continue;
}
Expand Down
8 changes: 2 additions & 6 deletions src/elements/Circle.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import React from 'react';
import { extract } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
import { RNSVGCircle } from './NativeComponents';
import { CircleProps } from './types';

export default class Circle extends Shape<{
cx?: NumberProp;
cy?: NumberProp;
r?: NumberProp;
}> {
export default class Circle extends Shape<CircleProps> {
static displayName = 'Circle';

static defaultProps = {
Expand Down
3 changes: 2 additions & 1 deletion src/elements/ClipPath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React from 'react';
import { extract } from '../lib/extract/extractProps';
import Shape from './Shape';
import { RNSVGClipPath } from './NativeComponents';
import { ClipPathProps } from './types';

export default class ClipPath extends Shape<{}> {
export default class ClipPath extends Shape<ClipPathProps> {
static displayName = 'ClipPath';

render() {
Expand Down
9 changes: 2 additions & 7 deletions src/elements/Ellipse.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React from 'react';
import { extract } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
import { RNSVGEllipse } from './NativeComponents';
import { EllipseProps } from './types';

export default class Ellipse extends Shape<{
cx?: NumberProp;
cy?: NumberProp;
rx?: NumberProp;
ry?: NumberProp;
}> {
export default class Ellipse extends Shape<EllipseProps> {
static displayName = 'Ellipse';

static defaultProps = {
Expand Down
9 changes: 2 additions & 7 deletions src/elements/ForeignObject.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React from 'react';
import { withoutXY } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import G from './G';
import { RNSVGForeignObject } from './NativeComponents';
import { ForeignObjectProps } from './types';

export default class ForeignObject extends G<{
x?: NumberProp;
y?: NumberProp;
width?: NumberProp;
height?: NumberProp;
}> {
export default class ForeignObject extends G<ForeignObjectProps> {
static displayName = 'ForeignObject';

static defaultProps = {
Expand Down
14 changes: 3 additions & 11 deletions src/elements/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import React from 'react';
import { Image, ImageSourcePropType } from 'react-native';
import { Image } from 'react-native';
import { alignEnum, meetOrSliceTypes } from '../lib/extract/extractViewBox';
import { withoutXY } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
import { RNSVGImage } from './NativeComponents';
import { ImageProps } from './types';

const spacesRegExp = /\s+/;

export default class SvgImage extends Shape<{
preserveAspectRatio?: string;
x?: NumberProp;
y?: NumberProp;
width?: NumberProp;
height?: NumberProp;
xlinkHref?: string | number | ImageSourcePropType;
href?: string | number | ImageSourcePropType;
}> {
export default class SvgImage extends Shape<ImageProps> {
static displayName = 'Image';

static defaultProps = {
Expand Down
9 changes: 2 additions & 7 deletions src/elements/Line.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React from 'react';
import { extract } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
import { RNSVGLine } from './NativeComponents';
import { LineProps } from './types';

export default class Line extends Shape<{
x1?: NumberProp;
y1?: NumberProp;
x2?: NumberProp;
y2?: NumberProp;
}> {
export default class Line extends Shape<LineProps> {
static displayName = 'Line';

static defaultProps = {
Expand Down
16 changes: 3 additions & 13 deletions src/elements/LinearGradient.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import React, { ReactElement } from 'react';
import React from 'react';
import extractGradient from '../lib/extract/extractGradient';
import { NumberProp, TransformProps } from '../lib/extract/types';
import Shape from './Shape';
import { RNSVGLinearGradient } from './NativeComponents';
import { LinearGradientProps } from './types';

export default class LinearGradient extends Shape<{
id?: string;
x1?: NumberProp;
y1?: NumberProp;
x2?: NumberProp;
y2?: NumberProp;
children?: ReactElement[];
transform?: number[] | string | TransformProps;
gradientTransform?: number[] | string | TransformProps;
gradientUnits?: 'objectBoundingBox' | 'userSpaceOnUse';
}> {
export default class LinearGradient extends Shape<LinearGradientProps> {
static displayName = 'LinearGradient';

static defaultProps = {
Expand Down
14 changes: 2 additions & 12 deletions src/elements/Marker.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import React from 'react';
import extractViewBox from '../lib/extract/extractViewBox';
import { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
import { RNSVGMarker } from './NativeComponents';
import { MarkerProps } from './types';

export default class Marker extends Shape<{
id?: string;
viewBox?: string;
preserveAspectRatio?: string;
refX?: NumberProp;
refY?: NumberProp;
markerWidth?: NumberProp;
markerHeight?: NumberProp;
markerUnits?: 'strokeWidth' | 'userSpaceOnUse';
orient?: 'auto' | 'auto-start-reverse' | NumberProp;
}> {
export default class Marker extends Shape<MarkerProps> {
static displayName = 'Marker';

static defaultProps = {
Expand Down
13 changes: 2 additions & 11 deletions src/elements/Mask.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import React from 'react';
import extractTransform from '../lib/extract/extractTransform';
import { withoutXY } from '../lib/extract/extractProps';
import { NumberProp, TransformProps } from '../lib/extract/types';
import units from '../lib/units';
import Shape from './Shape';
import { RNSVGMask } from './NativeComponents';
import { MaskProps } from './types';

export default class Mask extends Shape<{
x?: NumberProp;
y?: NumberProp;
width?: NumberProp;
height?: NumberProp;
transform?: number[] | string | TransformProps;
maskTransform?: number[] | string | TransformProps;
maskUnits?: 'objectBoundingBox' | 'userSpaceOnUse';
maskContentUnits?: 'objectBoundingBox' | 'userSpaceOnUse';
}> {
export default class Mask extends Shape<MaskProps> {
static displayName = 'Mask';

static defaultProps = {
Expand Down
5 changes: 2 additions & 3 deletions src/elements/Path.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import React from 'react';
import { extract } from '../lib/extract/extractProps';
import Shape from './Shape';
import { RNSVGPath } from './NativeComponents';
import { PathProps } from './types';

export default class Path extends Shape<{
d?: string;
}> {
export default class Path extends Shape<PathProps> {
static displayName = 'Path';

render() {
Expand Down
16 changes: 2 additions & 14 deletions src/elements/Pattern.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
import React from 'react';
import extractTransform from '../lib/extract/extractTransform';
import extractViewBox from '../lib/extract/extractViewBox';
import { NumberProp, TransformProps } from '../lib/extract/types';
import units from '../lib/units';
import Shape from './Shape';
import { RNSVGPattern } from './NativeComponents';
import { PatternProps } from './types';

export default class Pattern extends Shape<{
id?: string;
x?: NumberProp;
y?: NumberProp;
width?: NumberProp;
height?: NumberProp;
viewBox?: string;
preserveAspectRatio?: string;
transform?: number[] | string | TransformProps;
patternTransform?: number[] | string | TransformProps;
patternUnits?: 'objectBoundingBox' | 'userSpaceOnUse';
patternContentUnits?: 'objectBoundingBox' | 'userSpaceOnUse';
}> {
export default class Pattern extends Shape<PatternProps> {
static displayName = 'Pattern';

static defaultProps = {
Expand Down
3 changes: 2 additions & 1 deletion src/elements/Polygon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import Path from './Path';
import Shape from './Shape';
import { NumberProp } from '../lib/extract/types';
import extractPolyPoints from '../lib/extract/extractPolyPoints';
import { PolygonProps } from './types';

export default class Polygon extends Shape<{ points?: number[] }> {
export default class Polygon extends Shape<PolygonProps> {
static displayName = 'Polygon';

static defaultProps = {
Expand Down
3 changes: 2 additions & 1 deletion src/elements/Polyline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import Path from './Path';
import Shape from './Shape';
import { NumberProp } from '../lib/extract/types';
import extractPolyPoints from '../lib/extract/extractPolyPoints';
import { PolylineProps } from './types';

export default class Polyline extends Shape<{ points?: number[] }> {
export default class Polyline extends Shape<PolylineProps> {
static displayName = 'Polyline';

static defaultProps = {
Expand Down
19 changes: 3 additions & 16 deletions src/elements/RadialGradient.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import React, { ReactElement } from 'react';
import React from 'react';
import extractGradient from '../lib/extract/extractGradient';
import { NumberProp, TransformProps } from '../lib/extract/types';
import Shape from './Shape';
import { RNSVGRadialGradient } from './NativeComponents';
import { RadialGradientProps } from './types';

export default class RadialGradient extends Shape<{
fx?: NumberProp;
fy?: NumberProp;
rx?: NumberProp;
ry?: NumberProp;
r?: NumberProp;
cx?: NumberProp;
cy?: NumberProp;
id?: string;
children?: ReactElement[];
transform?: number[] | string | TransformProps;
gradientTransform?: number[] | string | TransformProps;
gradientUnits?: 'objectBoundingBox' | 'userSpaceOnUse';
}> {
export default class RadialGradient extends Shape<RadialGradientProps & {}> {
static displayName = 'RadialGradient';

static defaultProps = {
Expand Down
11 changes: 2 additions & 9 deletions src/elements/Rect.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import React from 'react';
import { withoutXY } from '../lib/extract/extractProps';
import { NumberProp } from '../lib/extract/types';
import Shape from './Shape';
import { RNSVGRect } from './NativeComponents';
import { RectProps } from './types';

export default class Rect extends Shape<{
x?: NumberProp;
y?: NumberProp;
width?: NumberProp;
height?: NumberProp;
rx?: NumberProp;
ry?: NumberProp;
}> {
export default class Rect extends Shape<RectProps> {
static displayName = 'Rect';

static defaultProps = {
Expand Down