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

Commit

Permalink
refactor(toast): use hammer more efficiently with limited recognizers
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Sep 12, 2014
1 parent 15d93b4 commit 45deab0
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/components/toast/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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.

Copy link
@ThomasBurleson

ThomasBurleson Sep 12, 2014

Contributor

We should provide a comment link to Hammer docs that discuss recognizers

This comment has been minimized.

Copy link
@ajoslin

ajoslin Sep 12, 2014

Author Contributor

The developer should know to look up the API for a library that he does not recognize.

This comment has been minimized.

Copy link
@ajoslin

ajoslin Sep 12, 2014

Author Contributor

Just like we aren't leaving a comment to angular docs for what .factory does.

This comment has been minimized.

Copy link
@ThomasBurleson

ThomasBurleson Sep 12, 2014

Contributor

Final thoughts on this:

Totally agree for AngularJS since this is an ng SDK. And I also agree with same regarding LoDash usages.

For custom libs, however, that play significant roles I think a @see .... link may make sense.

[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);
}
Expand All @@ -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() {
Expand Down

0 comments on commit 45deab0

Please sign in to comment.