From 8ccdb9ba0b697b429bfeccaf76aa1732afd95254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Vukovic=CC=81?= <3.14wee@gmail.com> Date: Thu, 1 Dec 2016 16:40:17 +0100 Subject: [PATCH 1/2] Avoid use of NativeMethodsMixin * https://github.com/shoutem/animation/issues/7 --- Parallax.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Parallax.js b/Parallax.js index 47e09a1..878aead 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'; /* @@ -79,9 +80,11 @@ export class Parallax extends Component { } measure() { - NativeMethodsMixin.measure.call(this, (x, y, width, height, pageX, pageY) => { + const handleMeasure = (x, y, width, height, pageX, pageY) => { this.setState({ x: pageX, y: pageY }); - }); + }; + + UIManager.measure(findNodeHandle(this), handleMeasure); } componentDidMount() { @@ -97,7 +100,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() { From 3a5b4354eaa07a6299770c344f43ac670c310edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Vukovic=CC=81?= <3.14wee@gmail.com> Date: Thu, 1 Dec 2016 23:06:30 +0100 Subject: [PATCH 2/2] Address CR comments --- Parallax.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Parallax.js b/Parallax.js index 878aead..15a3ddd 100644 --- a/Parallax.js +++ b/Parallax.js @@ -74,16 +74,17 @@ 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, }; } - measure() { - const handleMeasure = (x, y, width, height, pageX, pageY) => { - this.setState({ x: pageX, y: pageY }); - }; + handleMeasure(x, y, width, height, pageX, pageY) { + this.setState({ x: pageX, y: pageY }); + }; + measure() { UIManager.measure(findNodeHandle(this), handleMeasure); }