From 8564fc074b7ff270edd02032e7e317b1615987e4 Mon Sep 17 00:00:00 2001 From: Seth Kirby Date: Wed, 20 Jul 2016 23:27:34 -0700 Subject: [PATCH] Temporary low risk workaround for killing image network requests in rnfeed. Summary: View the comment thread for discussion: https://www.facebook.com/groups/1505872839725322/permalink/1630102823968989 Our current behaviour of add then immediately remove if a view is clipped pretty much guarantees that we kill network requests for images in feed. We have a better fix for that in the pipeline, but this is a low risk fix in the meantime. Reviewed By: ahmedre Differential Revision: D3597785 --- .../java/com/facebook/react/flat/FlatViewGroup.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java index 772709715..0b194195e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java @@ -416,7 +416,11 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper; @Override protected void onDetachedFromWindow() { if (!mIsAttached) { - throw new RuntimeException("Double detach"); + // Hack. Our current behaviour of add then immediately remove if a view is clipped pretty + // much guarantees that we kill network requests for images in feed. We have a fix, but are + // going to add it in master and patch this in in the meantime. + return; + // throw new RuntimeException("Double detach"); } mIsAttached = false; @@ -877,18 +881,17 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper; // Now off the screen. Don't invalidate in this case, as the canvas should not be // redrawn unless new elements are coming onscreen. mClippedSubviews.put(view.getId(), view); - removeViewsInLayout(--index, 1); + detachViewFromParent(--index); drawView.isViewGroupClipped = true; } } else { // Clipped, invisible. if (withinBounds(view, clippingRect)) { // Now on the screen. Invalidate as we have a new element to draw. - addViewInLayout( + attachViewToParent( view, index++, - ensureLayoutParams(view.getLayoutParams()), - true); + ensureLayoutParams(view.getLayoutParams())); mClippedSubviews.remove(view.getId()); drawView.isViewGroupClipped = false; needsInvalidate = true;