From 5f4390bf0364a79804747270733f8bab33b7a5c3 Mon Sep 17 00:00:00 2001 From: Krzysztof Magiera Date: Wed, 3 Feb 2016 03:30:23 -0800 Subject: [PATCH] Fix bug related to removeClippedSubviews and view collapsing. Summary: The bug occurs for the cases when there is a nested view structure of at least two views with removeClippedSubvews enabled and with a "collapsable" view in between them that migrates from the collapsed state to non-collapsed state. What happens in that case is that the "inner" view with "removeClippsedSubviews" gets reattached to a new parent, but we never update it's clipping rect because the update is currently only triggered for the size change (and for scroll change in case of scrollview). In the case when the view was doing some "clipping" when attached to its previous parent it needs to update its "clipping" status because the parent has change and clipping rect is calculated based on the parent clipping rect (see `ReactClippingViewGroupHelper#calculateClippingRect`). This change triggers `updateClippingRect` when the view is attached to the window, which covers the case when it's reattached from one parent to the other. Closes https://github.com/facebook/react-native/pull/5692 Reviewed By: svcscm Differential Revision: D2893304 Pulled By: foghina fb-gh-sync-id: a94ab3674adf9e496fc86dca5a430a91117f2c83 --- .../views/scroll/ReactHorizontalScrollView.java | 8 ++++++++ .../facebook/react/views/scroll/ReactScrollView.java | 8 ++++++++ .../facebook/react/views/view/ReactViewGroup.java | 12 +++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java index c8bdc978a8e..61735c0ea9b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java @@ -146,6 +146,14 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements } } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + if (mRemoveClippedSubviews) { + updateClippingRect(); + } + } + @Override public void updateClippingRect() { if (!mRemoveClippedSubviews) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java index a6a813db9f9..64559d1a35b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java @@ -72,6 +72,14 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou } } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + if (mRemoveClippedSubviews) { + updateClippingRect(); + } + } + @Override protected void onScrollChanged(int x, int y, int oldX, int oldY) { super.onScrollChanged(x, y, oldX, oldY); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java index b52399c82f3..88ac9339785 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java @@ -353,7 +353,17 @@ public class ReactViewGroup extends ViewGroup implements @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); - updateClippingRect(); + if (mRemoveClippedSubviews) { + updateClippingRect(); + } + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + if (mRemoveClippedSubviews) { + updateClippingRect(); + } } @Override