mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-04 23:54:53 +00:00
[android] Implement cache invalidation early exit shortcut
This commit is contained in:
@@ -125,7 +125,7 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
private boolean mRendered = false;
|
||||
int mTintColor = 0;
|
||||
|
||||
private void releaseCachedPath() {
|
||||
private void clearChildCache() {
|
||||
if (!mRendered) {
|
||||
return;
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
View node = getChildAt(i);
|
||||
if (node instanceof VirtualView) {
|
||||
VirtualView n = ((VirtualView)node);
|
||||
n.releaseCachedPath();
|
||||
n.clearChildCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,56 +152,56 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
public void setMinX(float minX) {
|
||||
mMinX = minX;
|
||||
invalidate();
|
||||
releaseCachedPath();
|
||||
clearChildCache();
|
||||
}
|
||||
|
||||
@ReactProp(name = "minY")
|
||||
public void setMinY(float minY) {
|
||||
mMinY = minY;
|
||||
invalidate();
|
||||
releaseCachedPath();
|
||||
clearChildCache();
|
||||
}
|
||||
|
||||
@ReactProp(name = "vbWidth")
|
||||
public void setVbWidth(float vbWidth) {
|
||||
mVbWidth = vbWidth;
|
||||
invalidate();
|
||||
releaseCachedPath();
|
||||
clearChildCache();
|
||||
}
|
||||
|
||||
@ReactProp(name = "vbHeight")
|
||||
public void setVbHeight(float vbHeight) {
|
||||
mVbHeight = vbHeight;
|
||||
invalidate();
|
||||
releaseCachedPath();
|
||||
clearChildCache();
|
||||
}
|
||||
|
||||
@ReactProp(name = "bbWidth")
|
||||
public void setVbWidth(String bbWidth) {
|
||||
mbbWidth = bbWidth;
|
||||
invalidate();
|
||||
releaseCachedPath();
|
||||
clearChildCache();
|
||||
}
|
||||
|
||||
@ReactProp(name = "bbHeight")
|
||||
public void setVbHeight(String bbHeight) {
|
||||
mbbHeight = bbHeight;
|
||||
invalidate();
|
||||
releaseCachedPath();
|
||||
clearChildCache();
|
||||
}
|
||||
|
||||
@ReactProp(name = "align")
|
||||
public void setAlign(String align) {
|
||||
mAlign = align;
|
||||
invalidate();
|
||||
releaseCachedPath();
|
||||
clearChildCache();
|
||||
}
|
||||
|
||||
@ReactProp(name = "meetOrSlice")
|
||||
public void setMeetOrSlice(int meetOrSlice) {
|
||||
mMeetOrSlice = meetOrSlice;
|
||||
invalidate();
|
||||
releaseCachedPath();
|
||||
clearChildCache();
|
||||
}
|
||||
|
||||
private Bitmap drawOutput() {
|
||||
|
||||
@@ -45,8 +45,11 @@ class TextView extends GroupView {
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
if (mPath == null) {
|
||||
return;
|
||||
}
|
||||
super.invalidate();
|
||||
releaseCachedPath();
|
||||
clearChildCache();
|
||||
}
|
||||
|
||||
@ReactProp(name = "textLength")
|
||||
|
||||
@@ -93,12 +93,15 @@ abstract public class VirtualView extends ReactViewGroup {
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
if (mPath == null) {
|
||||
return;
|
||||
}
|
||||
clearCache();
|
||||
clearParentCache();
|
||||
super.invalidate();
|
||||
clearPath();
|
||||
clearPathsUpToRoot();
|
||||
}
|
||||
|
||||
private void clearPath() {
|
||||
private void clearCache() {
|
||||
canvasDiagonal = -1;
|
||||
canvasHeight = -1;
|
||||
canvasWidth = -1;
|
||||
@@ -108,25 +111,28 @@ abstract public class VirtualView extends ReactViewGroup {
|
||||
mPath = null;
|
||||
}
|
||||
|
||||
void releaseCachedPath() {
|
||||
clearPath();
|
||||
void clearChildCache() {
|
||||
clearCache();
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View node = getChildAt(i);
|
||||
if (node instanceof VirtualView) {
|
||||
((VirtualView)node).releaseCachedPath();
|
||||
((VirtualView)node).clearChildCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clearPathsUpToRoot() {
|
||||
private void clearParentCache() {
|
||||
VirtualView node = this;
|
||||
while (true) {
|
||||
ViewParent parent = node.getParent();
|
||||
if (!(parent instanceof VirtualView)) {
|
||||
return;
|
||||
}
|
||||
node.clearPath();
|
||||
node = (VirtualView)parent;
|
||||
if (node.mPath == null) {
|
||||
return;
|
||||
}
|
||||
node.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +273,7 @@ abstract public class VirtualView extends ReactViewGroup {
|
||||
}
|
||||
|
||||
super.invalidate();
|
||||
clearPathsUpToRoot();
|
||||
clearParentCache();
|
||||
}
|
||||
|
||||
@ReactProp(name = "responsible")
|
||||
|
||||
Reference in New Issue
Block a user