From a8cb7e6eb09f6cbabe700a7d9dd8fb567d9b14b6 Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Fri, 9 Sep 2022 15:07:12 +0200 Subject: [PATCH] fix: restore bitmap recycling on children changes --- .../java/com/horcrux/svg/RenderableViewManager.java | 4 ---- android/src/main/java/com/horcrux/svg/SvgView.java | 13 +++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/android/src/main/java/com/horcrux/svg/RenderableViewManager.java b/android/src/main/java/com/horcrux/svg/RenderableViewManager.java index 7abb7d653..b08999518 100644 --- a/android/src/main/java/com/horcrux/svg/RenderableViewManager.java +++ b/android/src/main/java/com/horcrux/svg/RenderableViewManager.java @@ -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); } } diff --git a/android/src/main/java/com/horcrux/svg/SvgView.java b/android/src/main/java/com/horcrux/svg/SvgView.java index bb4e1bb7f..312719c3c 100644 --- a/android/src/main/java/com/horcrux/svg/SvgView.java +++ b/android/src/main/java/com/horcrux/svg/SvgView.java @@ -59,7 +59,7 @@ public String toString() { } private @Nullable Bitmap mBitmap; - private boolean mRemovedFromReactViewHierarchy; + private boolean mRemovalTransitionStarted; public SvgView(ReactContext reactContext) { super(reactContext); @@ -74,10 +74,6 @@ public void setId(int id) { SvgViewManager.setSvgView(id, this); } - public void setRemovedFromReactViewHierarchy() { - mRemovedFromReactViewHierarchy = true; - } - @Override public void invalidate() { super.invalidate(); @@ -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 @@ -101,6 +97,11 @@ public void invalidate() { } } + @Override + public void startViewTransition(View view) { + mRemovalTransitionStarted = true; + } + @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow();