Skip to content

Commit

Permalink
[andriod] invalidate SvgView when view hierarchy changes
Browse files Browse the repository at this point in the history
  • Loading branch information
InJung Chung authored and msand committed Dec 7, 2018
1 parent 69e9fcd commit b896714
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions android/src/main/java/com/horcrux/svg/RenderableViewManager.java
Expand Up @@ -11,6 +11,7 @@

import android.graphics.Matrix;
import android.view.View;
import android.view.ViewGroup;

import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.Dynamic;
Expand Down Expand Up @@ -1012,6 +1013,33 @@ public void setName(VirtualView node, String name) {
node.setName(name);
}

private void invalidateSvgView(VirtualView node) {
SvgView view = node.getSvgView();
if (view!= null) {
view.invalidate();
}
}

@Override
protected void addEventEmitters(ThemedReactContext reactContext, VirtualView view) {
super.addEventEmitters(reactContext, view);
view.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
@Override
public void onChildViewAdded(View view, View view1) {
if (view instanceof VirtualView) {
invalidateSvgView((VirtualView) view);
}
}

@Override
public void onChildViewRemoved(View view, View view1) {
if (view instanceof VirtualView) {
invalidateSvgView((VirtualView) view);
}
}
});
}

/**
* Callback that will be triggered after all properties are updated in current update transaction
* (all @ReactProp handlers for properties updated in current transaction have been called). If
Expand All @@ -1021,11 +1049,7 @@ public void setName(VirtualView node, String name) {
@Override
protected void onAfterUpdateTransaction(VirtualView node) {
super.onAfterUpdateTransaction(node);
SvgView view = node.getSvgView();
if (view == null) {
return;
}
view.invalidate();
invalidateSvgView(node);
}

@Override
Expand Down

0 comments on commit b896714

Please sign in to comment.