Skip to content

Commit c2a55ba

Browse files
AndrewJackFacebook Github Bot
authored andcommitted
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 #10952 Differential Revision: D4182815 Pulled By: ericvicenti fbshipit-source-id: 07d7aca67b5739d5d1939b257476c24dcb10cbb0
1 parent 2cc57d0 commit c2a55ba

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public void setHitSlop(final ReactViewGroup view, @Nullable ReadableMap hitSlop)
8181
view.setHitSlopRect(null);
8282
} else {
8383
view.setHitSlopRect(new Rect(
84-
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")),
85-
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")),
86-
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")),
87-
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom"))
84+
hitSlop.hasKey("left") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")) : 0,
85+
hitSlop.hasKey("top") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")) : 0,
86+
hitSlop.hasKey("right") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")) : 0,
87+
hitSlop.hasKey("bottom") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom")) : 0
8888
));
8989
}
9090
}

0 commit comments

Comments
 (0)