mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(collectionRepeat): restore scrollView's normal behavior when repeater is destroyed
Closes #2078.
This commit is contained in:
38
js/angular/directive/collectionRepeat.js
vendored
38
js/angular/directive/collectionRepeat.js
vendored
@@ -406,6 +406,21 @@ function RepeatManagerFactory($rootScope, $window, $$rAF) {
|
||||
(isGridView ? GridViewType : ListViewType).call(view);
|
||||
(isStaticView ? StaticViewType : DynamicViewType).call(view);
|
||||
|
||||
var contentSizeStr = isVertical ? 'getContentHeight' : 'getContentWidth';
|
||||
var originalGetContentSize = scrollView.options[contentSizeStr];
|
||||
scrollView.options[contentSizeStr] = angular.bind(view, view.getContentSize);
|
||||
|
||||
scrollView.__$callback = scrollView.__callback;
|
||||
scrollView.__callback = function(transformLeft, transformTop, zoom, wasResize) {
|
||||
var scrollValue = view.getScrollValue();
|
||||
if (renderStartIndex === -1 ||
|
||||
scrollValue + view.scrollPrimarySize > renderAfterBoundary ||
|
||||
scrollValue < renderBeforeBoundary) {
|
||||
render();
|
||||
}
|
||||
scrollView.__$callback(transformLeft, transformTop, zoom, wasResize);
|
||||
};
|
||||
|
||||
var isLayoutReady = false;
|
||||
var isDataReady = false;
|
||||
this.refreshLayout = function(itemsAfterRepeater) {
|
||||
@@ -448,6 +463,8 @@ function RepeatManagerFactory($rootScope, $window, $$rAF) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
this.refreshData = function(newData) {
|
||||
newData || (newData = []);
|
||||
|
||||
@@ -471,7 +488,6 @@ function RepeatManagerFactory($rootScope, $window, $$rAF) {
|
||||
render.destroyed = true;
|
||||
unwatch();
|
||||
|
||||
scrollView.__calback = scrollView.__$callback;
|
||||
itemsPool.forEach(function(item) {
|
||||
item.scope.$destroy();
|
||||
item.scope = item.element = item.node = item.images = null;
|
||||
@@ -479,24 +495,14 @@ function RepeatManagerFactory($rootScope, $window, $$rAF) {
|
||||
itemsPool.length = itemsEntering.length = itemsLeaving.length = 0;
|
||||
itemsShownMap = {};
|
||||
|
||||
//Restore the scrollView's normal behavior and resize it to normal size.
|
||||
scrollView.options[contentSizeStr] = originalGetContentSize;
|
||||
scrollView.__callback = scrollView.__$callback;
|
||||
scrollView.resize();
|
||||
|
||||
(view.onDestroy || angular.noop)();
|
||||
};
|
||||
|
||||
scrollView.options[isVertical ? 'getContentHeight' : 'getContentWidth'] =
|
||||
angular.bind(view, view.getContentSize);
|
||||
|
||||
scrollView.__$callback = scrollView.__callback;
|
||||
scrollView.__callback = function(transformLeft, transformTop, zoom, wasResize) {
|
||||
var scrollValue = view.getScrollValue();
|
||||
if (renderStartIndex === -1 ||
|
||||
scrollValue + view.scrollPrimarySize > renderAfterBoundary ||
|
||||
scrollValue < renderBeforeBoundary) {
|
||||
render();
|
||||
}
|
||||
scrollView.__$callback(transformLeft, transformTop, zoom, wasResize);
|
||||
};
|
||||
|
||||
|
||||
function forceRerender() {
|
||||
return render(true);
|
||||
}
|
||||
|
||||
@@ -156,14 +156,30 @@ describe('collectionRepeat', function() {
|
||||
}).toThrow();
|
||||
}));
|
||||
|
||||
it('should destroy', inject(function($compile, $rootScope) {
|
||||
it('should destroy and restore normal scrollView behavior', inject(function($compile, $rootScope) {
|
||||
var scope = $rootScope.$new();
|
||||
var content = $compile('<ion-content>' +
|
||||
'<div collection-repeat="item in items" item-height="5" item-width="5"></div>' +
|
||||
'</ion-content>')(scope);
|
||||
var content = $compile('<ion-content>')(scope);
|
||||
var scrollView = content.data('$$ionicScrollController').scrollView;
|
||||
|
||||
var originalCallback = scrollView.__callback;
|
||||
var originalGetContentHeight = scrollView.options.getContentHeight;
|
||||
|
||||
var repeater = angular.element(
|
||||
'<div collection-repeat="item in items" item-height="5" item-width="5"></div>'
|
||||
);
|
||||
content.append(repeater);
|
||||
$compile(repeater)(content.scope());
|
||||
$rootScope.$apply();
|
||||
content.triggerHandler('scroll.init');
|
||||
$rootScope.$apply();
|
||||
|
||||
expect(scrollView.__callback).not.toBe(originalCallback);
|
||||
expect(scrollView.options.getContentHeight).not.toBe(originalGetContentHeight);
|
||||
|
||||
scope.$destroy();
|
||||
|
||||
expect(scrollView.__callback).toBe(originalCallback);
|
||||
expect(scrollView.options.getContentHeight).toBe(originalGetContentHeight);
|
||||
}));
|
||||
|
||||
describe('automatic dimensions', function() {
|
||||
|
||||
Reference in New Issue
Block a user