diff --git a/package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java b/package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java index 0aeedd4442..f8a542734d 100644 --- a/package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +++ b/package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java @@ -13,6 +13,8 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView private String tag = "SkiaView"; + private boolean isDropped = false; + public SkiaBaseView(Context context) { super(context); mTexture = new TextureView(context); @@ -21,11 +23,6 @@ public SkiaBaseView(Context context) { addView(mTexture); } - public void destroySurface() { - Log.i(tag, "destroySurface"); - surfaceDestroyed(); - } - private void createSurfaceTexture() { // This API Level is >= 26, we created our own SurfaceTexture to have a faster time to first frame if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { @@ -36,6 +33,11 @@ private void createSurfaceTexture() { } } + void dropInstance() { + isDropped = true; + unregisterView(); + } + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); @@ -129,6 +131,9 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei @Override public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { + if (isDropped) { + return; + } Log.i(tag, "onSurfaceTextureSizeChanged " + width + "/" + height); surfaceSizeChanged(width, height); } @@ -137,12 +142,14 @@ public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int h public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { Log.i(tag, "onSurfaceTextureDestroyed"); // https://developer.android.com/reference/android/view/TextureView.SurfaceTextureListener#onSurfaceTextureDestroyed(android.graphics.SurfaceTexture) - destroySurface(); + surfaceDestroyed(); // Because of React Native Screens (which dettach the view), we always keep the surface alive. // If not, Texture view will recreate the texture surface by itself and // we will lose the fast first time to frame. // We only delete the surface when the view is dropped (destroySurface invoked by SkiaBaseViewManager); - createSurfaceTexture(); + if (!isDropped) { + createSurfaceTexture(); + } return false; } diff --git a/package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java b/package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java index 11a1cbf6bf..4317de650a 100644 --- a/package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +++ b/package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java @@ -29,7 +29,6 @@ public void setDebug(T view, boolean show) { @Override public void onDropViewInstance(@NonNull ReactViewGroup view) { super.onDropViewInstance(view); - ((SkiaBaseView)view).destroySurface(); - ((SkiaBaseView)view).unregisterView(); + ((SkiaBaseView)view).dropInstance(); } } \ No newline at end of file