diff --git a/Parallax.js b/Parallax.js index 47e09a1..15a3ddd 100644 --- a/Parallax.js +++ b/Parallax.js @@ -1,6 +1,7 @@ -import React, { Component, } from 'react'; -import NativeMethodsMixin from 'react/lib/NativeMethodsMixin'; -import { Animated, View, Dimensions } from 'react-native'; +import React, { Component } from 'react'; +import ReactNative, { Animated, View, Dimensions, UIManager } from 'react-native'; + +const findNodeHandle = ReactNative.findNodeHandle; import { DriverShape } from './DriverShape'; /* @@ -73,15 +74,18 @@ export class Parallax extends Component { this.translation = new Animated.Value(0); this.calculateTranslation = this.calculateTranslation.bind(this); this.measure = this.measure.bind(this); + this.handleMeasure = this.handleMeasure.bind(this); this.state = { y: 0, }; } + handleMeasure(x, y, width, height, pageX, pageY) { + this.setState({ x: pageX, y: pageY }); + }; + measure() { - NativeMethodsMixin.measure.call(this, (x, y, width, height, pageX, pageY) => { - this.setState({ x: pageX, y: pageY }); - }); + UIManager.measure(findNodeHandle(this), handleMeasure); } componentDidMount() { @@ -97,7 +101,12 @@ export class Parallax extends Component { componentWillMount() { const { driver } = this.props; - driver.value.addListener(this.calculateTranslation); + this.animationListener = driver.value.addListener(this.calculateTranslation); + } + + componentWillUnmount() { + const { driver } = this.props; + driver.value.removeListener(this.animationListener); } render() {