From 8447fa8027b2492abd8369c5c766aee2500a3336 Mon Sep 17 00:00:00 2001 From: Ali Taheri Date: Wed, 25 Nov 2015 02:59:18 +0330 Subject: [PATCH] Made LeftNav swipable only from far left (or right) --- src/left-nav.jsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/left-nav.jsx b/src/left-nav.jsx index 3571e973492f16..6fe04ee5c124e2 100644 --- a/src/left-nav.jsx +++ b/src/left-nav.jsx @@ -331,7 +331,24 @@ const LeftNav = React.createClass({ } }, - _onBodyTouchStart(e) { + _onBodyTouchStart(e) { + + const swipeAreaWidth = 30; + + let touchStartX = e.touches[0].pageX; + let touchStartY = e.touches[0].pageY; + + // Open only if swiping from far left (or right) while closed + if (!this.state.open) { + if (this.props.openRight) { + // If openRight is true calculate from the far right + if (touchStartX < document.body.offsetWidth - swipeAreaWidth) return; + } else { + // If openRight is false calculate from the far left + if (touchStartX > swipeAreaWidth) return; + } + } + if (!this.state.open && (openNavEventHandler !== this._onBodyTouchStart || this.props.disableSwipeToOpen) @@ -339,9 +356,6 @@ const LeftNav = React.createClass({ return; } - let touchStartX = e.touches[0].pageX; - let touchStartY = e.touches[0].pageY; - this._maybeSwiping = true; this._touchStartX = touchStartX; this._touchStartY = touchStartY;