Skip to content

Commit

Permalink
Fixes for animation of width and height
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Oct 10, 2018
1 parent b13e164 commit e307eee
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 15 deletions.
20 changes: 15 additions & 5 deletions android/src/main/java/com/horcrux/svg/RectShadowNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;

import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.uimanager.annotations.ReactProp;

/**
Expand Down Expand Up @@ -41,15 +44,22 @@ public void setY(String y) {
}

@ReactProp(name = "rectwidth")
public void setWidth(String width) {
mW = width;
public void setWidth(Dynamic width) {
if (width.getType() == ReadableType.String) {
mW = width.asString();
} else {
mW = String.valueOf(width.asDouble());
}
markUpdated();
}


@ReactProp(name = "rectheight")
public void setHeight(String height) {
mH = height;
public void setHeight(Dynamic height) {
if (height.getType() == ReadableType.String) {
mH = height.asString();
} else {
mH = String.valueOf(height.asDouble());
}
markUpdated();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ public void setY(RenderableView<RectShadowNode> node, String y) {
}

@ReactProp(name = "rectwidth")
public void setWidth(RenderableView<RectShadowNode> node, String width) {
public void setWidth(RenderableView<RectShadowNode> node, Dynamic width) {
node.shadowNode.setWidth(width);
}


@ReactProp(name = "rectheight")
public void setHeight(RenderableView<RectShadowNode> node, String height) {
public void setHeight(RenderableView<RectShadowNode> node, Dynamic height) {
node.shadowNode.setHeight(height);
}

Expand Down
10 changes: 8 additions & 2 deletions elements/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ export default class extends Shape {
preserveAspectRatio: "xMidYMid meet",
};

setNativeProps = (...args) => {
this.root.setNativeProps(...args);
setNativeProps = (props) => {
if (props.width) {
props.imagewidth = `${props.width}`;
}
if (props.height) {
props.imageheight = `${props.height}`;
}
this.root.setNativeProps(props);
};

render() {
Expand Down
13 changes: 13 additions & 0 deletions elements/Mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ export default class extends Component {
]),
};

setNativeProps = (props) => {
if (props.width) {
props.maskwidth = `${props.width}`;
}
if (props.height) {
props.maskheight = `${props.height}`;
}
this.root.setNativeProps(props);
};

render() {
const { props } = this;
const {
Expand All @@ -48,6 +58,9 @@ export default class extends Component {

return (
<RNSVGMask
ref={ele => {
this.root = ele;
}}
name={id}
x={`${x}`}
y={`${y}`}
Expand Down
13 changes: 13 additions & 0 deletions elements/Pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export default class extends Component {
preserveAspectRatio: PropTypes.string,
};

setNativeProps = (props) => {
if (props.width) {
props.patternwidth = `${props.width}`;
}
if (props.height) {
props.patternheight = `${props.height}`;
}
this.root.setNativeProps(props);
};

render() {
const { props } = this;
const {
Expand Down Expand Up @@ -53,6 +63,9 @@ export default class extends Component {

return (
<RNSVGPattern
ref={ele => {
this.root = ele;
}}
name={id}
x={`${x}`}
y={`${y}`}
Expand Down
10 changes: 8 additions & 2 deletions elements/Rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ export default class extends Shape {
ry: 0
};

setNativeProps = (...args) => {
this.root.setNativeProps(...args);
setNativeProps = (props) => {
if (props.width) {
props.rectwidth = `${props.width}`;
}
if (props.height) {
props.rectheight = `${props.height}`;
}
this.root.setNativeProps(props);
};

render() {
Expand Down
10 changes: 8 additions & 2 deletions elements/Svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ class Svg extends Shape {
this.root.measureLayout(...args);
};

setNativeProps = (...args) => {
this.root.setNativeProps(...args);
setNativeProps = (props) => {
if (props.width) {
props.bbWidth = `${props.width}`;
}
if (props.height) {
props.bbHeight = `${props.height}`;
}
this.root.setNativeProps(props);
};

toDataURL = callback => {
Expand Down
10 changes: 8 additions & 2 deletions elements/Use.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ export default class extends Shape {
height: 0
};

setNativeProps = (...args) => {
this.root.setNativeProps(...args);
setNativeProps = (props) => {
if (props.width) {
props.usewidth = `${props.width}`;
}
if (props.height) {
props.useheight = `${props.height}`;
}
this.root.setNativeProps(props);
};

render() {
Expand Down

0 comments on commit e307eee

Please sign in to comment.