Skip to content

Commit

Permalink
Add setNativeProps method for most of elements
Browse files Browse the repository at this point in the history
  • Loading branch information
magicismight committed Jul 18, 2016
1 parent 2516a77 commit efa7363
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Example/examples/G.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import Svg, {
Circle,
Line,
Rect,
Text
Text,
Use
} from 'react-native-svg';

class GExample extends Component{
Expand Down Expand Up @@ -63,6 +64,7 @@ class GTransform extends Component{
<G
rotate="50"
origin="100, 50"
id="group"
>
<Line
x1="60"
Expand Down Expand Up @@ -90,6 +92,7 @@ class GTransform extends Component{
>
Text grouped with shapes</Text>
</G>
<Use href="#group" x="5" rotate="0" />
</Svg>;
}
}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ npm install
2. more Text features support
3. Pattern element
4. implement Animated elements
5. refactor defs element (cannot use id prop for shape elements)

#### Thanks:

Expand Down
5 changes: 5 additions & 0 deletions elements/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ class Circle extends Shape {
svgId: numberProp
};

setNativeProps = (...args) => {
this.root.setNativeProps(...args);
};

render() {
let props = mergeContext(this.props, this.context);
return <RNSVGCircle
ref={ele => this.root = ele}
{...this.extractProps(props)}
cx={props.cx.toString()}
cy={props.cy.toString()}
Expand Down
5 changes: 5 additions & 0 deletions elements/Ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ class Ellipse extends Shape{
svgId: numberProp
};

setNativeProps = (...args) => {
this.root.setNativeProps(...args);
};

render() {
let props = mergeContext(this.props, this.context);
return <RNSVGEllipse
ref={ele => this.root = ele}
{...this.extractProps(props)}
cx={props.cx.toString()}
cy={props.cy.toString()}
Expand Down
10 changes: 10 additions & 0 deletions elements/G.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class G extends Component{
return _.defaults({}, this.context, context);
};

setNativeProps = (...args) => {
this.getNativeElement().setNativeProps(...args);
};

getNativeElement = () => {
return this.refs.root || this.root;
};

render() {
if (this.props.id) {
return <Defs.Item
Expand All @@ -42,12 +50,14 @@ class G extends Component{
>
<G
{...this.props}
ref={ele => this.root = ele.refs.root}
id={null}
/>
</Defs.Item>;
} else {
return <RNSVGGroup
{...extractProps(this.props, {transform: true})}
ref="root"
asClipPath={this.props.asClipPath}
>
{this.props.children}
Expand Down
4 changes: 4 additions & 0 deletions elements/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ class Image extends Shape {
//preserveAspectRatio: PropTypes.string
};

setNativeProps = (...args) => {
this.root.setNativeProps(...args);
};

render() {
let {props} = this;
return <RNSVGImage
ref={ele => this.root = ele}
{...this.extractProps(props, {transform: true, responder: true})}
x={props.x.toString()}
y={props.y.toString()}
Expand Down
5 changes: 5 additions & 0 deletions elements/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ class Line extends Shape {
svgId: numberProp
};

setNativeProps = (...args) => {
this.root.setNativeProps(...args);
};

render() {
let props = mergeContext(this.props, this.context);
return <RNSVGLine
ref={ele => this.root = ele}
{...this.extractProps(props)}
x1={props.x1.toString()}
y1={props.y1.toString()}
Expand Down
15 changes: 14 additions & 1 deletion elements/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ class Path extends Shape {
}
};

setNativeProps = (...args) => {
this.getNativeElement().setNativeProps(...args);
};

getNativeElement = () => {
return this.refs.root || this.root;
};

render() {
let props = mergeContext(this.props, this.context);

Expand All @@ -39,13 +47,18 @@ class Path extends Shape {
svgId={props.svgId}
visible={true}
>
<Path {...props} id={null} />
<Path
ref={ele => this.root = ele.refs.root}
{...props}
id={null}
/>
</Defs.Item>;
}

let d = new SerializablePath(props.d).toJSON();
return (
<RNSVGPath
ref="root"
{...this.extractProps(props)}
d={d}
/>
Expand Down
5 changes: 5 additions & 0 deletions elements/Polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ class Polygon extends Component{
points: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
};

setNativeProps = (...args) => {
this.root.getNativeElement().setNativeProps(...args);
};

render() {
return <Path
ref={ele => this.root = ele}
{...this.props}
d={`M${this.props.points.trim().replace(/\s+/g, 'L')}z`}
/>;
Expand Down
5 changes: 5 additions & 0 deletions elements/Polyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ class Polyline extends Component{
points: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
};

setNativeProps = (...args) => {
this.root.getNativeElement().setNativeProps(...args);
};

render() {
return <Path
ref={ele => this.root = ele}
{...this.props}
d={`M${this.props.points.trim().replace(/\s+/g, 'L')}`}
/>;
Expand Down
5 changes: 5 additions & 0 deletions elements/Rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ class Rect extends Shape {
svgId: numberProp
};

setNativeProps = (...args) => {
this.root.setNativeProps(...args);
};

render() {
let props = mergeContext(this.props, this.context);

return <RNSVGRect
ref={ele => this.root = ele}
{...this.extractProps({
...props,
x: null,
Expand Down
10 changes: 10 additions & 0 deletions elements/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class Text extends Shape {
svgId: numberProp
};

setNativeProps = (...args) => {
this.getNativeElement().setNativeProps(...args);
};

getNativeElement = () => {
return this.refs.root || this.root;
};

render() {
let props = mergeContext(this.props, this.context);

Expand All @@ -39,6 +47,7 @@ class Text extends Shape {

if (this.props.id) {
return <Defs.Item
ref={ele => this.root = ele.refs.root}
id={this.props.id}
svgId={this.props.svgId}
visible={true}
Expand All @@ -50,6 +59,7 @@ class Text extends Shape {

return (
<RNSVGText
ref="root"
{...extractProps({...props, x, y})}
{...extractText(props)}
/>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.1.0",
"version": "3.1.1",
"name": "react-native-svg",
"description": "react native svg library",
"repository": {
Expand Down

0 comments on commit efa7363

Please sign in to comment.