From 7055c52288c94f5ef87a59f4f421c925e59fb05c Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Thu, 25 Feb 2016 17:49:51 -0800 Subject: [PATCH] Fix screenshot tests for React with nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Fix screenshot tests for React with nodes. It was broken due to calling clipRect with bounds of [-∞, ∞], which, due to a bug in Canvas that appeared in screenshot tests, caused the view not to draw. Since this is a no-op anyway, this patch just doesn't call clipRect when we have infinite bounds. Differential Revision: D2975494 --- .../facebook/react/flat/AbstractClippingDrawCommand.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/AbstractClippingDrawCommand.java b/ReactAndroid/src/main/java/com/facebook/react/flat/AbstractClippingDrawCommand.java index 3ac0391c8..2919b52e9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/AbstractClippingDrawCommand.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/AbstractClippingDrawCommand.java @@ -55,6 +55,13 @@ import android.graphics.Canvas; } protected final void applyClipping(Canvas canvas) { - canvas.clipRect(mClipLeft, mClipTop, mClipRight, mClipBottom); + // We put this check here to not clip when we have the default [-infinity, infinity] bounds, + // since clipRect in those cases is essentially no-op anyway. This is needed to fix a bug that + // shows up during screenshot testing. Note that checking one side is enough, since if one side + // is infinite, all sides will be infinite, since we only set infinite for all sides at the + // same time - conversely, if one side is finite, all sides will be finite. + if (mClipLeft != Float.NEGATIVE_INFINITY) { + canvas.clipRect(mClipLeft, mClipTop, mClipRight, mClipBottom); + } } }