diff --git a/dist/index.js b/dist/index.js index d4a976c5..9c1c90ee 100644 --- a/dist/index.js +++ b/dist/index.js @@ -154,7 +154,7 @@ var Swipeout = (0, _createReactClass2.default)({ }; }, - componentWillMount: function componentWillMount() { + componentDidMount: function componentDidMount() { var _this = this; this._panResponder = _reactNative.PanResponder.create({ @@ -180,10 +180,10 @@ var Swipeout = (0, _createReactClass2.default)({ }); }, - componentWillReceiveProps: function componentWillReceiveProps(nextProps) { - if (nextProps.close) this._close(); - if (nextProps.openRight) this._openRight(); - if (nextProps.openLeft) this._openLeft(); + componentDidUpdate: function componentDidUpdate(prevProps) { + if (!prevProps.close && this.props.close) this._close(); + if (!prevProps.openRight && this.props.openRight) this._openRight(); + if (!prevProps.openLeft && this.props.openLeft) this._openLeft(); }, _handlePanResponderGrant: function _handlePanResponderGrant(e, gestureState) { @@ -195,7 +195,7 @@ var Swipeout = (0, _createReactClass2.default)({ } else { this._callOnClose(); } - this.refs.swipeoutContent.measure(function (ox, oy, width, height) { + this.swipeoutContent.measure(function (ox, oy, width, height) { var buttonWidth = _this2.props.buttonWidth || width / 5; _this2.setState({ btnWidth: buttonWidth, @@ -337,7 +337,7 @@ var Swipeout = (0, _createReactClass2.default)({ _openRight: function _openRight() { var _this3 = this; - this.refs.swipeoutContent.measure(function (ox, oy, width, height) { + this.swipeoutContent.measure(function (ox, oy, width, height) { var btnWidth = _this3.props.buttonWidth || width / 5; _this3.setState({ @@ -359,7 +359,7 @@ var Swipeout = (0, _createReactClass2.default)({ _openLeft: function _openLeft() { var _this4 = this; - this.refs.swipeoutContent.measure(function (ox, oy, width, height) { + this.swipeoutContent.measure(function (ox, oy, width, height) { var btnWidth = _this4.props.buttonWidth || width / 5; _this4.setState({ @@ -379,6 +379,11 @@ var Swipeout = (0, _createReactClass2.default)({ }, render: function render() { + var _this5 = this; + + if (!this._panResponder) { + return null; + } var contentWidth = this.state.contentWidth; var posX = this.getTweeningValue('contentPos'); @@ -427,7 +432,9 @@ var Swipeout = (0, _createReactClass2.default)({ _react2.default.createElement( _reactNative.View, _extends({ - ref: 'swipeoutContent', + ref: function ref(node) { + return _this5.swipeoutContent = node; + }, style: styleContent, onLayout: this._onLayout }, this._panResponder.panHandlers), @@ -462,7 +469,7 @@ var Swipeout = (0, _createReactClass2.default)({ }, _renderButton: function _renderButton(btn, i) { - var _this5 = this; + var _this6 = this; return _react2.default.createElement(SwipeoutBtn, { backgroundColor: btn.backgroundColor, @@ -472,7 +479,7 @@ var Swipeout = (0, _createReactClass2.default)({ height: this.state.contentHeight, key: i, onPress: function onPress() { - return _this5._autoClose(btn); + return _this6._autoClose(btn); }, text: btn.text, type: btn.type, diff --git a/src/index.js b/src/index.js index 93d72414..1ce5907f 100644 --- a/src/index.js +++ b/src/index.js @@ -137,7 +137,7 @@ const Swipeout = createReactClass({ }; }, - componentWillMount: function () { + componentDidMount: function () { this._panResponder = PanResponder.create({ onStartShouldSetPanResponder: (event, gestureState) => true, onStartShouldSetPanResponderCapture: (event, gestureState) => @@ -154,10 +154,10 @@ const Swipeout = createReactClass({ }); }, - componentWillReceiveProps: function (nextProps) { - if (nextProps.close) this._close(); - if (nextProps.openRight) this._openRight(); - if (nextProps.openLeft) this._openLeft(); + componentDidUpdate: function (prevProps) { + if (!prevProps.close && this.props.close) this._close(); + if (!prevProps.openRight && this.props.openRight) this._openRight(); + if (!prevProps.openLeft && this.props.openLeft) this._openLeft(); }, _handlePanResponderGrant: function (e: Object, gestureState: Object) { @@ -342,6 +342,9 @@ const Swipeout = createReactClass({ }, render: function () { + if (!this._panResponder) { + return null; + } var contentWidth = this.state.contentWidth; var posX = this.getTweeningValue('contentPos');