mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
Add hitSlop prop on iOS and Android
Summary:New prop `hitSlop` allows extending the touch area of Touchable components. This makes it easier to touch small buttons without needing to change your styles. It takes `top`, `bottom`, `left`, and `right` same as the `pressRetentionOffset` prop. When a touch is moved, `hitSlop` is combined with `pressRetentionOffset` to determine how far the touch can move off the button before deactivating the button. On Android I had to add a new file `ids.xml` to generate a unique ID to use for the tag where I store the `hitSlop` state. The iOS side is more straightforward. terribleben worked on the iOS and JS parts of this diff. Fixes #110 Closes https://github.com/facebook/react-native/pull/5720 Differential Revision: D2941671 Pulled By: androidtrunkagent fb-gh-sync-id: 07e3eb8b6a36eebf76968fdaac3c6ac335603194 shipit-source-id: 07e3eb8b6a36eebf76968fdaac3c6ac335603194
This commit is contained in:
committed by
facebook-github-bot-7
parent
ecf6981093
commit
0176ac488e
@@ -193,6 +193,17 @@ RCT_CUSTOM_VIEW_PROPERTY(borderStyle, RCTBorderStyle, RCTView)
|
||||
view.borderStyle = json ? [RCTConvert RCTBorderStyle:json] : defaultView.borderStyle;
|
||||
}
|
||||
}
|
||||
RCT_CUSTOM_VIEW_PROPERTY(hitSlop, UIEdgeInsets, RCTView)
|
||||
{
|
||||
if ([view respondsToSelector:@selector(setHitTestEdgeInsets:)]) {
|
||||
if (json) {
|
||||
UIEdgeInsets hitSlopInsets = [RCTConvert UIEdgeInsets:json];
|
||||
view.hitTestEdgeInsets = UIEdgeInsetsMake(-hitSlopInsets.top, -hitSlopInsets.left, -hitSlopInsets.bottom, -hitSlopInsets.right);
|
||||
} else {
|
||||
view.hitTestEdgeInsets = defaultView.hitTestEdgeInsets;
|
||||
}
|
||||
}
|
||||
}
|
||||
RCT_EXPORT_VIEW_PROPERTY(onAccessibilityTap, RCTDirectEventBlock)
|
||||
RCT_EXPORT_VIEW_PROPERTY(onMagicTap, RCTDirectEventBlock)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user