Skip to content

Commit 5133185

Browse files
authored
Merge pull request #85 from mattcolman/master
don’t reactivate the Tappable when moving back within the moveThreshold
2 parents 3448658 + 4557312 commit 5133185

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

lib/getComponent.js

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module.exports = function (mixins) {
5656
}, this.handlers());
5757

5858
delete newComponentProps.activeDelay;
59+
delete newComponentProps.allowReactivation;
5960
delete newComponentProps.classBase;
6061
delete newComponentProps.classes;
6162
delete newComponentProps.handlers;
@@ -64,7 +65,11 @@ module.exports = function (mixins) {
6465
delete newComponentProps.onPinchStart;
6566
delete newComponentProps.onPinchMove;
6667
delete newComponentProps.onPinchEnd;
68+
delete newComponentProps.onDeactivate;
69+
delete newComponentProps.onReactivate;
6770
delete newComponentProps.moveThreshold;
71+
delete newComponentProps.moveXThreshold;
72+
delete newComponentProps.moveYThreshold;
6873
delete newComponentProps.pressDelay;
6974
delete newComponentProps.pressMoveThreshold;
7075
delete newComponentProps.preventDefault;

src/TappableMixin.js

+25-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ function getTouchProps (touch) {
1818
var Mixin = {
1919
propTypes: {
2020
moveThreshold: PropTypes.number, // pixels to move before cancelling tap
21+
moveXThreshold: PropTypes.number, // pixels on the x axis to move before cancelling tap (overrides moveThreshold)
22+
moveYThreshold: PropTypes.number, // pixels on the y axis to move before cancelling tap (overrides moveThreshold)
23+
allowReactivation: PropTypes.bool, // after moving outside of the moveThreshold will you allow
24+
// reactivation by moving back within the moveThreshold?
2125
activeDelay: PropTypes.number, // ms to wait before adding the `-active` class
2226
pressDelay: PropTypes.number, // ms to wait before detecting a press
2327
pressMoveThreshold: PropTypes.number, // pixels to move before cancelling press
@@ -40,6 +44,7 @@ var Mixin = {
4044
getDefaultProps: function () {
4145
return {
4246
activeDelay: 0,
47+
allowReactivation: true,
4348
moveThreshold: 100,
4449
pressDelay: 1000,
4550
pressMoveThreshold: 5
@@ -65,6 +70,14 @@ var Mixin = {
6570
this.clearActiveTimeout();
6671
},
6772

73+
componentWillUpdate: function(nextProps, nextState) {
74+
if (this.state.isActive && !nextState.isActive) {
75+
this.props.onDeactivate && this.props.onDeactivate();
76+
} else if (!this.state.isActive && nextState.isActive) {
77+
this.props.onReactivate && this.props.onReactivate();
78+
}
79+
},
80+
6881
processEvent: function (event) {
6982
if (this.props.preventDefault) event.preventDefault();
7083
if (this.props.stopPropagation) event.stopPropagation();
@@ -193,11 +206,16 @@ var Mixin = {
193206
if (movement.x > this.props.pressMoveThreshold || movement.y > this.props.pressMoveThreshold) {
194207
this.cancelPressDetection();
195208
}
196-
if (movement.x > this.props.moveThreshold || movement.y > this.props.moveThreshold) {
209+
if (movement.x > (this.props.moveXThreshold || this.props.moveThreshold) ||
210+
movement.y > (this.props.moveYThreshold || this.props.moveThreshold)) {
197211
if (this.state.isActive) {
198-
this.setState({
199-
isActive: false
200-
});
212+
if (this.props.allowReactivation) {
213+
this.setState({
214+
isActive: false
215+
});
216+
} else {
217+
return this.endTouch(event);
218+
}
201219
} else if (this._activeTimeout) {
202220
this.clearActiveTimeout();
203221
}
@@ -219,7 +237,9 @@ var Mixin = {
219237
this.processEvent(event);
220238
var afterEndTouch;
221239
var movement = this.calculateMovement(this._lastTouch);
222-
if (movement.x <= this.props.moveThreshold && movement.y <= this.props.moveThreshold && this.props.onTap) {
240+
if (movement.x <= (this.props.moveXThreshold || this.props.moveThreshold) &&
241+
movement.y <= (this.props.moveYThreshold || this.props.moveThreshold) &&
242+
this.props.onTap) {
223243
event.preventDefault();
224244
afterEndTouch = () => {
225245
var finalParentScrollPos = this._scrollParents.map(node => node.scrollTop + node.scrollLeft);

src/getComponent.js

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = function (mixins) {
5252
}, this.handlers());
5353

5454
delete newComponentProps.activeDelay;
55+
delete newComponentProps.allowReactivation;
5556
delete newComponentProps.classBase;
5657
delete newComponentProps.classes;
5758
delete newComponentProps.handlers;
@@ -60,7 +61,11 @@ module.exports = function (mixins) {
6061
delete newComponentProps.onPinchStart;
6162
delete newComponentProps.onPinchMove;
6263
delete newComponentProps.onPinchEnd;
64+
delete newComponentProps.onDeactivate;
65+
delete newComponentProps.onReactivate;
6366
delete newComponentProps.moveThreshold;
67+
delete newComponentProps.moveXThreshold;
68+
delete newComponentProps.moveYThreshold;
6469
delete newComponentProps.pressDelay;
6570
delete newComponentProps.pressMoveThreshold;
6671
delete newComponentProps.preventDefault;

0 commit comments

Comments
 (0)