Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Disable swiping when starting from the navigation bar
Browse files Browse the repository at this point in the history
Summary: Right now, it is possible to initiate a swipe by pressing on a key in the navigation bar. Since the navigation bar does not move with a swipe, it can be confusing to swipe the navigation bar but see other elements move instead. Now, it is not possible to initiate a swipe from the navigation bar, and so swipes must start from the main key panel instead.

Test Plan:
- Verified in a browser that it is still possible to swipe from non-navigation keys
- Checked that it is still possible to use all the keys on the keypad
- Checked that it is still possible to move over the navigation bar during a swipe

Reviewers: charlie, kevinb

Reviewed By: charlie, kevinb

Differential Revision: https://phabricator.khanacademy.org/D28012
  • Loading branch information
shadaj committed Jun 9, 2016
1 parent 3b7cde4 commit 1bf10fa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/gesture-manager.js
Expand Up @@ -13,7 +13,7 @@ const coordsForEvent = (evt) => {
}; };


class GestureManager { class GestureManager {
constructor(options, handlers) { constructor(options, handlers, disabledSwipeKeys) {
const { swipeEnabled } = options; const { swipeEnabled } = options;


this.swipeEnabled = swipeEnabled; this.swipeEnabled = swipeEnabled;
Expand Down Expand Up @@ -70,7 +70,7 @@ class GestureManager {
}, },
onSwipeChange: handlers.onSwipeChange, onSwipeChange: handlers.onSwipeChange,
onSwipeEnd: handlers.onSwipeEnd, onSwipeEnd: handlers.onSwipeEnd,
}); }, disabledSwipeKeys);
} }


/** /**
Expand Down
14 changes: 11 additions & 3 deletions src/components/gesture-state-machine.js
Expand Up @@ -10,11 +10,13 @@ const longPressWaitTimeMs = 100;
const swipeThresholdPx = 20; const swipeThresholdPx = 20;


class GestureStateMachine { class GestureStateMachine {
constructor(handlers) { constructor(handlers, swipeDisabledNodeIds) {
this.handlers = handlers; this.handlers = handlers;
this.swipeDisabledNodeIds = swipeDisabledNodeIds;


this.swiping = false; this.swiping = false;
this.startX = null; this.startX = null;
this._swipeDisabledForGesture = false;
} }


_maybeCancelLongPress() { _maybeCancelLongPress() {
Expand Down Expand Up @@ -88,8 +90,12 @@ class GestureStateMachine {
*/ */
onTouchStart(getId, pageX) { onTouchStart(getId, pageX) {
this.startX = pageX; this.startX = pageX;
const startingNode = getId();


this._onFocus(getId()); this._swipeDisabledForGesture =
this.swipeDisabledNodeIds.includes(startingNode);

this._onFocus(startingNode);
} }


/** /**
Expand All @@ -104,7 +110,7 @@ class GestureStateMachine {
onTouchMove(getId, pageX, swipeEnabled) { onTouchMove(getId, pageX, swipeEnabled) {
const dx = pageX - this.startX; const dx = pageX - this.startX;
const shouldBeginSwiping = !this.swiping && swipeEnabled && const shouldBeginSwiping = !this.swiping && swipeEnabled &&
Math.abs(dx) > swipeThresholdPx; Math.abs(dx) > swipeThresholdPx && !this._swipeDisabledForGesture;


if (this.swiping) { if (this.swiping) {
this.handlers.onSwipeChange(dx); this.handlers.onSwipeChange(dx);
Expand Down Expand Up @@ -155,6 +161,7 @@ class GestureStateMachine {


this.swiping = false; this.swiping = false;
this.startX = null; this.startX = null;
this._swipeDisabledForGesture = false;
} }


/** /**
Expand All @@ -174,6 +181,7 @@ class GestureStateMachine {


this.swiping = false; this.swiping = false;
this.startX = null; this.startX = null;
this._swipeDisabledForGesture = false;
} }
} }


Expand Down
3 changes: 2 additions & 1 deletion src/store/index.js
Expand Up @@ -257,7 +257,8 @@ const createStore = () => {
...layoutProps, ...layoutProps,
}); });
}, },
}); }, [Keys.LEFT, Keys.RIGHT, Keys.BACKSPACE, Keys.DISMISS,
Keys.JUMP_OUT, Keys.MORE, Keys.NUMBERS]);
}; };


const initialGestureState = { const initialGestureState = {
Expand Down

0 comments on commit 1bf10fa

Please sign in to comment.