From c2a55baf80c99df84c3a3d99ec58696ab2141e27 Mon Sep 17 00:00:00 2001 From: Andrew Jack Date: Tue, 15 Nov 2016 09:13:31 -0800 Subject: [PATCH] Prevent hitslop crash on Android Summary: **Motivation** Currently to use the `hitSlop` property on Android you must define the object properties `left`, `top`, `right`, and `bottom` or it will crash. iOS allows omitting object properties from the hitSlop. This change guards and allows the `hitSlop` object properties to be optional like iOS. **Test plan (required)** Run the [example](https://github.com/facebook/react-native/blob/f930270b005953bb7083190eef60d050e4de7607/Examples/UIExplorer/js/TouchableExample.js#L318) and omit a hitslop property and check it does not crash. Closes https://github.com/facebook/react-native/pull/10952 Differential Revision: D4182815 Pulled By: ericvicenti fbshipit-source-id: 07d7aca67b5739d5d1939b257476c24dcb10cbb0 --- .../com/facebook/react/views/view/ReactViewManager.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java index 3655e898a..a04ea4839 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java @@ -81,10 +81,10 @@ public class ReactViewManager extends ViewGroupManager { view.setHitSlopRect(null); } else { view.setHitSlopRect(new Rect( - (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")), - (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")), - (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")), - (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom")) + hitSlop.hasKey("left") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")) : 0, + hitSlop.hasKey("top") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")) : 0, + hitSlop.hasKey("right") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")) : 0, + hitSlop.hasKey("bottom") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom")) : 0 )); } }