Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

HardwareBackButton support #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions ionic.contrib.drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
*/
angular.module('ionic.contrib.drawer', ['ionic'])

.controller('drawerCtrl', ['$element', '$attrs', '$ionicGesture', '$document', function($element, $attr, $ionicGesture, $document) {
.controller('drawerCtrl', ['$element', '$attrs', '$ionicGesture', '$document', '$ionicPlatform', function($element, $attr, $ionicGesture, $document, $ionicPlatform) {
var el = $element[0];
var dragging = false;
var startX, lastX, offsetX, newX;
var side;

// Handle back button
var unregisterBackAction;

// How far to drag before triggering
var thresholdX = 15;
// How far from edge before triggering
Expand Down Expand Up @@ -106,7 +109,7 @@ angular.module('ionic.contrib.drawer', ['ionic'])
startTargetDrag(e);
} else if(startX < edgeX) {
startDrag(e);
}
}
}
} else {
console.log(lastX, offsetX, lastX - offsetX);
Expand All @@ -132,6 +135,10 @@ angular.module('ionic.contrib.drawer', ['ionic'])
doEndDrag(e);
}, $document);

var hardwareBackCallback = function() {
this.close();
}.bind(this);


this.close = function() {
enableAnimation();
Expand All @@ -142,6 +149,9 @@ angular.module('ionic.contrib.drawer', ['ionic'])
el.style.transform = el.style.webkitTransform = 'translate3d(100%, 0, 0)';
}
});
if (unregisterBackAction) {
unregisterBackAction();
}
};

this.open = function() {
Expand All @@ -153,6 +163,7 @@ angular.module('ionic.contrib.drawer', ['ionic'])
el.style.transform = el.style.webkitTransform = 'translate3d(0%, 0, 0)';
}
});
unregisterBackAction = $ionicPlatform.registerBackButtonAction(hardwareBackCallback, 100);
};
}])

Expand Down