From 098020e51166607e2e1148b5ed0b0406656e45c4 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Wed, 11 Dec 2013 17:07:10 -0600 Subject: [PATCH] Fixed #315 - scroll size waiting --- dist/css/ionic.css | 6 +- dist/js/ionic-angular.js | 14 +++ dist/js/ionic.js | 23 ++++ js/ext/angular/src/directive/ionicContent.js | 7 ++ js/ext/angular/src/directive/ionicScroll.js | 7 ++ js/ext/angular/test/content.html | 1 + js/ext/angular/test/content_defer.html | 111 +++++++++++++++++++ js/views/scrollView.js | 23 ++++ scss/_scaffolding.scss | 6 +- 9 files changed, 192 insertions(+), 6 deletions(-) create mode 100644 js/ext/angular/test/content_defer.html diff --git a/dist/css/ionic.css b/dist/css/ionic.css index ccecfa004d..36da08e541 100644 --- a/dist/css/ionic.css +++ b/dist/css/ionic.css @@ -2611,7 +2611,7 @@ body, .ionic-body { height: 3px; left: 2px; right: 2px; - bottom: 0; } + bottom: 3px; } .scroll-bar-h .scroll-bar-indicator { height: 100%; } @@ -2619,14 +2619,14 @@ body, .ionic-body { width: 3px; bottom: 2px; top: 2px; - right: 1px; } + right: 3px; } .scroll-bar-v .scroll-bar-indicator { width: 100%; } .scroll-bar-indicator { position: absolute; background: rgba(0, 0, 0, 0.3); - border-radius: 2px; } + border-radius: 4px; } .scroll-refresher { overflow: hidden; diff --git a/dist/js/ionic-angular.js b/dist/js/ionic-angular.js index f798adbcd2..f1a3f5157a 100644 --- a/dist/js/ionic-angular.js +++ b/dist/js/ionic-angular.js @@ -747,6 +747,13 @@ angular.module('ionic.ui.content', []) }); }); + $scope.$parent.$on('scroll.resize', function(e) { + // Run the resize after this digest + $timeout(function() { + sv && sv.resize(); + }) + }); + $scope.$parent.$on('scroll.refreshComplete', function(e) { sv && sv.finishPullToRefresh(); }); @@ -1657,6 +1664,13 @@ angular.module('ionic.ui.scroll', []) }); }); + $scope.$parent.$on('scroll.resize', function(e) { + // Run the resize after this digest + $timeout(function() { + sv && sv.resize(); + }) + }); + $scope.$parent.$on('scroll.refreshComplete', function(e) { sv && sv.finishPullToRefresh(); }); diff --git a/dist/js/ionic.js b/dist/js/ionic.js index 4f52b0a966..a5fd4984b8 100644 --- a/dist/js/ionic.js +++ b/dist/js/ionic.js @@ -2614,6 +2614,9 @@ ionic.views.Scroll = ionic.views.View.inherit({ __indicatorX: null, __indicatorY: null, + /** {Boolean} whether we've tried to wait for size already */ + __didWaitForSize: null, + __sizerTimeout: null, __initEventHandlers: function() { var self = this; @@ -3787,9 +3790,29 @@ ionic.views.Scroll = ionic.views.View.inherit({ self.__maxScrollLeft = Math.max((self.__contentWidth * zoomLevel) - self.__clientWidth, 0); self.__maxScrollTop = Math.max((self.__contentHeight * zoomLevel) - self.__clientHeight, 0); + if(!self.__didWaitForSize && self.__maxScrollLeft == 0 && self.__maxScrollTop == 0) { + self.__didWaitForSize = true; + self.__waitForSize(); + } }, + /** + * If the scroll view isn't sized correctly on start, wait until we have at least some size + */ + __waitForSize: function() { + + var self = this; + + clearTimeout(self.__sizerTimeout); + self.__sizerTimeout = setTimeout(function sizer() { + self.resize(); + if(self.__maxScrollLeft == 0 && self.__maxScrollTop == 0) { + self.__sizerTimeout = setTimeout(sizer, 1000); + } + }, 1000); + + }, /* --------------------------------------------------------------------------- diff --git a/js/ext/angular/src/directive/ionicContent.js b/js/ext/angular/src/directive/ionicContent.js index 1ea68c8e41..2af52e4826 100644 --- a/js/ext/angular/src/directive/ionicContent.js +++ b/js/ext/angular/src/directive/ionicContent.js @@ -123,6 +123,13 @@ angular.module('ionic.ui.content', []) }); }); + $scope.$parent.$on('scroll.resize', function(e) { + // Run the resize after this digest + $timeout(function() { + sv && sv.resize(); + }) + }); + $scope.$parent.$on('scroll.refreshComplete', function(e) { sv && sv.finishPullToRefresh(); }); diff --git a/js/ext/angular/src/directive/ionicScroll.js b/js/ext/angular/src/directive/ionicScroll.js index 2413d13585..b2c2d8f067 100644 --- a/js/ext/angular/src/directive/ionicScroll.js +++ b/js/ext/angular/src/directive/ionicScroll.js @@ -84,6 +84,13 @@ angular.module('ionic.ui.scroll', []) }); }); + $scope.$parent.$on('scroll.resize', function(e) { + // Run the resize after this digest + $timeout(function() { + sv && sv.resize(); + }) + }); + $scope.$parent.$on('scroll.refreshComplete', function(e) { sv && sv.finishPullToRefresh(); }); diff --git a/js/ext/angular/test/content.html b/js/ext/angular/test/content.html index 6efd2e6a4d..2778614bf5 100644 --- a/js/ext/angular/test/content.html +++ b/js/ext/angular/test/content.html @@ -116,6 +116,7 @@ $scope.onScrollComplete = function(event, scrollTop, scrollLeft) { console.log('Scroll complete', scrollTop, scrollLeft); } + var last = 0; $scope.onScroll = function(event, scrollTop, scrollLeft) { /* if(scrollTop > startTop) { diff --git a/js/ext/angular/test/content_defer.html b/js/ext/angular/test/content_defer.html new file mode 100644 index 0000000000..fede62bd27 --- /dev/null +++ b/js/ext/angular/test/content_defer.html @@ -0,0 +1,111 @@ + + + + Content + + + + + + + + + + + + + + + + + + +
{{$index}}
+
+ + +
+ + + + + diff --git a/js/views/scrollView.js b/js/views/scrollView.js index 1f061dcce1..64a7950170 100644 --- a/js/views/scrollView.js +++ b/js/views/scrollView.js @@ -547,6 +547,9 @@ ionic.views.Scroll = ionic.views.View.inherit({ __indicatorX: null, __indicatorY: null, + /** {Boolean} whether we've tried to wait for size already */ + __didWaitForSize: null, + __sizerTimeout: null, __initEventHandlers: function() { var self = this; @@ -1720,9 +1723,29 @@ ionic.views.Scroll = ionic.views.View.inherit({ self.__maxScrollLeft = Math.max((self.__contentWidth * zoomLevel) - self.__clientWidth, 0); self.__maxScrollTop = Math.max((self.__contentHeight * zoomLevel) - self.__clientHeight, 0); + if(!self.__didWaitForSize && self.__maxScrollLeft == 0 && self.__maxScrollTop == 0) { + self.__didWaitForSize = true; + self.__waitForSize(); + } }, + /** + * If the scroll view isn't sized correctly on start, wait until we have at least some size + */ + __waitForSize: function() { + + var self = this; + + clearTimeout(self.__sizerTimeout); + self.__sizerTimeout = setTimeout(function sizer() { + self.resize(); + if(self.__maxScrollLeft == 0 && self.__maxScrollTop == 0) { + self.__sizerTimeout = setTimeout(sizer, 1000); + } + }, 1000); + + }, /* --------------------------------------------------------------------------- diff --git a/scss/_scaffolding.scss b/scss/_scaffolding.scss index 15f2ee57ca..78af8f29b1 100644 --- a/scss/_scaffolding.scss +++ b/scss/_scaffolding.scss @@ -112,7 +112,7 @@ body, .ionic-body { height: 3px; left: 2px; right: 2px; - bottom: 0; + bottom: 3px; .scroll-bar-indicator { height: 100%; @@ -123,7 +123,7 @@ body, .ionic-body { width: 3px; bottom: 2px; top: 2px; - right: 1px; + right: 3px; .scroll-bar-indicator { width: 100%; @@ -132,7 +132,7 @@ body, .ionic-body { .scroll-bar-indicator { position: absolute; background:rgba(0,0,0,0.3); - border-radius: 2px; + border-radius: 4px; }