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

Commit 45deab0

Browse files
committed
refactor(toast): use hammer more efficiently with limited recognizers
1 parent 15d93b4 commit 45deab0

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/components/toast/toast.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ function QpToastService($timeout, $rootScope, $materialCompiler, $rootElement, $
9696
toastParent = $rootElement;
9797
}
9898

99-
// Which swipe events to listen for, depending on the toast's position
100-
var positionSwipeEvents = {
101-
top: 'swipeleft swiperight swipeup',
102-
bottom: 'swipeleft swiperight swipedown'
103-
};
104-
10599
return showToast;
106100

107101
/**
@@ -139,13 +133,15 @@ function QpToastService($timeout, $rootScope, $materialCompiler, $rootElement, $
139133
}
140134
});
141135

142-
var isTop = options.position.indexOf('top') > -1;
143-
var swipeEvents = positionSwipeEvents[isTop ? 'top' : 'bottom'];
144-
var mc = new Hammer(element[0]);
145-
mc.on(swipeEvents, onSwipe);
136+
var hammer = new Hammer(element[0], {
137+
recognizers: [
138+
[Hammer.Swipe, { direction: Hammer.DIRECTION_HORIZONTAL }]
139+
]
140+
});
141+
hammer.on('swipeleft swiperight', onSwipe);
146142

147143
function onSwipe(ev) {
148-
//Add swipeleft/swiperight/swipeup/swipedown class to element
144+
//Add swipeleft/swiperight class to element so it can animate correctly
149145
element.addClass(ev.type);
150146
$timeout(destroy);
151147
}
@@ -156,7 +152,7 @@ function QpToastService($timeout, $rootScope, $materialCompiler, $rootElement, $
156152
if (destroy.called) return;
157153
destroy.called = true;
158154

159-
mc.destroy();
155+
hammer.destroy();
160156
toastParent.removeClass(toastParentClass);
161157
$timeout.cancel(delayTimeout);
162158
$animate.leave(element, function() {

0 commit comments

Comments
 (0)