Skip to content

Commit

Permalink
Expose the touch-retention offset as a prop
Browse files Browse the repository at this point in the history
Summary: The touch-retention offset defines a rect around a touchable component in which the touch is retained. Easiest way to see this is to touch a button in a real navigation bar and slide your finger out of the range and back in. This diff exposes the offset as a prop (I thought touchRetentionOffset was a more informative name than pressRectOffset)

Fixes #198
Closes #713

Reviewed By: svcscm

Differential Revision: D2115370

Pulled By: shayne

fb-gh-sync-id: c3f57940dfa3806f9c88df03a01d4d65bb58cf32
  • Loading branch information
ide authored and facebook-github-bot-7 committed Nov 16, 2015
1 parent 5217c82 commit f331d2a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
25 changes: 14 additions & 11 deletions Libraries/Components/Touchable/TouchableBounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,19 @@
'use strict';

var Animated = require('Animated');
var EdgeInsetsPropType = require('EdgeInsetsPropType');
var NativeMethodsMixin = require('NativeMethodsMixin');
var React = require('React');
var Touchable = require('Touchable');

var merge = require('merge');

type Event = Object;

type State = {
animationID: ?number;
};

/**
* When the scroll view is disabled, this defines how far your touch may move
* off of the button, before deactivating the button. Once deactivated, try
* moving it back and you'll see that the button is once again reactivated!
* Move it back and forth several times while the scroll view is disabled.
*/
var PRESS_RECT_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
var PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};

/**
* Example of using the `TouchableMixin` to play well with other responder
* locking views including `ScrollView`. `TouchableMixin` provides touchable
Expand All @@ -50,6 +45,14 @@ var TouchableBounce = React.createClass({
onPressWithCompletion: React.PropTypes.func,
// the function passed is called after the animation is complete
onPressAnimationComplete: React.PropTypes.func,
/**
* When the scroll view is disabled, this defines how far your touch may
* move off of the button, before deactivating the button. Once deactivated,
* try moving it back and you'll see that the button is once again
* reactivated! Move it back and forth several times while the scroll view
* is disabled. Ensure you pass in a constant to reduce memory allocations.
*/
pressRetentionOffset: EdgeInsetsPropType,
},

getInitialState: function(): State {
Expand Down Expand Up @@ -100,8 +103,8 @@ var TouchableBounce = React.createClass({
this.props.onPress && this.props.onPress(e);
},

touchableGetPressRectOffset: function(): typeof PRESS_RECT_OFFSET {
return PRESS_RECT_OFFSET; // Always make sure to predeclare a constant!
touchableGetPressRectOffset: function(): typeof PRESS_RETENTION_OFFSET {
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET;
},

touchableGetHighlightDelayMS: function(): number {
Expand Down
5 changes: 3 additions & 2 deletions Libraries/Components/Touchable/TouchableHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var DEFAULT_PROPS = {
underlayColor: 'black',
};

var PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};

/**
* A wrapper for making views respond properly to touches.
* On press down, the opacity of the wrapped view is decreased, which allows
Expand Down Expand Up @@ -169,7 +171,7 @@ var TouchableHighlight = React.createClass({
},

touchableGetPressRectOffset: function() {
return PRESS_RECT_OFFSET; // Always make sure to predeclare a constant!
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET;
},

touchableGetHighlightDelayMS: function() {
Expand Down Expand Up @@ -234,7 +236,6 @@ var TouchableHighlight = React.createClass({
}
});

var PRESS_RECT_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
var CHILD_REF = keyOf({childRef: null});
var UNDERLAY_REF = keyOf({underlayRef: null});
var INACTIVE_CHILD_PROPS = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var TouchableView = createReactNativeComponentClass({
uiViewClassName: 'RCTView',
});

var PRESS_RECT_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
var PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};

/**
* A wrapper for making views respond properly to touches (Android only).
Expand Down Expand Up @@ -161,7 +161,8 @@ var TouchableNativeFeedback = React.createClass({
},

touchableGetPressRectOffset: function() {
return PRESS_RECT_OFFSET; // Always make sure to predeclare a constant!
// Always make sure to predeclare a constant!
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET;
},

touchableGetHighlightDelayMS: function() {
Expand Down
15 changes: 3 additions & 12 deletions Libraries/Components/Touchable/TouchableOpacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ var TouchableWithoutFeedback = require('TouchableWithoutFeedback');

var ensurePositiveDelayProps = require('ensurePositiveDelayProps');
var flattenStyle = require('flattenStyle');
var keyOf = require('keyOf');

type Event = Object;

var PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};

/**
* A wrapper for making views respond properly to touches.
* On press down, the opacity of the wrapped view is decreased, dimming it.
Expand All @@ -46,7 +47,6 @@ type Event = Object;
* },
* ```
*/

var TouchableOpacity = React.createClass({
mixins: [TimerMixin, Touchable.Mixin, NativeMethodsMixin],

Expand Down Expand Up @@ -120,7 +120,7 @@ var TouchableOpacity = React.createClass({
},

touchableGetPressRectOffset: function() {
return PRESS_RECT_OFFSET; // Always make sure to predeclare a constant!
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET;
},

touchableGetHighlightDelayMS: function() {
Expand Down Expand Up @@ -170,13 +170,4 @@ var TouchableOpacity = React.createClass({
},
});

/**
* When the scroll view is disabled, this defines how far your touch may move
* off of the button, before deactivating the button. Once deactivated, try
* moving it back and you'll see that the button is once again reactivated!
* Move it back and forth several times while the scroll view is disabled.
*/
var PRESS_RECT_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};


module.exports = TouchableOpacity;
23 changes: 14 additions & 9 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -11,22 +12,18 @@
*/
'use strict';

var EdgeInsetsPropType = require('EdgeInsetsPropType');
var React = require('React');
var TimerMixin = require('react-timer-mixin');
var Touchable = require('Touchable');
var View = require('View');
var ensurePositiveDelayProps = require('ensurePositiveDelayProps');
var invariant = require('invariant');
var onlyChild = require('onlyChild');

type Event = Object;

/**
* When the scroll view is disabled, this defines how far your touch may move
* off of the button, before deactivating the button. Once deactivated, try
* moving it back and you'll see that the button is once again reactivated!
* Move it back and forth several times while the scroll view is disabled.
*/
var PRESS_RECT_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
var PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};

/**
* Do not use unless you have a very good reason. All the elements that
Expand Down Expand Up @@ -71,6 +68,14 @@ var TouchableWithoutFeedback = React.createClass({
* Delay in ms, from onPressIn, before onLongPress is called.
*/
delayLongPress: React.PropTypes.number,
/**
* When the scroll view is disabled, this defines how far your touch may
* move off of the button, before deactivating the button. Once deactivated,
* try moving it back and you'll see that the button is once again
* reactivated! Move it back and forth several times while the scroll view
* is disabled. Ensure you pass in a constant to reduce memory allocations.
*/
pressRetentionOffset: EdgeInsetsPropType,
},

getInitialState: function() {
Expand Down Expand Up @@ -105,8 +110,8 @@ var TouchableWithoutFeedback = React.createClass({
this.props.onLongPress && this.props.onLongPress(e);
},

touchableGetPressRectOffset: function(): typeof PRESS_RECT_OFFSET {
return PRESS_RECT_OFFSET; // Always make sure to predeclare a constant!
touchableGetPressRectOffset: function(): typeof PRESS_RETENTION_OFFSET {
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET;
},

touchableGetHighlightDelayMS: function(): number {
Expand Down

0 comments on commit f331d2a

Please sign in to comment.