diff --git a/index.js b/index.js index 8528ba2..18ccf8c 100644 --- a/index.js +++ b/index.js @@ -4,18 +4,21 @@ import React, { Component } from 'react' import { View, NativeMethodsMixin, Dimensions } from 'react-native' exports.InViewPort = class extends Component { + isMounted = false constructor(props) { super(props) this.state = { rectTop: 0, rectBottom: 0 } } componentDidMount() { + this.isMounted = true if (!this.props.disabled) { this.startWatching() } } componentWillUnmount() { + this.isMounted = false this.stopWatching() } @@ -37,11 +40,13 @@ exports.InViewPort = class extends Component { return } this.myview.measure((x, y, width, height, pageX, pageY) => { - this.setState({ - rectTop: pageY, - rectBottom: pageY + height, - rectWidth: pageX + width - }) + if (this.isMounted) { + this.setState({ + rectTop: pageY, + rectBottom: pageY + height, + rectWidth: pageX + width + }) + } }) this.isInViewPort() }, this.props.delay || 100)