From 45e081f2e4b76ccf9eb6fc319cbf8a63e4910e32 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 13 Dec 2017 12:23:49 -0600 Subject: [PATCH] Update index.js Make more efficient. Only update swipeable when something changes. --- src/index.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index cdec6cc..424b3b0 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,12 @@ /* eslint-disable import/no-unresolved, import/extensions */ -import React, {PureComponent} from 'react'; +import React, {Component} from 'react'; import {Animated, Easing, PanResponder, StyleSheet, View, ViewPropTypes} from 'react-native'; import {PropTypes} from 'prop-types'; /* eslint-enable import/no-unresolved, import/extensions */ function noop() {} -export default class Swipeable extends PureComponent { +export default class Swipeable extends Component { static propTypes = { // elements @@ -186,6 +186,21 @@ export default class Swipeable extends PureComponent { this._unmounted = true; } + shouldComponentUpdate(nextProps, nextState) { + if ( + this.state.leftActionActivated != nextState.leftActionActivated || + this.state.leftButtonsActivated != nextState.leftButtonsActivated || + this.state.leftButtonsOpen != nextState.leftButtonsOpen || + this.state.rightActionActivated != nextState.rightActionActivated || + this.state.rightButtonsActivated != nextState.rightButtonsActivated || + this.state.rightButtonsOpen != nextState.rightButtonsOpen + ) { + return true; + } else { + return false; + } + } + recenter = ( animationFn = this.props.swipeReleaseAnimationFn, animationConfig = this.props.swipeReleaseAnimationConfig,