Skip to content
This repository was archived by the owner on Sep 16, 2020. It is now read-only.

RTL fix #313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
},
Expand Down Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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');

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
13 changes: 9 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Text,
View,
ViewPropTypes,
I18nManager,
} from 'react-native';

const SwipeoutBtn = createReactClass({
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down