Fixed #366 - no Android scroll bouncing by default

This commit is contained in:
Max Lynch
2014-01-10 09:52:32 -06:00
parent c0cee27747
commit cb75c9de96
8 changed files with 66 additions and 11 deletions

View File

@@ -333,9 +333,10 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ngAnimate'
return modal;
},
fromTemplateUrl: function(url, cb, options) {
TemplateLoader.load(url).then(function(templateString) {
return TemplateLoader.load(url).then(function(templateString) {
var modal = createModal(templateString, options || {});
cb(modal);
cb ? cb(modal) : null;
return modal;
});
},
};
@@ -409,6 +410,10 @@ angular.module('ionic.service.platform', [])
});
},
is: function(type) {
return ionic.Platform.is(type);
},
/**
* Trigger a callback once the device is ready, or immediately if the device is already
* ready.
@@ -724,7 +729,7 @@ angular.module('ionic.ui.content', ['ionic.ui.service'])
// The content directive is a core scrollable content area
// that is part of many View hierarchies
.directive('content', ['$parse', '$timeout', 'ScrollDelegate', function($parse, $timeout, ScrollDelegate) {
.directive('content', ['$parse', '$timeout', 'Platform', 'ScrollDelegate', function($parse, $timeout, Platform, ScrollDelegate) {
return {
restrict: 'E',
replace: true,
@@ -738,6 +743,7 @@ angular.module('ionic.ui.content', ['ionic.ui.service'])
refreshComplete: '=',
onInfiniteScroll: '=',
infiniteScrollDistance: '@',
hasBouncing: '@',
scroll: '@',
hasScrollX: '@',
hasScrollY: '@',
@@ -793,8 +799,13 @@ angular.module('ionic.ui.content', ['ionic.ui.service'])
// Otherwise, supercharge this baby!
$timeout(function() {
var hasBouncing = $scope.$eval($scope.hasBouncing);
var enableBouncing = !Platform.is('Android') && hasBouncing !== false;
// No bouncing by default for Android users, lest they take up pitchforks
// to our bouncing goodness
sv = new ionic.views.Scroll({
el: $element[0],
bouncing: enableBouncing,
scrollbarX: $scope.$eval($scope.scrollbarX) !== false,
scrollbarY: $scope.$eval($scope.scrollbarY) !== false,
scrollingX: $scope.$eval($scope.hasScrollX) === true,

View File

File diff suppressed because one or more lines are too long

12
dist/js/ionic.js vendored
View File

@@ -1789,7 +1789,17 @@ window.ionic = {
if(!window.device) {
return navigator.userAgent.toLowerCase().indexOf('android') >= 0;
}
return device.platform === "Android";
return window.device.platform === "Android";
},
// Check if the platform is the one detected by cordova
is: function(type) {
if(window.device) {
return window.device.platform === type || window.device.platform.toLowerCase() === type;
}
// A quick hack for
return navigator.userAgent.toLowerCase().indexOf(type.toLowerCase()) >= 0;
}
};

View File

File diff suppressed because one or more lines are too long

View File

@@ -18,7 +18,7 @@ angular.module('ionic.ui.content', ['ionic.ui.service'])
// The content directive is a core scrollable content area
// that is part of many View hierarchies
.directive('content', ['$parse', '$timeout', 'ScrollDelegate', function($parse, $timeout, ScrollDelegate) {
.directive('content', ['$parse', '$timeout', 'Platform', 'ScrollDelegate', function($parse, $timeout, Platform, ScrollDelegate) {
return {
restrict: 'E',
replace: true,
@@ -32,6 +32,7 @@ angular.module('ionic.ui.content', ['ionic.ui.service'])
refreshComplete: '=',
onInfiniteScroll: '=',
infiniteScrollDistance: '@',
hasBouncing: '@',
scroll: '@',
hasScrollX: '@',
hasScrollY: '@',
@@ -87,8 +88,13 @@ angular.module('ionic.ui.content', ['ionic.ui.service'])
// Otherwise, supercharge this baby!
$timeout(function() {
var hasBouncing = $scope.$eval($scope.hasBouncing);
var enableBouncing = !Platform.is('Android') && hasBouncing !== false;
// No bouncing by default for Android users, lest they take up pitchforks
// to our bouncing goodness
sv = new ionic.views.Scroll({
el: $element[0],
bouncing: enableBouncing,
scrollbarX: $scope.$eval($scope.scrollbarX) !== false,
scrollbarY: $scope.$eval($scope.scrollbarY) !== false,
scrollingX: $scope.$eval($scope.hasScrollX) === true,

View File

@@ -66,6 +66,10 @@ angular.module('ionic.service.platform', [])
});
},
is: function(type) {
return ionic.Platform.is(type);
},
/**
* Trigger a callback once the device is ready, or immediately if the device is already
* ready.

View File

@@ -1,11 +1,13 @@
describe('Ionic Content directive', function() {
var compile, element, scope;
beforeEach(module('ionic.ui.content'));
beforeEach(module('ionic'));
beforeEach(inject(function($compile, $rootScope) {
beforeEach(inject(function($compile, $rootScope, $timeout, $window) {
compile = $compile;
scope = $rootScope;
timeout = $timeout;
window = $window;
}));
it('Has content class', function() {
@@ -17,4 +19,16 @@ describe('Ionic Content directive', function() {
element = compile('<content has-header="true"></content>')(scope);
expect(element.hasClass('has-header')).toEqual(true);
});
/**
* Not currently possible to mock this AFAIK
*/
xit('Disables bouncing by default on Android', function() {
window.navigator.userAgent = 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';
element = compile('<content has-header="true"></content>')(scope);
timeout.flush();
var newScope = element.isolateScope();
var scrollView = scope.scrollView;
expect(scrollView.options.bouncing).toBe(false);
});
});

View File

@@ -53,7 +53,17 @@
if(!window.device) {
return navigator.userAgent.toLowerCase().indexOf('android') >= 0;
}
return device.platform === "Android";
return window.device.platform === "Android";
},
// Check if the platform is the one detected by cordova
is: function(type) {
if(window.device) {
return window.device.platform === type || window.device.platform.toLowerCase() === type;
}
// A quick hack for
return navigator.userAgent.toLowerCase().indexOf(type.toLowerCase()) >= 0;
}
};