Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection Repeat With Search Input #2523

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions js/angular/directive/collectionRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
*
* @param {expression} collection-item-width The width of the repeated element. Can be a number (in pixels) or a percentage.
* @param {expression} collection-item-height The height of the repeated element. Can be a number (in pixels), or a percentage.
* @param {expression} collection-list-top A boolean switch indicating that the list should scroll to the top upon list change or
* scrollView resize. Defaults to `true`.
*
*/
var COLLECTION_REPEAT_SCROLLVIEW_XY_ERROR = "Cannot create a collection-repeat within a scrollView that is scrollable on both x and y axis. Choose either x direction or y direction.";
Expand Down Expand Up @@ -166,6 +168,7 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {

var heightParsed = $parse($attr.collectionItemHeight || '"100%"');
var widthParsed = $parse($attr.collectionItemWidth || '"100%"');
var listTopParsed = $parse($attr.collectionListTop || true);

var heightGetter = function(scope, locals) {
var result = heightParsed(scope, locals);
Expand Down Expand Up @@ -246,6 +249,9 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {
scrollView.resize();
dataSource.setData(value, beforeSiblings, afterSiblings);
collectionRepeatManager.resize();
if (listTopParsed) {
scrollView.scrollTo(0,0, false, null, true);
}
}

var requiresRerender;
Expand Down
33 changes: 33 additions & 0 deletions test/unit/angular/directive/collectionRepeat.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,41 @@ describe('collectionRepeat directive', function() {
var el = setup('collection-repeat="item in items" collection-item-height="50"');
var scrollView = el.controller('$ionicScroll').scrollView;
spyOn(scrollView, 'resize');
spyOn(scrollView, 'scrollTo');
dataSource.setData.reset();
repeatManager.resize.reset();

el.scope().$apply('items = [ 1,2,3 ]');
expect(dataSource.setData).toHaveBeenCalledWith(el.scope().items, [], []);
expect(repeatManager.resize.callCount).toBe(1);
expect(scrollView.resize.callCount).toBe(1);
expect(scrollView.scrollTo).toHaveBeenCalledWith(0, 0, false, null, true);
el.scope().$apply('items = null');
expect(dataSource.setData).toHaveBeenCalledWith(null, [], []);
expect(repeatManager.resize.callCount).toBe(2);
expect(scrollView.resize.callCount).toBe(2);
expect(scrollView.scrollTo).toHaveBeenCalledWith(0, 0, false, null, true);
});

it('should rerender not scroll top of list', function() {
var el = setup('collection-repeat="item in items" collection-item-height="50" collection-list-top=false');
var scrollView = el.controller('$ionicScroll').scrollView;
spyOn(scrollView, 'resize');
spyOn(scrollView, 'scrollTo');
dataSource.setData.reset();
repeatManager.resize.reset();

el.scope().$apply('items = [ 1,2,3 ]');
expect(scrollView.scrollTo).not.toHaveBeenCalled;
el.scope().$apply('items = null');
expect(scrollView.scrollTo).not.toHaveBeenCalled;
});

it('should rerender on window resize', function() {
var el = setup('collection-repeat="item in items" collection-item-height="50"');
var scrollView = el.controller('$ionicScroll').scrollView;
spyOn(scrollView, 'resize');
spyOn(scrollView, 'scrollTo');
dataSource.setData.reset();
repeatManager.resize.reset();

Expand All @@ -147,6 +165,21 @@ describe('collectionRepeat directive', function() {
expect(dataSource.setData).toHaveBeenCalledWith(el.scope().items, [], []);
expect(repeatManager.resize.callCount).toBe(1);
expect(scrollView.resize.callCount).toBe(1);
expect(scrollView.scrollTo).toHaveBeenCalledWith(0, 0, false, null, true);
});

it('should rerender not scroll top on window resize', function() {
var el = setup('collection-repeat="item in items" collection-item-height="50" collection-list-top=false');
var scrollView = el.controller('$ionicScroll').scrollView;
spyOn(scrollView, 'resize');
spyOn(scrollView, 'scrollTo');
dataSource.setData.reset();
repeatManager.resize.reset();

el.scope().items = [1,2,3];

ionic.trigger('resize', { target: window });
expect(scrollView.scrollTo).not.toHaveBeenCalled;
});

it('should rerender on scrollCtrl resize', inject(function($timeout) {
Expand Down