Skip to content

Commit

Permalink
Fix isMounted deprecation
Browse files Browse the repository at this point in the history
As of React 15.5, `isMounted` is deprecated.

This changeset is based on React's own `isMounted` implementation:
https://github.com/facebook/react/blob/v15.6.1/addons/create-react-class/factory.js#L695-L705

Fixes #105.
  • Loading branch information
matthieuprat committed Jul 3, 2017
1 parent 6bfec78 commit 752f4a2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/TappableMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ var Mixin = {
};
},

componentDidMount: function () {
this.isMounted = true;
},

componentWillUnmount: function () {
this.isMounted = false;
this.cleanupScrollDetection();
this.cancelPressDetection();
this.clearActiveTimeout();
Expand Down Expand Up @@ -87,7 +92,7 @@ var Mixin = {
},

makeActive: function () {
if (!this.isMounted()) return;
if (!this.isMounted) return;
this.clearActiveTimeout();
this.setState({
isActive: true
Expand Down Expand Up @@ -152,10 +157,10 @@ var Mixin = {

initPressDetection: function (event, callback) {
if (!this.props.onPress) return;

// SyntheticEvent objects are pooled, so persist the event so it can be referenced asynchronously
event.persist();

this._pressTimeout = setTimeout(function () {
this.props.onPress(event);
callback();
Expand Down

0 comments on commit 752f4a2

Please sign in to comment.