mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(ionNavBackButton): stop flicker when pressing back on ios
This commit is contained in:
3
js/angular/controller/navBarController.js
vendored
3
js/angular/controller/navBarController.js
vendored
@@ -25,10 +25,9 @@ function($scope, $element, $attrs, $ionicViewService, $animate, $compile, $ionic
|
||||
$element[0].querySelector('.buttons.right-buttons')
|
||||
);
|
||||
|
||||
this.back = function(e) {
|
||||
this.back = function() {
|
||||
var backView = $ionicViewService.getBackView();
|
||||
backView && backView.go();
|
||||
e && (e.alreadyHandled = true);
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
19
js/angular/directive/navBackButton.js
vendored
19
js/angular/directive/navBackButton.js
vendored
@@ -65,10 +65,9 @@ IonicModule
|
||||
'$animate',
|
||||
'$rootScope',
|
||||
'$sanitize',
|
||||
|
||||
'$ionicNavBarConfig',
|
||||
|
||||
function($animate, $rootScope, $sanitize, $ionicNavBarConfig) {
|
||||
'$ionicNgClick',
|
||||
function($animate, $rootScope, $sanitize, $ionicNavBarConfig, $ionicNgClick) {
|
||||
var backIsShown = false;
|
||||
//If the current viewstate does not allow a back button,
|
||||
//always hide it.
|
||||
@@ -80,23 +79,19 @@ function($animate, $rootScope, $sanitize, $ionicNavBarConfig) {
|
||||
require: '^ionNavBar',
|
||||
compile: function(tElement, tAttrs) {
|
||||
tElement.addClass('button back-button ng-hide');
|
||||
|
||||
|
||||
return function($scope, $element, $attr, navBarCtrl) {
|
||||
console.log($attr.textFromTitle);
|
||||
|
||||
// Add a default back button icon based on the nav config, unless one is set
|
||||
if($element[0].className.indexOf('ion-') < 0) {
|
||||
$element.addClass($ionicNavBarConfig.backButtonIcon);
|
||||
}
|
||||
|
||||
if (!$attr.ngClick) {
|
||||
$scope.$navBack = navBarCtrl.back;
|
||||
$element.on('click', function(event){
|
||||
$scope.$apply(function() {
|
||||
$scope.$navBack(event);
|
||||
});
|
||||
});
|
||||
//Default to ngClick going back, but don't override a custom one
|
||||
if (!isDefined($attr.ngClick)) {
|
||||
$ionicNgClick($scope, $element, navBarCtrl.back);
|
||||
}
|
||||
|
||||
//Make sure both that a backButton is allowed in the first place,
|
||||
//and that it is shown by the current view.
|
||||
$scope.$watch(function() {
|
||||
|
||||
4
js/angular/directive/ngClick.js
vendored
4
js/angular/directive/ngClick.js
vendored
@@ -13,7 +13,9 @@ IonicModule
|
||||
*/
|
||||
.factory('$ionicNgClick', ['$parse', function($parse) {
|
||||
return function(scope, element, clickExpr) {
|
||||
var clickHandler = $parse(clickExpr);
|
||||
var clickHandler = angular.isFunction(clickExpr) ?
|
||||
clickExpr :
|
||||
$parse(clickExpr);
|
||||
|
||||
element.on('click', function(event) {
|
||||
scope.$apply(function() {
|
||||
|
||||
0
test/html/list-simple.html
Normal file
0
test/html/list-simple.html
Normal file
@@ -1,4 +1,3 @@
|
||||
|
||||
describe('ionNavBackButton directive', function() {
|
||||
beforeEach(module('ionic'));
|
||||
|
||||
@@ -62,11 +61,11 @@ describe('ionNavBackButton directive', function() {
|
||||
expect(el.children().eq(0)[0].tagName.toLowerCase()).toBe('b');
|
||||
});
|
||||
|
||||
it('should $navBack on click by default', function() {
|
||||
it('should go back on click by default', function() {
|
||||
var el = setup();
|
||||
el.scope().$navBack = jasmine.createSpy('$navBack');
|
||||
expect(el.controller('ionNavBar').back).not.toHaveBeenCalled();
|
||||
el.triggerHandler('click');
|
||||
expect(el.scope().$navBack).toHaveBeenCalled();
|
||||
expect(el.controller('ionNavBar').back).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should do ngClick expression if defined', function() {
|
||||
@@ -80,7 +79,7 @@ describe('ionNavBackButton directive', function() {
|
||||
|
||||
|
||||
describe('ionNavBackButton directive: Platforms', function() {
|
||||
describe('ionNavBackButton directive: iOS Platform', function() {
|
||||
describe('ionNavBackButton directive: iOS Platform', function() {
|
||||
beforeEach(function($provide) {
|
||||
TestUtil.setPlatform('ios');
|
||||
});
|
||||
|
||||
@@ -49,11 +49,9 @@ describe('ionNavBar', function() {
|
||||
|
||||
it('should go back', inject(function($ionicViewService) {
|
||||
var ctrl = setup();
|
||||
var e = { alreadyHandled: false };
|
||||
ctrl.back(e);
|
||||
ctrl.back();
|
||||
expect($ionicViewService.getBackView).toHaveBeenCalled();
|
||||
expect(backView.go).toHaveBeenCalled();
|
||||
expect(e.alreadyHandled).toBe(true);
|
||||
}));
|
||||
|
||||
it('should align', function() {
|
||||
@@ -308,7 +306,7 @@ describe('ionNavBar', function() {
|
||||
describe('iOS', function() {
|
||||
beforeEach(module('ionic', function($provide) {
|
||||
TestUtil.setPlatform('ios');
|
||||
$provide.constant('$ionicNavBarConfig', {
|
||||
$provide.constant('$ionicNavBarConfig', {
|
||||
alignTitle: 'center',
|
||||
transition: 'nav-title-slide-ios7',
|
||||
backButtonIcon: 'ion-ios7-arrow-back'
|
||||
@@ -330,7 +328,7 @@ describe('ionNavBar', function() {
|
||||
describe('Android', function() {
|
||||
beforeEach(module('ionic', function($provide) {
|
||||
TestUtil.setPlatform('android');
|
||||
$provide.constant('$ionicNavBarConfig', {
|
||||
$provide.constant('$ionicNavBarConfig', {
|
||||
alignTitle: 'left',
|
||||
transition: 'no-animation',
|
||||
backButtonIcon: 'ion-android-back'
|
||||
|
||||
Reference in New Issue
Block a user