Skip to content

Commit

Permalink
fix: restore bitmap recycling on children changes (#1864)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
WoLewicki authored Sep 14, 2022
1 parent 992cf19 commit f16a08f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
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

0 comments on commit f16a08f

Please sign in to comment.