Skip to content

Commit bfe1019

Browse files
committed
fix missing updated lib/ files
1 parent 3f24e83 commit bfe1019

5 files changed

+37
-24
lines changed

lib/PinchableMixin.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
4-
53
var PropTypes = require('prop-types');
64
var React = require('react');
75

@@ -30,7 +28,7 @@ var Mixin = {
3028
}
3129
var touches = event.touches;
3230
this._initialPinch = getPinchProps(touches);
33-
this._initialPinch = _extends(this._initialPinch, {
31+
this._initialPinch = Object.assign(this._initialPinch, {
3432
displacement: { x: 0, y: 0 },
3533
displacementVelocity: { x: 0, y: 0 },
3634
rotation: 0,
@@ -82,7 +80,7 @@ var Mixin = {
8280

8381
onPinchEnd: function onPinchEnd(event) {
8482
// TODO use helper to order touches by identifier and use actual values on touchEnd.
85-
var currentPinch = _extends({}, this._lastPinch);
83+
var currentPinch = Object.assign({}, this._lastPinch);
8684
currentPinch.time = Date.now();
8785

8886
if (currentPinch.time - this._lastPinch.time > 16) {

lib/TapAndPinchable.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
4-
53
var TappableMixin = require('./TappableMixin');
64
var PinchableMixin = require('./PinchableMixin');
75
var getComponent = require('./getComponent');
@@ -11,7 +9,7 @@ var Component = getComponent([TappableMixin, PinchableMixin]);
119

1210
module.exports = Component;
1311
module.exports.touchStyles = touchStyles;
14-
module.exports.Mixin = _extends({}, TappableMixin, {
12+
module.exports.Mixin = Object.assign({}, TappableMixin, {
1513
onPinchStart: PinchableMixin.onPinchStart,
1614
onPinchMove: PinchableMixin.onPinchMove,
1715
onPinchEnd: PinchableMixin.onPinchEnd

lib/TappableMixin.js

+29-12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ function getTouchProps(touch) {
2020
var Mixin = {
2121
propTypes: {
2222
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?
2327
activeDelay: PropTypes.number, // ms to wait before adding the `-active` class
2428
pressDelay: PropTypes.number, // ms to wait before detecting a press
2529
pressMoveThreshold: PropTypes.number, // pixels to move before cancelling press
@@ -36,12 +40,13 @@ var Mixin = {
3640
onMouseMove: PropTypes.func, // pass-through mouse event
3741
onMouseOut: PropTypes.func, // pass-through mouse event
3842
onKeyDown: PropTypes.func, // pass-through key event
39-
onKeyUp: PropTypes.func },
43+
onKeyUp: PropTypes.func // pass-through key event
44+
},
4045

41-
// pass-through key event
4246
getDefaultProps: function getDefaultProps() {
4347
return {
4448
activeDelay: 0,
49+
allowReactivation: true,
4550
moveThreshold: 100,
4651
pressDelay: 1000,
4752
pressMoveThreshold: 5
@@ -67,6 +72,14 @@ var Mixin = {
6772
this.clearActiveTimeout();
6873
},
6974

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+
7083
processEvent: function processEvent(event) {
7184
if (this.props.preventDefault) event.preventDefault();
7285
if (this.props.stopPropagation) event.stopPropagation();
@@ -161,10 +174,10 @@ var Mixin = {
161174
// SyntheticEvent objects are pooled, so persist the event so it can be referenced asynchronously
162175
event.persist();
163176

164-
this._pressTimeout = setTimeout((function () {
177+
this._pressTimeout = setTimeout(function () {
165178
this.props.onPress(event);
166179
callback();
167-
}).bind(this), this.props.pressDelay);
180+
}.bind(this), this.props.pressDelay);
168181
},
169182

170183
cancelPressDetection: function cancelPressDetection() {
@@ -179,11 +192,11 @@ var Mixin = {
179192
return this.endTouch(event);
180193
} else {
181194
if (this._touchmoveTriggeredTimes++ === 0) {
182-
this._touchmoveDetectionTimeout = setTimeout((function () {
195+
this._touchmoveDetectionTimeout = setTimeout(function () {
183196
if (this._touchmoveTriggeredTimes === 1) {
184197
this.endTouch(event);
185198
}
186-
}).bind(this), 64);
199+
}.bind(this), 64);
187200
}
188201
}
189202

@@ -193,11 +206,15 @@ 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) || movement.y > (this.props.moveYThreshold || this.props.moveThreshold)) {
197210
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+
}
201218
} else if (this._activeTimeout) {
202219
this.clearActiveTimeout();
203220
}
@@ -221,9 +238,9 @@ var Mixin = {
221238
this.processEvent(event);
222239
var afterEndTouch;
223240
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) {
225242
event.preventDefault();
226-
afterEndTouch = function () {
243+
afterEndTouch = function afterEndTouch() {
227244
var finalParentScrollPos = _this._scrollParents.map(function (node) {
228245
return node.scrollTop + node.scrollLeft;
229246
});

lib/getComponent.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
4-
53
var createReactClass = require('create-react-class');
64
var PropTypes = require('prop-types');
75
var React = require('react');
@@ -46,9 +44,9 @@ module.exports = function (mixins) {
4644
}
4745

4846
var style = {};
49-
_extends(style, touchStyles, props.style);
47+
Object.assign(style, touchStyles, props.style);
5048

51-
var newComponentProps = _extends({}, props, {
49+
var newComponentProps = Object.assign({}, props, {
5250
style: style,
5351
className: className,
5452
disabled: props.disabled,

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"react-dom": "^0.14 || ^15.0.0-rc || ^15.0.0 || ^16.0.0"
1717
},
1818
"devDependencies": {
19+
"babel-cli": "^6.26.0",
1920
"babel-core": "^6.26.0",
2021
"babel-eslint": "^4.1.3",
2122
"babel-preset-es2015": "^6.24.1",
@@ -43,7 +44,8 @@
4344
"react-dom": "global:ReactDOM"
4445
},
4546
"scripts": {
46-
"build": "browserify src/TapAndPinchable.js --standalone ReactTappable --transform [ babelify ] > dist/react-tappable.js",
47+
"build": "babel src --out-dir lib",
48+
"dist": "browserify src/TapAndPinchable.js --standalone ReactTappable --transform [ babelify ] > dist/react-tappable.js",
4749
"start": "gulp dev",
4850
"examples": "gulp dev:server",
4951
"lint": "eslint ./; true",

0 commit comments

Comments
 (0)