From f16a08f40f7ebc76bb5e4ade63e23de315e7088e Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Wed, 14 Sep 2022 11:03:48 +0200 Subject: [PATCH] fix: restore bitmap recycling on children changes (#1864) PR fixing the regression introduced in #1844. In that PR we set mRemovedFromReactViewHierarchy after one of SvgView's children has been removed, resulting in not being able to update it after one of the components in its hierarchy has been removed. In this PR the behavior has been changed, now we subscribe to startViewTransition which should be called only by react-native-screens when the screen starts its removal animation. It should still work for old issues as well as the new ones. --- .../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();