Skip to content

Commit

Permalink
fix: scale path markers so they match ios (#2018)
Browse files Browse the repository at this point in the history
PR adding scaling of markers of path in order to make them behave the same as on iOS. Also bumped the versions of agp and spotless.
  • Loading branch information
WoLewicki authored Mar 30, 2023
1 parent a7af70c commit 29382d9
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 37 deletions.
77 changes: 68 additions & 9 deletions Example/src/examples/Markers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
Ellipse,
Line,
Polygon,
Path,
} from 'react-native-svg';

class CircleExample extends Component {
class EllipseExample extends Component {
static title = 'Circle shaped marker on ellipse';
render() {
return (
Expand Down Expand Up @@ -47,7 +48,7 @@ class CircleExample extends Component {
}
}

class StrokeCircle extends Component {
class LineExample extends Component {
static title = 'Triangle shaped marker on line';
render() {
return (
Expand Down Expand Up @@ -81,7 +82,7 @@ class StrokeCircle extends Component {
}
}

class StrokeOpacityCircle extends Component {
class CircleExample extends Component {
static title = 'Rect shaped marker on circle';
render() {
return (
Expand Down Expand Up @@ -111,15 +112,15 @@ class StrokeOpacityCircle extends Component {
}
}

class PieCircle extends Component {
class RectExample extends Component {
static title = 'Ellipse shaped marker on rect';
render() {
return (
<Svg width="400" height="200" viewBox="0 0 100 100">
<Defs>
<Marker
id="selection"
markerUnits="userSpaceOnUse"
markerUnits="strokeWidth"
refX="0"
refY="0"
orient="auto">
Expand All @@ -141,19 +142,77 @@ class PieCircle extends Component {
height="30"
fill="none"
stroke="blue"
strokeWidth="5"
strokeWidth="1"
marker="url(#selection)"
/>
</Svg>
);
}
}

class PathExample extends Component {
static title = 'Path shaped marker on line';
render() {
return (
<Svg height="200" width="400" viewBox="0 0 300 100">
<Defs>
<Marker
id="arrow"
// viewBox="0 0 10 10"
refX="5"
refY="5"
markerWidth="6"
markerHeight="6"
// orient="auto-start-reverse"
>
<Path fill="blue" d="M 0 0 L 10 5 L 0 10 z" />
</Marker>
</Defs>
<Line
x1="10"
y1="10"
x2="90"
y2="90"
stroke="black"
strokeWidth="3"
markerEnd="url(#arrow)"
/>
</Svg>
);
}
}

const icon = (
<Svg height="30" width="30" viewBox="0 0 20 20">
<Circle cx="10" cy="10" r="8" stroke="purple" strokeWidth="1" fill="pink" />
<Svg height="30" width="30" viewBox="0 0 3000 2500">
<Defs>
<Marker
id="Triangle"
// viewBox="0 0 10 10"
refX="0"
refY="5"
markerUnits="strokeWidth"
markerWidth="4"
markerHeight="3"
orient="auto">
<Path fill="blue" d="M 0 0 L 10 5 L 0 10 z" />
</Marker>
</Defs>
<Path
d="M 1000 750 L 2000 750 L 2500 1250"
fill="none"
stroke="black"
strokeWidth="70"
markerEnd="url(#Triangle)"
markerStart="url(#Triangle)"
/>
</Svg>
);

const samples = [CircleExample, StrokeCircle, StrokeOpacityCircle, PieCircle];
const samples = [
EllipseExample,
LineExample,
CircleExample,
RectExample,
PathExample,
];
export {icon, samples};
1 change: 1 addition & 0 deletions FabricExample/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const names: (keyof typeof examples)[] = [
'PanResponder',
'Reusable',
'Transforms',
'Markers',
];

const initialState = {
Expand Down
2 changes: 2 additions & 0 deletions FabricExample/src/examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as Reusable from './examples/Reusable';
import * as TouchEvents from './examples/TouchEvents';
import * as PanResponder from './examples/PanResponder';
import * as Transforms from './examples/Transforms';
import * as Markers from './examples/Markers';

export {
Svg,
Expand All @@ -36,4 +37,5 @@ export {
Reusable,
PanResponder,
Transforms,
Markers,
};
218 changes: 218 additions & 0 deletions FabricExample/src/examples/Markers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
import React, {Component} from 'react';
import {
Svg,
Circle,
Defs,
Marker,
Rect,
Ellipse,
Line,
Polygon,
Path,
} from 'react-native-svg';

class EllipseExample extends Component {
static title = 'Circle shaped marker on ellipse';
render() {
return (
<Svg height="300" width="400">
<Defs>
<Marker
id="selection"
markerUnits="userSpaceOnUse"
refX="0"
refY="0"
orient="auto">
<Circle
fill="#3a6cff"
r={5}
cx={0}
cy={0}
strokeWidth={1}
stroke="white"
/>
</Marker>
</Defs>
<Ellipse
cx="200"
cy="170"
rx="30%"
ry="10%"
stroke="purple"
strokeWidth="2"
fill="yellow"
marker="url(#selection)"
/>
</Svg>
);
}
}

class LineExample extends Component {
static title = 'Triangle shaped marker on line';
render() {
return (
<Svg height="200" width="200">
<Defs>
<Marker
id="selection"
markerUnits="userSpaceOnUse"
refX="0"
refY="0"
orient="auto">
<Polygon
points="0,0 -5,20 10,30"
fill="lime"
stroke="purple"
strokeWidth="1"
/>
</Marker>
</Defs>
<Line
x1="20"
y1="10%"
x2="60%"
y2="60%"
stroke="red"
strokeWidth="2"
marker="url(#selection)"
/>
</Svg>
);
}
}

class CircleExample extends Component {
static title = 'Rect shaped marker on circle';
render() {
return (
<Svg height="150" width="200">
<Defs>
<Marker
id="selection"
markerUnits="userSpaceOnUse"
refX="0"
refY="0"
orient="auto">
<Rect x="0" y="0" width="15" height="15" fill="rgb(0,0,255)" />
</Marker>
</Defs>
<Circle
cx="70"
cy="70"
r="30%"
stroke="purple"
strokeOpacity="0.5"
strokeWidth="10"
fill="pink"
marker="url(#selection)"
/>
</Svg>
);
}
}

class RectExample extends Component {
static title = 'Ellipse shaped marker on rect';
render() {
return (
<Svg width="400" height="200" viewBox="0 0 100 100">
<Defs>
<Marker
id="selection"
markerUnits="strokeWidth"
refX="0"
refY="0"
orient="auto">
<Ellipse
fill="#3a6cff"
rx={5}
ry={8}
cx={0}
cy={0}
strokeWidth={1}
stroke="white"
/>
</Marker>
</Defs>
<Rect
x="50%"
y="50"
width="30"
height="30"
fill="none"
stroke="blue"
strokeWidth="1"
marker="url(#selection)"
/>
</Svg>
);
}
}

class PathExample extends Component {
static title = 'Path shaped marker on line';
render() {
return (
<Svg height="200" width="400" viewBox="0 0 300 100">
<Defs>
<Marker
id="arrow"
// viewBox="0 0 10 10"
refX="5"
refY="5"
markerWidth="6"
markerHeight="6"
// orient="auto-start-reverse"
>
<Path fill="blue" d="M 0 0 L 10 5 L 0 10 z" />
</Marker>
</Defs>
<Line
x1="10"
y1="10"
x2="90"
y2="90"
stroke="black"
strokeWidth="3"
markerEnd="url(#arrow)"
/>
</Svg>
);
}
}

const icon = (
<Svg height="30" width="30" viewBox="0 0 3000 2500">
<Defs>
<Marker
id="Triangle"
// viewBox="0 0 10 10"
refX="0"
refY="5"
markerUnits="strokeWidth"
markerWidth="4"
markerHeight="3"
orient="auto">
<Path fill="blue" d="M 0 0 L 10 5 L 0 10 z" />
</Marker>
</Defs>
<Path
d="M 1000 750 L 2000 750 L 2500 1250"
fill="none"
stroke="black"
strokeWidth="70"
markerEnd="url(#Triangle)"
markerStart="url(#Triangle)"
/>
</Svg>
);

const samples = [
EllipseExample,
LineExample,
CircleExample,
RectExample,
PathExample,
];
export {icon, samples};
Loading

0 comments on commit 29382d9

Please sign in to comment.