Skip to content
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

Fixed usage of deprecated React lifecycle method componentWillUpdate #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/TappableMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var ReactDOM = require('react-dom');
const SPACE_KEY = 32;
const ENTER_KEY = 13;

function getTouchProps (touch) {
function getTouchProps(touch) {
if (!touch) return {};
return {
pageX: touch.pageX,
Expand All @@ -21,7 +21,7 @@ var Mixin = {
moveXThreshold: PropTypes.number, // pixels on the x axis to move before cancelling tap (overrides moveThreshold)
moveYThreshold: PropTypes.number, // pixels on the y axis to move before cancelling tap (overrides moveThreshold)
allowReactivation: PropTypes.bool, // after moving outside of the moveThreshold will you allow
// reactivation by moving back within the moveThreshold?
// reactivation by moving back within the moveThreshold?
activeDelay: PropTypes.number, // ms to wait before adding the `-active` class
pressDelay: PropTypes.number, // ms to wait before detecting a press
pressMoveThreshold: PropTypes.number, // pixels to move before cancelling press
Expand Down Expand Up @@ -70,12 +70,14 @@ var Mixin = {
this.clearActiveTimeout();
},

componentWillUpdate: function(nextProps, nextState) {
shouldComponentUpdate: function (nextProps, nextState) {
if (this.state.isActive && !nextState.isActive) {
this.props.onDeactivate && this.props.onDeactivate();
} else if (!this.state.isActive && nextState.isActive) {
this.props.onReactivate && this.props.onReactivate();
}

return true;
},

processEvent: function (event) {
Expand All @@ -98,8 +100,8 @@ var Mixin = {
this.makeActive();
}
} else if (this.onPinchStart &&
(this.props.onPinchStart || this.props.onPinchMove || this.props.onPinchEnd) &&
event.touches.length === 2) {
(this.props.onPinchStart || this.props.onPinchMove || this.props.onPinchEnd) &&
event.touches.length === 2) {
this.onPinchStart(event);
}
},
Expand Down Expand Up @@ -192,7 +194,7 @@ var Mixin = {
return this.endTouch(event);
} else {
if ((this._touchmoveTriggeredTimes)++ === 0) {
this._touchmoveDetectionTimeout = setTimeout(function() {
this._touchmoveDetectionTimeout = setTimeout(function () {
if (this._touchmoveTriggeredTimes === 1) {
this.endTouch(event);
}
Expand All @@ -207,7 +209,7 @@ var Mixin = {
this.cancelPressDetection();
}
if (movement.x > (this.props.moveXThreshold || this.props.moveThreshold) ||
movement.y > (this.props.moveYThreshold || this.props.moveThreshold)) {
movement.y > (this.props.moveYThreshold || this.props.moveThreshold)) {
if (this.state.isActive) {
if (this.props.allowReactivation) {
this.setState({
Expand Down Expand Up @@ -238,8 +240,8 @@ var Mixin = {
var afterEndTouch;
var movement = this.calculateMovement(this._lastTouch);
if (movement.x <= (this.props.moveXThreshold || this.props.moveThreshold) &&
movement.y <= (this.props.moveYThreshold || this.props.moveThreshold) &&
this.props.onTap) {
movement.y <= (this.props.moveYThreshold || this.props.moveThreshold) &&
this.props.onTap) {
event.preventDefault();
afterEndTouch = () => {
var finalParentScrollPos = this._scrollParents.map(node => node.scrollTop + node.scrollLeft);
Expand Down