mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-04 07:25:53 +00:00
Clear cached data in tree when changing properties on root svg element.
Fixes staleness issues when changing width and height.
This commit is contained in:
@@ -53,58 +53,82 @@ public class SvgViewShadowNode extends LayoutShadowNode {
|
||||
private int mMeetOrSlice;
|
||||
private Matrix mInvViewBoxMatrix = new Matrix();
|
||||
private boolean mInvertible = true;
|
||||
private boolean mRendered = false;
|
||||
|
||||
|
||||
public SvgViewShadowNode() {
|
||||
mScale = DisplayMetricsHolder.getScreenDisplayMetrics().density;
|
||||
}
|
||||
|
||||
private void releaseCachedPath() {
|
||||
if (!mRendered) {
|
||||
return;
|
||||
}
|
||||
mRendered = false;
|
||||
traverseChildren(new VirtualNode.NodeRunnable() {
|
||||
public void run(ReactShadowNode node) {
|
||||
if (node instanceof VirtualNode) {
|
||||
VirtualNode n = ((VirtualNode)node);
|
||||
n.releaseCachedPath();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ReactProp(name = "minX")
|
||||
public void setMinX(float minX) {
|
||||
mMinX = minX;
|
||||
markUpdated();
|
||||
releaseCachedPath();
|
||||
}
|
||||
|
||||
@ReactProp(name = "minY")
|
||||
public void setMinY(float minY) {
|
||||
mMinY = minY;
|
||||
markUpdated();
|
||||
releaseCachedPath();
|
||||
}
|
||||
|
||||
@ReactProp(name = "vbWidth")
|
||||
public void setVbWidth(float vbWidth) {
|
||||
mVbWidth = vbWidth;
|
||||
markUpdated();
|
||||
releaseCachedPath();
|
||||
}
|
||||
|
||||
@ReactProp(name = "vbHeight")
|
||||
public void setVbHeight(float vbHeight) {
|
||||
mVbHeight = vbHeight;
|
||||
markUpdated();
|
||||
releaseCachedPath();
|
||||
}
|
||||
|
||||
@ReactProp(name = "bbWidth")
|
||||
public void setVbWidth(String bbWidth) {
|
||||
mbbWidth = bbWidth;
|
||||
markUpdated();
|
||||
releaseCachedPath();
|
||||
}
|
||||
|
||||
@ReactProp(name = "bbHeight")
|
||||
public void setVbHeight(String bbHeight) {
|
||||
mbbHeight = bbHeight;
|
||||
markUpdated();
|
||||
releaseCachedPath();
|
||||
}
|
||||
|
||||
@ReactProp(name = "align")
|
||||
public void setAlign(String align) {
|
||||
mAlign = align;
|
||||
markUpdated();
|
||||
releaseCachedPath();
|
||||
}
|
||||
|
||||
@ReactProp(name = "meetOrSlice")
|
||||
public void setMeetOrSlice(int meetOrSlice) {
|
||||
mMeetOrSlice = meetOrSlice;
|
||||
markUpdated();
|
||||
releaseCachedPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,6 +154,7 @@ public class SvgViewShadowNode extends LayoutShadowNode {
|
||||
}
|
||||
|
||||
Bitmap drawOutput() {
|
||||
mRendered = true;
|
||||
float width = getLayoutWidth();
|
||||
float height = getLayoutHeight();
|
||||
boolean early = Float.isNaN(width) || Float.isNaN(height) || width * height == 0 || (Math.log10(width) + Math.log10(height) > 42);
|
||||
|
||||
@@ -185,16 +185,6 @@ class TextShadowNode extends GroupShadowNode {
|
||||
return mBaselineShift;
|
||||
}
|
||||
|
||||
void releaseCachedPath() {
|
||||
traverseChildren(new NodeRunnable() {
|
||||
public void run(ReactShadowNode node) {
|
||||
if (node instanceof TextShadowNode) {
|
||||
((TextShadowNode)node).releaseCachedPath();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Path getGroupPath(Canvas canvas, Paint paint) {
|
||||
pushGlyphContext();
|
||||
Path groupPath = super.getPath(canvas, paint);
|
||||
|
||||
@@ -56,7 +56,7 @@ abstract class VirtualNode extends LayoutShadowNode {
|
||||
Matrix mMatrix = new Matrix();
|
||||
Matrix mInvMatrix = new Matrix();
|
||||
boolean mInvertible = true;
|
||||
RectF mClientRect;
|
||||
private RectF mClientRect;
|
||||
|
||||
private int mClipRule;
|
||||
private @Nullable String mClipPath;
|
||||
@@ -99,6 +99,10 @@ abstract class VirtualNode extends LayoutShadowNode {
|
||||
@Override
|
||||
public void markUpdated() {
|
||||
super.markUpdated();
|
||||
clearPath();
|
||||
}
|
||||
|
||||
private void clearPath() {
|
||||
canvasHeight = -1;
|
||||
canvasWidth = -1;
|
||||
mRegion = null;
|
||||
@@ -106,6 +110,17 @@ abstract class VirtualNode extends LayoutShadowNode {
|
||||
mBox = null;
|
||||
}
|
||||
|
||||
void releaseCachedPath() {
|
||||
clearPath();
|
||||
traverseChildren(new NodeRunnable() {
|
||||
public void run(ReactShadowNode node) {
|
||||
if (node instanceof VirtualNode) {
|
||||
((VirtualNode)node).releaseCachedPath();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
GroupShadowNode getTextRoot() {
|
||||
VirtualNode node = this;
|
||||
@@ -156,7 +171,7 @@ abstract class VirtualNode extends LayoutShadowNode {
|
||||
public abstract void draw(Canvas canvas, Paint paint, float opacity);
|
||||
public void render(Canvas canvas, Paint paint, float opacity) {
|
||||
draw(canvas, paint, opacity);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the transform matrix on the canvas before an element is drawn.
|
||||
|
||||
Reference in New Issue
Block a user