On refresh opening

This commit is contained in:
Max Lynch
2013-11-08 15:44:22 -06:00
parent 8a7db90aaf
commit 7c4a37e56a
6 changed files with 84 additions and 71 deletions

View File

@ -516,6 +516,9 @@ angular.module('ionic.ui.content', [])
el: $element[0].firstElementChild, el: $element[0].firstElementChild,
onRefresh: function() { onRefresh: function() {
$scope.onRefresh && $scope.onRefresh(); $scope.onRefresh && $scope.onRefresh();
},
onRefreshOpening: function(amt) {
$scope.onRefreshOpening && $scope.onRefreshOpening({amount: amt});
} }
}); });
// Let child scopes access this // Let child scopes access this

72
dist/js/ionic.js vendored
View File

@ -1836,6 +1836,33 @@ window.ionic = {
(function(ionic) { (function(ionic) {
ionic.Utils = { ionic.Utils = {
throttle: function(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
options || (options = {});
var later = function() {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
result = func.apply(context, args);
};
return function() {
var now = Date.now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0) {
clearTimeout(timeout);
timeout = null;
previous = now;
result = func.apply(context, args);
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
},
// Borrowed from Backbone.js's extend // Borrowed from Backbone.js's extend
// Helper function to correctly set up the prototype chain, for subclasses. // Helper function to correctly set up the prototype chain, for subclasses.
// Similar to `goog.inherits`, but uses a hash of prototype properties and // Similar to `goog.inherits`, but uses a hash of prototype properties and
@ -1890,6 +1917,7 @@ window.ionic = {
ionic.inherit = ionic.Utils.inherit; ionic.inherit = ionic.Utils.inherit;
ionic.extend = ionic.Utils.extend; ionic.extend = ionic.Utils.extend;
ionic.throttle = ionic.Utils.throttle;
})(window.ionic); })(window.ionic);
; ;
@ -1938,40 +1966,6 @@ window.ionic = {
toiletSeat: 'cubic-bezier(0.05, 0.60, 0.05, 0.60)' toiletSeat: 'cubic-bezier(0.05, 0.60, 0.05, 0.60)'
}; };
/**
* The Pull To Refresh drag operation handles the well-known
* "pull to refresh" concept seen on various apps. This lets
* the user indicate they want to refresh a given list by dragging
* down.
*
* @param {object} opts the options for the pull to refresh drag.
*/
/*
var PullToRefreshDrag = function(opts) {
this.dragThresholdY = opts.dragThresholdY || 10;
this.onRefreshOpening = opts.onRefreshOpening || function() {};
this.onRefresh = opts.onRefresh || function() {};
this.onRefreshHolding = opts.onRefreshHolding || function() {};
this.el = opts.el;
};
PullToRefreshDrag.prototype.end = function(e, doneCallback) {
if(currentHeight > firstChildHeight) {
//this.refreshing();
} else {
// Enable animations
refresher.classList.add('list-refreshing');
refresher.style.height = '0px';
this.onRefresh && _this.onRefresh();
}
this._currentDrag = null;
doneCallback && doneCallback();
};
*/
ionic.views.Scroll = ionic.views.View.inherit({ ionic.views.Scroll = ionic.views.View.inherit({
initialize: function(opts) { initialize: function(opts) {
@ -1998,6 +1992,7 @@ window.ionic = {
refreshEasing: EASING_FUNCTIONS.bounce, refreshEasing: EASING_FUNCTIONS.bounce,
// ms transition time // ms transition time
refreshEasingTime: 400, refreshEasingTime: 400,
refreshOpeningInterval: 100,
// How frequently to fire scroll events in the case of // How frequently to fire scroll events in the case of
// a flick or momentum scroll where the finger is no longer // a flick or momentum scroll where the finger is no longer
@ -2034,6 +2029,13 @@ window.ionic = {
this.y = 0; this.y = 0;
this.x = 0; this.x = 0;
// Create a throttled pull to refresh "opening" function
// which will get called as the refresh "opens" from drag
var refreshOpening = _this.onRefreshOpening;
_this.onRefreshOpening = ionic.throttle(function(ratio) {
refreshOpening && refreshOpening(ratio);
}, 100);
// Listen for drag and release events // Listen for drag and release events
ionic.onGesture('drag', function(e) { ionic.onGesture('drag', function(e) {
_this._handleDrag(e); _this._handleDrag(e);
@ -2533,7 +2535,7 @@ window.ionic = {
} else { } else {
// Trigger refresh open amount // Trigger refresh open amount
var ratio = Math.min(1, newY / _this._refresherHeight); var ratio = Math.min(1, newY / _this._refresherHeight);
_this.onRefreshOpening && _this.onRefreshOpening(ratio); _this.onRefreshOpening(ratio);
} }
// Update the new translated Y point of the container // Update the new translated Y point of the container

View File

@ -49,6 +49,9 @@ angular.module('ionic.ui.content', [])
el: $element[0].firstElementChild, el: $element[0].firstElementChild,
onRefresh: function() { onRefresh: function() {
$scope.onRefresh && $scope.onRefresh(); $scope.onRefresh && $scope.onRefresh();
},
onRefreshOpening: function(amt) {
$scope.onRefreshOpening && $scope.onRefreshOpening({amount: amt});
} }
}); });
// Let child scopes access this // Let child scopes access this

View File

@ -55,7 +55,7 @@
<header class="bar bar-header bar-success"> <header class="bar bar-header bar-success">
<button class="button"><i class="icon ion-home"></i></button> <button class="button"><i class="icon ion-home"></i></button>
</header> </header>
<content on-refresh="onRefresh()" has-header="true" ng-controller="AppCtrl" class="reveal-animation"> <content on-refresh="onRefresh()" on-refresh-opening="onRefreshOpening(amount)" has-header="true" ng-controller="AppCtrl" class="reveal-animation">
<refresher> <refresher>
<div id="refresh-content"> <div id="refresh-content">
<i class="icon ion-ios7-reloading"></i> <i class="icon ion-ios7-reloading"></i>
@ -81,6 +81,9 @@
$scope.onRefresh = function() { $scope.onRefresh = function() {
console.log('On refresh'); console.log('On refresh');
} }
$scope.onRefreshOpening = function(amt) {
console.log('On refresh opening', amt);
}
}) })
</script> </script>
</body> </body>

View File

@ -1,6 +1,33 @@
(function(ionic) { (function(ionic) {
ionic.Utils = { ionic.Utils = {
throttle: function(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
options || (options = {});
var later = function() {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
result = func.apply(context, args);
};
return function() {
var now = Date.now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0) {
clearTimeout(timeout);
timeout = null;
previous = now;
result = func.apply(context, args);
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
},
// Borrowed from Backbone.js's extend // Borrowed from Backbone.js's extend
// Helper function to correctly set up the prototype chain, for subclasses. // Helper function to correctly set up the prototype chain, for subclasses.
// Similar to `goog.inherits`, but uses a hash of prototype properties and // Similar to `goog.inherits`, but uses a hash of prototype properties and
@ -55,5 +82,6 @@
ionic.inherit = ionic.Utils.inherit; ionic.inherit = ionic.Utils.inherit;
ionic.extend = ionic.Utils.extend; ionic.extend = ionic.Utils.extend;
ionic.throttle = ionic.Utils.throttle;
})(window.ionic); })(window.ionic);

View File

@ -29,40 +29,6 @@
toiletSeat: 'cubic-bezier(0.05, 0.60, 0.05, 0.60)' toiletSeat: 'cubic-bezier(0.05, 0.60, 0.05, 0.60)'
}; };
/**
* The Pull To Refresh drag operation handles the well-known
* "pull to refresh" concept seen on various apps. This lets
* the user indicate they want to refresh a given list by dragging
* down.
*
* @param {object} opts the options for the pull to refresh drag.
*/
/*
var PullToRefreshDrag = function(opts) {
this.dragThresholdY = opts.dragThresholdY || 10;
this.onRefreshOpening = opts.onRefreshOpening || function() {};
this.onRefresh = opts.onRefresh || function() {};
this.onRefreshHolding = opts.onRefreshHolding || function() {};
this.el = opts.el;
};
PullToRefreshDrag.prototype.end = function(e, doneCallback) {
if(currentHeight > firstChildHeight) {
//this.refreshing();
} else {
// Enable animations
refresher.classList.add('list-refreshing');
refresher.style.height = '0px';
this.onRefresh && _this.onRefresh();
}
this._currentDrag = null;
doneCallback && doneCallback();
};
*/
ionic.views.Scroll = ionic.views.View.inherit({ ionic.views.Scroll = ionic.views.View.inherit({
initialize: function(opts) { initialize: function(opts) {
@ -89,6 +55,7 @@
refreshEasing: EASING_FUNCTIONS.bounce, refreshEasing: EASING_FUNCTIONS.bounce,
// ms transition time // ms transition time
refreshEasingTime: 400, refreshEasingTime: 400,
refreshOpeningInterval: 100,
// How frequently to fire scroll events in the case of // How frequently to fire scroll events in the case of
// a flick or momentum scroll where the finger is no longer // a flick or momentum scroll where the finger is no longer
@ -125,6 +92,13 @@
this.y = 0; this.y = 0;
this.x = 0; this.x = 0;
// Create a throttled pull to refresh "opening" function
// which will get called as the refresh "opens" from drag
var refreshOpening = _this.onRefreshOpening;
_this.onRefreshOpening = ionic.throttle(function(ratio) {
refreshOpening && refreshOpening(ratio);
}, 100);
// Listen for drag and release events // Listen for drag and release events
ionic.onGesture('drag', function(e) { ionic.onGesture('drag', function(e) {
_this._handleDrag(e); _this._handleDrag(e);
@ -624,7 +598,7 @@
} else { } else {
// Trigger refresh open amount // Trigger refresh open amount
var ratio = Math.min(1, newY / _this._refresherHeight); var ratio = Math.min(1, newY / _this._refresherHeight);
_this.onRefreshOpening && _this.onRefreshOpening(ratio); _this.onRefreshOpening(ratio);
} }
// Update the new translated Y point of the container // Update the new translated Y point of the container