@@ -104,6 +104,8 @@ function VirtualRepeatContainerController(
104
104
this . originalSize = null ;
105
105
/** @type {number } Amount to offset the total scroll size by. */
106
106
this . offsetSize = parseInt ( this . $attrs . mdOffsetSize , 10 ) || 0 ;
107
+ /** @type {?string } height or width element style on the container prior to auto-shrinking. */
108
+ this . oldElementSize = null ;
107
109
108
110
if ( this . $attrs . mdTopIndex ) {
109
111
/** @type {function(angular.Scope): number } Binds to topIndex on Angular scope */
@@ -184,8 +186,16 @@ VirtualRepeatContainerController.prototype.getSize = function() {
184
186
* @param {number } The new size to set.
185
187
*/
186
188
VirtualRepeatContainerController . prototype . setSize_ = function ( size ) {
189
+ var dimension = this . getDimensionName_ ( ) ;
190
+
187
191
this . size = size ;
188
- this . $element [ 0 ] . style [ this . isHorizontal ( ) ? 'width' : 'height' ] = size + 'px' ;
192
+ this . $element [ 0 ] . style [ dimension ] = size + 'px' ;
193
+ } ;
194
+
195
+
196
+ VirtualRepeatContainerController . prototype . unsetSize_ = function ( ) {
197
+ this . $element [ 0 ] . style [ this . getDimensionName_ ( ) ] = this . oldElementSize ;
198
+ this . oldElementSize = null ;
189
199
} ;
190
200
191
201
@@ -197,6 +207,11 @@ VirtualRepeatContainerController.prototype.updateSize = function() {
197
207
? this . $element [ 0 ] . clientWidth
198
208
: this . $element [ 0 ] . clientHeight ;
199
209
210
+ // Recheck the scroll position after updating the size. This resolves
211
+ // problems that can result if the scroll position was measured while the
212
+ // element was display: none or detached from the document.
213
+ this . handleScroll_ ( ) ;
214
+
200
215
this . repeater && this . repeater . containerUpdated ( ) ;
201
216
} ;
202
217
@@ -207,13 +222,18 @@ VirtualRepeatContainerController.prototype.getScrollSize = function() {
207
222
} ;
208
223
209
224
225
+ VirtualRepeatContainerController . prototype . getDimensionName_ = function ( ) {
226
+ return this . isHorizontal ( ) ? 'width' : 'height' ;
227
+ } ;
228
+
229
+
210
230
/**
211
231
* Sets the scroller element to the specified size.
212
232
* @private
213
233
* @param {number } size The new size.
214
234
*/
215
235
VirtualRepeatContainerController . prototype . sizeScroller_ = function ( size ) {
216
- var dimension = this . isHorizontal ( ) ? 'width' : 'height' ;
236
+ var dimension = this . getDimensionName_ ( ) ;
217
237
var crossDimension = this . isHorizontal ( ) ? 'height' : 'width' ;
218
238
219
239
// Clear any existing dimensions.
@@ -255,16 +275,21 @@ VirtualRepeatContainerController.prototype.sizeScroller_ = function(size) {
255
275
VirtualRepeatContainerController . prototype . autoShrink_ = function ( size ) {
256
276
var shrinkSize = Math . max ( size , this . autoShrinkMin * this . repeater . getItemSize ( ) ) ;
257
277
if ( this . autoShrink && shrinkSize !== this . size ) {
278
+ if ( this . oldElementSize === null ) {
279
+ this . oldElementSize = this . $element [ 0 ] . style [ this . getDimensionName_ ( ) ] ;
280
+ }
281
+
258
282
var currentSize = this . originalSize || this . size ;
259
283
if ( ! currentSize || shrinkSize < currentSize ) {
260
284
if ( ! this . originalSize ) {
261
285
this . originalSize = this . size ;
262
286
}
263
287
264
288
this . setSize_ ( shrinkSize ) ;
265
- } else if ( this . originalSize ) {
266
- this . setSize_ ( this . originalSize ) ;
289
+ } else if ( this . originalSize !== null ) {
290
+ this . unsetSize_ ( ) ;
267
291
this . originalSize = null ;
292
+ this . updateSize ( ) ;
268
293
}
269
294
270
295
this . repeater . containerUpdated ( ) ;
0 commit comments