mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-23 19:25:54 +00:00
fix: bitmap nulled before screen transition (#1844)
This PR fixes the issues in `react-native-screens` and probably other libraries using native `Fragments` for transitions on Android (see https://github.com/software-mansion/react-native-screens/issues/773). It moves the recycling and setting `mBitMap` to `null` to `onDetachedFromWindow` when the view is removed from `react` view hierarchy. `invalidate` is not always the proper place for doing it since the native view can still be visible for the user after the `invalidate` is called (see this comment with video: https://github.com/software-mansion/react-native-screens/issues/773#issuecomment-769418173).
This commit is contained in:
@@ -530,6 +530,10 @@ class VirtualViewManager<V extends VirtualView> extends ViewGroupManager<Virtual
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ public class SvgView extends FabricEnabledViewGroup
|
||||
}
|
||||
|
||||
private @Nullable Bitmap mBitmap;
|
||||
private boolean mRemovedFromReactViewHierarchy;
|
||||
|
||||
public SvgView(ReactContext reactContext) {
|
||||
super(reactContext);
|
||||
@@ -73,6 +74,10 @@ public class SvgView extends FabricEnabledViewGroup
|
||||
SvgViewManager.setSvgView(id, this);
|
||||
}
|
||||
|
||||
public void setRemovedFromReactViewHierarchy() {
|
||||
mRemovedFromReactViewHierarchy = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
@@ -85,6 +90,20 @@ public class SvgView extends FabricEnabledViewGroup
|
||||
((VirtualView) parent).getSvgView().invalidate();
|
||||
return;
|
||||
}
|
||||
if (!mRemovedFromReactViewHierarchy) {
|
||||
// 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
|
||||
if (mBitmap != null) {
|
||||
mBitmap.recycle();
|
||||
}
|
||||
mBitmap = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
if (mBitmap != null) {
|
||||
mBitmap.recycle();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user