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](f930270b00/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
This commit is contained in:
Andrew Jack 2016-11-15 09:13:31 -08:00 committed by Facebook Github Bot
parent 2cc57d05a4
commit c2a55baf80
1 changed files with 4 additions and 4 deletions

View File

@ -81,10 +81,10 @@ public class ReactViewManager extends ViewGroupManager<ReactViewGroup> {
view.setHitSlopRect(null); view.setHitSlopRect(null);
} else { } else {
view.setHitSlopRect(new Rect( view.setHitSlopRect(new Rect(
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")), hitSlop.hasKey("left") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")) : 0,
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")), hitSlop.hasKey("top") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")) : 0,
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")), hitSlop.hasKey("right") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")) : 0,
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom")) hitSlop.hasKey("bottom") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom")) : 0
)); ));
} }
} }