Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 75cd97e

Browse files
committed
slight optimization of viewport adjustment
1 parent 63f811b commit 75cd97e

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

list/elements/polymer-virtual-list/polymer-virtual-list.html

+33-22
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,6 @@
125125
}
126126
this.initialized = true;
127127
},
128-
measurePage: function(page) {
129-
var ph = this.calcPageHeight(page);
130-
var pn = page.pageNum;
131-
if (!this.rowHeight) {
132-
// rowHeight is not set, use the page's height to setup initial values
133-
this.initialize(ph, pn);
134-
}
135-
var ph0 = this.getPageHeight(pn);
136-
if (ph && ph0 != ph) {
137-
this.pageHeights[pn] = ph;
138-
// since page height has changed, invalidate all the pageTops after
139-
// this page
140-
this.pageTops.splice(pn+1, this.pageTops.length);
141-
// also adjust the viewport's height
142-
this.viewportHeight += ph - ph0;
143-
}
144-
},
145128
get viewportHeight() {
146129
return this._viewportHeight;
147130
},
@@ -191,6 +174,25 @@
191174
var ph = this.getPageHeight(pn);
192175
return pn + (pos-pt+ph)/ph;
193176
},
177+
/* returns delta between actual and expected */
178+
measurePage: function(page) {
179+
var ph = this.calcPageHeight(page);
180+
var pn = page.pageNum;
181+
if (!this.rowHeight) {
182+
// rowHeight is not set, use the page's height to setup initial values
183+
this.initialize(ph, pn);
184+
}
185+
var ph0 = this.getPageHeight(pn);
186+
if (ph && ph0 != ph) {
187+
this.pageHeights[pn] = ph;
188+
// since page height has changed, invalidate all the pageTops after
189+
// this page
190+
this.pageTops.splice(pn+1, this.pageTops.length);
191+
// also adjust the viewport's height
192+
return ph - ph0;
193+
}
194+
return 0;
195+
},
194196
// positions the given page and returns the adjustment delta.
195197
positionPage: function(page) {
196198
var pn = page.pageNum, t;
@@ -257,7 +259,7 @@
257259
invalidate: function(info) {
258260
info = info || this.getViewportPageInfo();
259261
var k = info.start, n = info.start+this.numPages,
260-
c = info.center;
262+
c = info.center, v=0, s=0, d;
261263
this.previousPages = this.pages;
262264
this.pages = [];
263265
for (; k<n; k++) {
@@ -266,15 +268,24 @@
266268
if (this.retainPages) {
267269
p.style.display = null;
268270
}
269-
this.measurePage(p);
270-
var d = this.positionPage(p);
271+
v += this.measurePage(p);
272+
d = this.positionPage(p);
271273
// adjust scrollOffset if center page's top has changed
272-
if (!this.fixedHeight && (d && k === c)) {
273-
this.scrollOffset -= d;
274+
if (d && k === c) {
275+
s = d;
274276
}
275277
this.pages.push(p);
276278
}
277279
}
280+
// adjust viewport and scroll position iff needed
281+
if (!this.fixedHeight) {
282+
if (v) {
283+
this.viewportHeight += v;
284+
}
285+
if (s) {
286+
this.scrollOffset -= s;
287+
}
288+
}
278289
// remove out-of-bounds pages
279290
this.cleanupPages();
280291
},

0 commit comments

Comments
 (0)