@@ -20,6 +20,10 @@ function getTouchProps(touch) {
20
20
var Mixin = {
21
21
propTypes : {
22
22
moveThreshold : PropTypes . number , // pixels to move before cancelling tap
23
+ moveXThreshold : PropTypes . number , // pixels on the x axis to move before cancelling tap (overrides moveThreshold)
24
+ moveYThreshold : PropTypes . number , // pixels on the y axis to move before cancelling tap (overrides moveThreshold)
25
+ allowReactivation : PropTypes . bool , // after moving outside of the moveThreshold will you allow
26
+ // reactivation by moving back within the moveThreshold?
23
27
activeDelay : PropTypes . number , // ms to wait before adding the `-active` class
24
28
pressDelay : PropTypes . number , // ms to wait before detecting a press
25
29
pressMoveThreshold : PropTypes . number , // pixels to move before cancelling press
@@ -36,12 +40,13 @@ var Mixin = {
36
40
onMouseMove : PropTypes . func , // pass-through mouse event
37
41
onMouseOut : PropTypes . func , // pass-through mouse event
38
42
onKeyDown : PropTypes . func , // pass-through key event
39
- onKeyUp : PropTypes . func } ,
43
+ onKeyUp : PropTypes . func // pass-through key event
44
+ } ,
40
45
41
- // pass-through key event
42
46
getDefaultProps : function getDefaultProps ( ) {
43
47
return {
44
48
activeDelay : 0 ,
49
+ allowReactivation : true ,
45
50
moveThreshold : 100 ,
46
51
pressDelay : 1000 ,
47
52
pressMoveThreshold : 5
@@ -67,6 +72,14 @@ var Mixin = {
67
72
this . clearActiveTimeout ( ) ;
68
73
} ,
69
74
75
+ componentWillUpdate : function componentWillUpdate ( nextProps , nextState ) {
76
+ if ( this . state . isActive && ! nextState . isActive ) {
77
+ this . props . onDeactivate && this . props . onDeactivate ( ) ;
78
+ } else if ( ! this . state . isActive && nextState . isActive ) {
79
+ this . props . onReactivate && this . props . onReactivate ( ) ;
80
+ }
81
+ } ,
82
+
70
83
processEvent : function processEvent ( event ) {
71
84
if ( this . props . preventDefault ) event . preventDefault ( ) ;
72
85
if ( this . props . stopPropagation ) event . stopPropagation ( ) ;
@@ -161,10 +174,10 @@ var Mixin = {
161
174
// SyntheticEvent objects are pooled, so persist the event so it can be referenced asynchronously
162
175
event . persist ( ) ;
163
176
164
- this . _pressTimeout = setTimeout ( ( function ( ) {
177
+ this . _pressTimeout = setTimeout ( function ( ) {
165
178
this . props . onPress ( event ) ;
166
179
callback ( ) ;
167
- } ) . bind ( this ) , this . props . pressDelay ) ;
180
+ } . bind ( this ) , this . props . pressDelay ) ;
168
181
} ,
169
182
170
183
cancelPressDetection : function cancelPressDetection ( ) {
@@ -179,11 +192,11 @@ var Mixin = {
179
192
return this . endTouch ( event ) ;
180
193
} else {
181
194
if ( this . _touchmoveTriggeredTimes ++ === 0 ) {
182
- this . _touchmoveDetectionTimeout = setTimeout ( ( function ( ) {
195
+ this . _touchmoveDetectionTimeout = setTimeout ( function ( ) {
183
196
if ( this . _touchmoveTriggeredTimes === 1 ) {
184
197
this . endTouch ( event ) ;
185
198
}
186
- } ) . bind ( this ) , 64 ) ;
199
+ } . bind ( this ) , 64 ) ;
187
200
}
188
201
}
189
202
@@ -193,11 +206,15 @@ var Mixin = {
193
206
if ( movement . x > this . props . pressMoveThreshold || movement . y > this . props . pressMoveThreshold ) {
194
207
this . cancelPressDetection ( ) ;
195
208
}
196
- if ( movement . x > this . props . moveThreshold || movement . y > this . props . moveThreshold ) {
209
+ if ( movement . x > ( this . props . moveXThreshold || this . props . moveThreshold ) || movement . y > ( this . props . moveYThreshold || this . props . moveThreshold ) ) {
197
210
if ( this . state . isActive ) {
198
- this . setState ( {
199
- isActive : false
200
- } ) ;
211
+ if ( this . props . allowReactivation ) {
212
+ this . setState ( {
213
+ isActive : false
214
+ } ) ;
215
+ } else {
216
+ return this . endTouch ( event ) ;
217
+ }
201
218
} else if ( this . _activeTimeout ) {
202
219
this . clearActiveTimeout ( ) ;
203
220
}
@@ -221,9 +238,9 @@ var Mixin = {
221
238
this . processEvent ( event ) ;
222
239
var afterEndTouch ;
223
240
var movement = this . calculateMovement ( this . _lastTouch ) ;
224
- if ( movement . x <= this . props . moveThreshold && movement . y <= this . props . moveThreshold && this . props . onTap ) {
241
+ if ( movement . x <= ( this . props . moveXThreshold || this . props . moveThreshold ) && movement . y <= ( this . props . moveYThreshold || this . props . moveThreshold ) && this . props . onTap ) {
225
242
event . preventDefault ( ) ;
226
- afterEndTouch = function ( ) {
243
+ afterEndTouch = function afterEndTouch ( ) {
227
244
var finalParentScrollPos = _this . _scrollParents . map ( function ( node ) {
228
245
return node . scrollTop + node . scrollLeft ;
229
246
} ) ;
0 commit comments