diff --git a/dist/index.js b/dist/index.js index d4a976c5..ee68072c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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, @@ -209,11 +209,11 @@ var Swipeout = (0, _createReactClass2.default)({ _handlePanResponderMove: function _handlePanResponderMove(e, gestureState) { if (this.props.disabled) return; - var posX = gestureState.dx; + var posX = gestureState.dx * (_reactNative.I18nManager.isRTL ? -1 : 1); var posY = gestureState.dy; var leftWidth = this.state.btnsLeftWidth; var rightWidth = this.state.btnsRightWidth; - if (this.state.openedRight) var posX = gestureState.dx - rightWidth;else if (this.state.openedLeft) var posX = gestureState.dx + leftWidth; + if (this.state.openedRight) var posX = gestureState.dx * (_reactNative.I18nManager.isRTL ? -1 : 1) - rightWidth;else if (this.state.openedLeft) var posX = gestureState.dx * (_reactNative.I18nManager.isRTL ? -1 : 1) + leftWidth; // prevent scroll if moveX is true var moveX = Math.abs(posX) > Math.abs(posY); @@ -232,7 +232,7 @@ var Swipeout = (0, _createReactClass2.default)({ _handlePanResponderEnd: function _handlePanResponderEnd(e, gestureState) { if (this.props.disabled) return; - var posX = gestureState.dx; + var posX = gestureState.dx * (_reactNative.I18nManager.isRTL ? -1 : 1); var contentPos = this.state.contentPos; var contentWidth = this.state.contentWidth; var btnsLeftWidth = this.state.btnsLeftWidth; @@ -279,6 +279,10 @@ var Swipeout = (0, _createReactClass2.default)({ }, _rubberBandEasing: function _rubberBandEasing(value, limit) { + if (_reactNative.I18nManager.isRTL) { + value *= -1; + limit *= -1; + } if (value < 0 && value < limit) return limit - Math.pow(limit - value, 0.85);else if (value > 0 && value > limit) return limit + Math.pow(value - limit, 0.85); return value; }, @@ -337,7 +341,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 +363,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 +383,8 @@ var Swipeout = (0, _createReactClass2.default)({ }, render: function render() { + var _this5 = this; + var contentWidth = this.state.contentWidth; var posX = this.getTweeningValue('contentPos'); @@ -427,7 +433,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 +470,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 +480,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..ae8a8f96 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,7 @@ import { Text, View, ViewPropTypes, + I18nManager, } from 'react-native'; const SwipeoutBtn = createReactClass({ @@ -181,12 +182,12 @@ const Swipeout = createReactClass({ _handlePanResponderMove: function (e: Object, gestureState: Object) { if (this.props.disabled) return; - var posX = gestureState.dx; + var posX = gestureState.dx * (I18nManager.isRTL ? -1 : 1); var posY = gestureState.dy; var leftWidth = this.state.btnsLeftWidth; var rightWidth = this.state.btnsRightWidth; - if (this.state.openedRight) var posX = gestureState.dx - rightWidth; - else if (this.state.openedLeft) var posX = gestureState.dx + leftWidth; + if (this.state.openedRight) var posX = (gestureState.dx * (I18nManager.isRTL ? -1 : 1)) - rightWidth; + else if (this.state.openedLeft) var posX = (gestureState.dx * (I18nManager.isRTL ? -1 : 1)) + leftWidth; // prevent scroll if moveX is true var moveX = Math.abs(posX) > Math.abs(posY); @@ -206,7 +207,7 @@ const Swipeout = createReactClass({ _handlePanResponderEnd: function (e: Object, gestureState: Object) { if (this.props.disabled) return; - var posX = gestureState.dx; + var posX = gestureState.dx * (I18nManager.isRTL ? -1 : 1); var contentPos = this.state.contentPos; var contentWidth = this.state.contentWidth; var btnsLeftWidth = this.state.btnsLeftWidth; @@ -253,6 +254,10 @@ const Swipeout = createReactClass({ }, _rubberBandEasing: function (value, limit) { + if (I18nManager.isRTL) { + value *= -1 + limit *= -1 + } if (value < 0 && value < limit) return limit - Math.pow(limit - value, 0.85); else if (value > 0 && value > limit) return limit + Math.pow(value - limit, 0.85); return value;