From 22a21eaf418d82f3b845f9bd6d737244a3e6c5ce Mon Sep 17 00:00:00 2001 From: Laura Knight Date: Wed, 2 Nov 2016 14:58:11 -0700 Subject: [PATCH 1/3] Update to allow swipe to close --- src/Swipeout.web.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Swipeout.web.js b/src/Swipeout.web.js index 0bf1885..a819f6e 100644 --- a/src/Swipeout.web.js +++ b/src/Swipeout.web.js @@ -198,12 +198,7 @@ class Swipeout extends React.Component { ]); let direction = 'DIRECTION_HORIZONTAL'; - if (left.length && right.length === 0) { - direction = 'DIRECTION_RIGHT'; - } - if (right.length && left.length === 0) { - direction = 'DIRECTION_LEFT'; - } + return (left.length || right.length) ? (
Date: Wed, 2 Nov 2016 14:59:45 -0700 Subject: [PATCH 2/3] Use const --- src/Swipeout.web.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Swipeout.web.js b/src/Swipeout.web.js index a819f6e..952dda3 100644 --- a/src/Swipeout.web.js +++ b/src/Swipeout.web.js @@ -197,7 +197,7 @@ class Swipeout extends React.Component { 'onClose', ]); - let direction = 'DIRECTION_HORIZONTAL'; + const direction = 'DIRECTION_HORIZONTAL'; return (left.length || right.length) ? (
From 1416daf1bd9ac52f0eae890212139b6dd386ef6d Mon Sep 17 00:00:00 2001 From: Laura Knight Date: Wed, 9 Nov 2016 14:40:35 -0800 Subject: [PATCH 3/3] Prevent triggering open on wrong direction --- src/Swipeout.web.js | 48 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/Swipeout.web.js b/src/Swipeout.web.js index 952dda3..3a43e78 100644 --- a/src/Swipeout.web.js +++ b/src/Swipeout.web.js @@ -37,10 +37,26 @@ class Swipeout extends React.Component { this.openedRight = false; } + state = { + direction: 'DIRECTION_HORIZONTAL', + } + componentDidMount() { const { left, right } = this.props; const width = this.refs.content.offsetWidth; + if (left.length && right.length === 0) { + this.setState({ + direction: 'DIRECTION_RIGHT', + }); + } + + if (right.length && left.length === 0) { + this.setState({ + direction: 'DIRECTION_LEFT', + }); + } + this.contentWidth = width; this.btnsLeftWidth = left ? (width / 5) * left.length : 0; this.btnsRightWidth = right ? (width / 5) * right.length : 0; @@ -93,7 +109,11 @@ class Swipeout extends React.Component { openLeft = posX + openX > openX; } - if (openRight && posX < 0) { + if (this.openedRight && openLeft && posX > 0) { + this.close(); + } else if (this.openedLeft && openRight && posX < 0) { + this.close(); + } else if (openRight && posX < 0) { this.open(-btnsRightWidth, false, true); } else if (openLeft && posX > 0) { this.open(btnsLeftWidth, true, false); @@ -153,13 +173,35 @@ class Swipeout extends React.Component { this.openedLeft = openedLeft; this.openedRight = openedRight; + + this.setState({ + direction: 'DIRECTION_HORIZONTAL', + }); + this._setStyle(value); } close() { + const { left, right } = this.props; + if (this.openedLeft || this.openedRight) { this.props.onClose(); } + + if (left.length && right.length) { + this.setState({ + direction: 'DIRECTION_HORIZONTAL', + }); + } else if (left.length && right.length === 0) { + this.setState({ + direction: 'DIRECTION_RIGHT', + }); + } else if (right.length && left.length === 0) { + this.setState({ + direction: 'DIRECTION_LEFT', + }); + } + this.openedLeft = false; this.openedRight = false; this._setStyle(0); @@ -197,12 +239,10 @@ class Swipeout extends React.Component { 'onClose', ]); - const direction = 'DIRECTION_HORIZONTAL'; - return (left.length || right.length) ? (