This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(toast): use hammer more efficiently with limited recognizers
- Loading branch information
Showing
1 changed file
with
8 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,12 +96,6 @@ function QpToastService($timeout, $rootScope, $materialCompiler, $rootElement, $ | |
toastParent = $rootElement; | ||
} | ||
|
||
// Which swipe events to listen for, depending on the toast's position | ||
var positionSwipeEvents = { | ||
top: 'swipeleft swiperight swipeup', | ||
bottom: 'swipeleft swiperight swipedown' | ||
}; | ||
|
||
return showToast; | ||
|
||
/** | ||
|
@@ -139,13 +133,15 @@ function QpToastService($timeout, $rootScope, $materialCompiler, $rootElement, $ | |
} | ||
}); | ||
|
||
var isTop = options.position.indexOf('top') > -1; | ||
var swipeEvents = positionSwipeEvents[isTop ? 'top' : 'bottom']; | ||
var mc = new Hammer(element[0]); | ||
mc.on(swipeEvents, onSwipe); | ||
var hammer = new Hammer(element[0], { | ||
recognizers: [ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ajoslin
Author
Contributor
|
||
[Hammer.Swipe, { direction: Hammer.DIRECTION_HORIZONTAL }] | ||
] | ||
}); | ||
hammer.on('swipeleft swiperight', onSwipe); | ||
|
||
function onSwipe(ev) { | ||
//Add swipeleft/swiperight/swipeup/swipedown class to element | ||
//Add swipeleft/swiperight class to element so it can animate correctly | ||
element.addClass(ev.type); | ||
$timeout(destroy); | ||
} | ||
|
@@ -156,7 +152,7 @@ function QpToastService($timeout, $rootScope, $materialCompiler, $rootElement, $ | |
if (destroy.called) return; | ||
destroy.called = true; | ||
|
||
mc.destroy(); | ||
hammer.destroy(); | ||
toastParent.removeClass(toastParentClass); | ||
$timeout.cancel(delayTimeout); | ||
$animate.leave(element, function() { | ||
|
We should provide a comment link to Hammer docs that discuss
recognizers