mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(scroll): make refresher be detected after timeout
This commit is contained in:
@@ -10,8 +10,9 @@ angular.module('ionic.ui.scroll')
|
||||
scrollViewOptions.bouncing :
|
||||
!ionic.Platform.isAndroid();
|
||||
|
||||
var self = this;
|
||||
|
||||
var element = this.element = scrollViewOptions.el;
|
||||
var refresher = this.refresher = element.querySelector('.scroll-refresher');
|
||||
var scrollView = this.scrollView = new ionic.views.Scroll(scrollViewOptions);
|
||||
|
||||
this.$element = angular.element(element);
|
||||
@@ -23,16 +24,18 @@ angular.module('ionic.ui.scroll')
|
||||
$timeout(function() {
|
||||
scrollView.run();
|
||||
|
||||
self.refresher = element.querySelector('.scroll-refresher');
|
||||
|
||||
// Activate pull-to-refresh
|
||||
if(refresher) {
|
||||
var refresherHeight = refresher.clientHeight || 0;
|
||||
if(self.refresher) {
|
||||
var refresherHeight = self.refresher.clientHeight || 0;
|
||||
scrollView.activatePullToRefresh(refresherHeight, function() {
|
||||
refresher.classList.add('active');
|
||||
self.refresher.classList.add('active');
|
||||
}, function() {
|
||||
refresher.classList.remove('refreshing');
|
||||
refresher.classList.remove('active');
|
||||
self.refresher.classList.remove('refreshing');
|
||||
self.refresher.classList.remove('active');
|
||||
}, function() {
|
||||
refresher.classList.add('refreshing');
|
||||
self.refresher.classList.add('refreshing');
|
||||
$scope.onRefresh && $scope.onRefresh();
|
||||
$scope.$parent.$broadcast('scroll.onRefresh');
|
||||
});
|
||||
|
||||
@@ -43,12 +43,21 @@ describe('$ionicScroll Controller', function() {
|
||||
|
||||
it('should not setup if no child .scroll-refresher', function() {
|
||||
setup();
|
||||
timeout.flush();
|
||||
expect(ctrl.refresher).toBeFalsy();
|
||||
spyOn(ctrl.scrollView, 'activatePullToRefresh');
|
||||
timeout.flush();
|
||||
expect(ctrl.scrollView.activatePullToRefresh).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not setup ctrl.refresher until after timeout', function() {
|
||||
setup({
|
||||
el: angular.element('<div><div class="scroll-refresher"></div></div>')[0]
|
||||
});
|
||||
expect(ctrl.refresher).toBeUndefined();
|
||||
timeout.flush();
|
||||
expect(ctrl.refresher).toBe(ctrl.element.children[0]);
|
||||
});
|
||||
|
||||
it('should work with .scroll-refresher child and proper refresher', function() {
|
||||
var startCb, refreshingCb, doneCb, refresherEl;
|
||||
setup({
|
||||
@@ -59,12 +68,12 @@ describe('$ionicScroll Controller', function() {
|
||||
refreshingCb = refreshing;
|
||||
doneCb = done;
|
||||
});
|
||||
|
||||
|
||||
scope.onRefresh = jasmine.createSpy('onRefresh');
|
||||
scope.$parent.$broadcast = jasmine.createSpy('$broadcast');
|
||||
var refresher = ctrl.refresher;
|
||||
|
||||
timeout.flush();
|
||||
var refresher = ctrl.refresher;
|
||||
|
||||
expect(refresher.classList.contains('active')).toBe(false);
|
||||
expect(refresher.classList.contains('refreshing')).toBe(false);
|
||||
|
||||
Reference in New Issue
Block a user