Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore bitmap recycling on children changes #1864

Merged
merged 1 commit into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,6 @@ public void onChildViewAdded(View view, View view1) {
@Override
public void onChildViewRemoved(View view, View view1) {
if (view instanceof VirtualView) {
SvgView svgView = ((VirtualView) view).getSvgView();
if (svgView != null) {
svgView.setRemovedFromReactViewHierarchy();
}
invalidateSvgView((V) view);
}
}
Expand Down
13 changes: 7 additions & 6 deletions android/src/main/java/com/horcrux/svg/SvgView.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public String toString() {
}

private @Nullable Bitmap mBitmap;
private boolean mRemovedFromReactViewHierarchy;
private boolean mRemovalTransitionStarted;

public SvgView(ReactContext reactContext) {
super(reactContext);
Expand All @@ -74,10 +74,6 @@ public void setId(int id) {
SvgViewManager.setSvgView(id, this);
}

public void setRemovedFromReactViewHierarchy() {
mRemovedFromReactViewHierarchy = true;
}

@Override
public void invalidate() {
super.invalidate();
Expand All @@ -90,7 +86,7 @@ public void invalidate() {
((VirtualView) parent).getSvgView().invalidate();
return;
}
if (!mRemovedFromReactViewHierarchy) {
if (!mRemovalTransitionStarted) {
// when view is removed from the view hierarchy, we want to recycle the mBitmap when
// the view is detached from window, in order to preserve it for during animation, see
// https://github.com/react-native-svg/react-native-svg/pull/1542
Expand All @@ -101,6 +97,11 @@ public void invalidate() {
}
}

@Override
public void startViewTransition(View view) {
mRemovalTransitionStarted = true;
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
Expand Down