Let SvgViewManager handle removing node and view references.

This commit is contained in:
Niko Rehnbäck
2018-09-18 16:09:52 +03:00
parent 2bde9c9c04
commit 2219317513
2 changed files with 13 additions and 13 deletions
@@ -78,12 +78,6 @@ public class SvgView extends ViewGroup {
SvgViewManager.setSvgView(this); SvgViewManager.setSvgView(this);
} }
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
SvgViewManager.dropSvgView(this);
}
@Override @Override
public void invalidate() { public void invalidate() {
super.invalidate(); super.invalidate();
@@ -97,7 +91,11 @@ public class SvgView extends ViewGroup {
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
if (mBitmap == null) { if (mBitmap == null) {
mBitmap = getShadowNode().drawOutput(); SvgViewShadowNode node = getShadowNode();
if (node == null) {
return;
}
mBitmap = node.drawOutput();
} }
canvas.drawBitmap(mBitmap, 0, 0, null); canvas.drawBitmap(mBitmap, 0, 0, null);
} }
@@ -50,12 +50,6 @@ class SvgViewManager extends ViewGroupManager<SvgView> {
mTagToSvgView.put(svg.getId(), svg); mTagToSvgView.put(svg.getId(), svg);
} }
static void dropSvgView(SvgView view) {
int tag = view.getId();
mTagToShadowNode.remove(tag);
mTagToSvgView.remove(tag);
}
@SuppressWarnings("unused") @SuppressWarnings("unused")
static @Nullable SvgView getSvgViewByTag(int tag) { static @Nullable SvgView getSvgViewByTag(int tag) {
return mTagToSvgView.get(tag); return mTagToSvgView.get(tag);
@@ -92,4 +86,12 @@ class SvgViewManager extends ViewGroupManager<SvgView> {
root.invalidate(); root.invalidate();
} }
@Override
public void onDropViewInstance(SvgView view) {
super.onDropViewInstance(view);
int tag = view.getId();
mTagToShadowNode.remove(tag);
mTagToSvgView.remove(tag);
}
} }