-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hitSlop prop on iOS and Android #5720
Conversation
By analyzing the blame information on this pull request, we identified @dmmiller, @andreicoman11 and @Ehesp to be potential reviewers. |
@@ -108,6 +113,10 @@ var TouchableBounce = React.createClass({ | |||
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET; | |||
}, | |||
|
|||
touchableGetHitSlop: function(): number { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined This type is incompatible with number
779f977
to
34cec67
Compare
@jesseruder updated the pull request. |
It looks like the tests don't like me doing |
@andreicoman11 @kmagiera are you guys the best people to look at Android touch system diffs? |
@bestander it looks like R.java isn't generated (?) because the tests don't use Gradle -- off the top of your head do you know how to make Buck take care of this for us? |
@@ -118,6 +123,10 @@ var TouchableWithoutFeedback = React.createClass({ | |||
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET; | |||
}, | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined This type is incompatible with object type
34cec67
to
b5ee125
Compare
@jesseruder updated the pull request. |
hitSlopPixels.put("bottom", PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom"))); | ||
hitSlopPixels.put("left", PixelUtil.toPixelFromDIP(hitSlop.getDouble("left"))); | ||
hitSlopPixels.put("right", PixelUtil.toPixelFromDIP(hitSlop.getDouble("right"))); | ||
view.setTag(R.id.hitSlopTag, hitSlopPixels); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just add an extra property to the ReactViewGroup
and assing it there? Calling setTag
this way will often allocate an extra SparseArray
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I'll change that.
b5ee125
to
a50bc13
Compare
@jesseruder updated the pull request. |
I tried adding
Is there any clean way to solve this @bestander? I could add an interface under react/uimanager but that seems like overkill. |
if ((localX >= 0 && localX < (child.getRight() - child.getLeft())) | ||
&& (localY >= 0 && localY < (child.getBottom() - child.getTop()))) { | ||
Rect hitSlopRect = new Rect(); | ||
if (child instanceof ReactViewGroup && ((ReactViewGroup) child).getHitSlopRect() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you extract getHitSlopRect
to an interface so that other views (such as Text elements) can implement hitSlop too if we need it?
@jesseruder yeah, that sucks. |
a50bc13
to
6db6921
Compare
@mkonicek iOS side looks 👍 to me. LGTM |
Also, just FYI martin, we've been using this internally and it's working great on both platforms :) |
Oh cool, good to know! |
/** | ||
* This defines how far your touch can start away from the button. This is | ||
* added to `pressRetentionOffset` when moving off of the button. | ||
* The touch area never extends past the parent view bounds and the Z-index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be more obvious to the reader, something like ** NOTE ** or even "Experimental" would help here
@jesseruder updated the pull request. |
@@ -202,6 +203,14 @@ const View = React.createClass({ | |||
onMoveShouldSetResponderCapture: PropTypes.func, | |||
|
|||
/** | |||
* This defines how far a touch event can start away from the view. | |||
* The touch area never extends past the parent view bounds and the Z-index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
@jesseruder updated the pull request. |
* This defines how far a touch event can start away from the view. | ||
* The touch area never extends past the parent view bounds and the Z-index | ||
* of sibling views always takes precedence if a touch hits two overlapping | ||
* views. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a short example here showing how I would extend the area by n pixels in each direction? What's a reasonable number?
@jesseruder updated the pull request. |
Looks good! Just two small nits and would be nice to add a small example: https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/TouchableExample.js |
6db6921
to
6cdf128
Compare
@jesseruder updated the pull request. |
@mkonicek @andreicoman11 Added an example and more comments. Thanks! |
6cdf128
to
d13c51a
Compare
@jesseruder updated the pull request. |
1 similar comment
@jesseruder updated the pull request. |
d13c51a
to
54dcde6
Compare
@jesseruder updated the pull request. |
54dcde6
to
8211582
Compare
@jesseruder updated the pull request. |
8211582
to
951c8bd
Compare
The example looks good and this is working on both platforms. |
@facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1041390565903389/int_phab to review. |
0176ac4
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 facebook#110 Closes facebook#5720 Differential Revision: D2941671 Pulled By: androidtrunkagent fb-gh-sync-id: 07e3eb8b6a36eebf76968fdaac3c6ac335603194 shipit-source-id: 07e3eb8b6a36eebf76968fdaac3c6ac335603194
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
, andright
same as thepressRetentionOffset
prop. When a touch is moved,hitSlop
is combined withpressRetentionOffset
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 thehitSlop
state. The iOS side is more straightforward.@terribleben worked on the iOS and JS parts of this diff.
Fixes #110